06/11 Fix some errors: submission datetime incorrect; inspection & issue not linked, etc

This commit is contained in:
Nguyen Ngo
2026-06-11 17:18:30 -04:00
parent 3643fb1828
commit 7b4496a456
7 changed files with 223 additions and 18 deletions
+17 -3
View File
@@ -191,8 +191,18 @@ actor APIClient {
if let areaId = inspection.areaServerId { body["area_id"] = areaId }
if let parentId = inspection.parentServerId { body["parent_inspection_id"] = parentId }
if !inspection.inspectorNotes.isEmpty { body["notes"] = inspection.inspectorNotes }
if let lat = inspection.submitLatitude { body["submit_latitude"] = lat }
if let lng = inspection.submitLongitude { body["submit_longitude"] = lng }
// IMPORTANT: timeZone must be explicitly set to UTC.
// ISO8601DateFormatter() default timeZone is the DEVICE local timezone,
// which produces offset strings like "2026-06-11T10:30:00-04:00".
// The server's _parse_datetime() only recognises the Z suffix as UTC;
// offset-format strings fail all strptime patterns and return None,
// causing the server to fall back to now_eastern() the sync time
// instead of the actual inspection/completion time.
let fmt = ISO8601DateFormatter()
fmt.timeZone = TimeZone(identifier: "UTC")!
body["inspection_date"] = fmt.string(from: inspection.inspectionDate)
if let c = inspection.completedAt { body["completed_at"] = fmt.string(from: c) }
@@ -203,15 +213,19 @@ actor APIClient {
// Submit Issue
func submitIssue(_ issue: LocalIssue) async throws -> Int {
func submitIssue(_ issue: LocalIssue, inspectionServerId: Int?) async throws -> Int {
var body: [String: Any] = [
"facility_id": issue.facilityServerId,
"severity": issue.severity,
"description": issue.issueDescription,
"mobile_local_id": issue.localId,
]
if let id = issue.inspection?.serverId { body["inspection_id"] = id }
if let areaId = issue.areaServerId { body["area_id"] = areaId }
// Use the explicitly passed serverId rather than issue.inspection?.serverId.
// The ORM relationship object is a separate fetch instance from the one
// processInspectionQueue updated, so its serverId is nil even after the
// inspection synced in the same triggerSync() pass.
if let id = inspectionServerId { body["inspection_id"] = id }
if let areaId = issue.areaServerId { body["area_id"] = areaId }
// photo_path = primary photo. Additional photos are sent via a
// separate PATCH call in processIssueQueue after the issue is created,
// because the server create endpoint only stores a single photo_path.