@@ -8,6 +8,7 @@ final class BookingDetailsViewModel: ObservableObject {
88 private let booking : Booking
99 private let headerContent : HeaderContent
1010 private let customerContent = CustomerContent ( )
11+ private( set) var order : Order ?
1112
1213 let navigationTitle : String
1314 @Published private( set) var sections : [ Section ] = [ ]
@@ -87,7 +88,10 @@ private extension BookingDetailsViewModel {
8788
8889extension BookingDetailsViewModel {
8990 func syncData( ) async {
90- await syncCustomer ( )
91+ await withTaskGroup ( of: Void . self) { group in
92+ group. addTask { await self . syncCustomer ( ) }
93+ group. addTask { await self . syncOrder ( ) }
94+ }
9195 }
9296}
9397
@@ -106,6 +110,21 @@ private extension BookingDetailsViewModel {
106110 }
107111 }
108112
113+ func syncOrder( ) async {
114+ guard booking. orderID > 0 else {
115+ return
116+ }
117+
118+ do {
119+ let fetchedOrder = try await retrieveOrder ( )
120+ await MainActor . run {
121+ self . order = fetchedOrder
122+ }
123+ } catch {
124+ DDLogError ( " ⛔️ Error synchronizing Order for Booking: \( error) " )
125+ }
126+ }
127+
109128 @MainActor
110129 func retrieveCustomer( ) async throws -> Customer {
111130 try await withCheckedThrowingContinuation { continuation in
@@ -124,6 +143,29 @@ private extension BookingDetailsViewModel {
124143 }
125144 }
126145
146+ @MainActor
147+ func retrieveOrder( ) async throws -> Order {
148+ enum OrderSyncError : Error {
149+ case unknown
150+ }
151+
152+ return try await withCheckedThrowingContinuation { continuation in
153+ let action = OrderAction . retrieveOrder (
154+ siteID: booking. siteID,
155+ orderID: booking. orderID
156+ ) { order, error in
157+ if let order = order {
158+ continuation. resume ( returning: order)
159+ } else if let error = error {
160+ continuation. resume ( throwing: error)
161+ } else {
162+ continuation. resume ( throwing: OrderSyncError . unknown)
163+ }
164+ }
165+ stores. dispatch ( action)
166+ }
167+ }
168+
127169 @MainActor
128170 func updateCustomerSection( with customer: Customer ) {
129171 customerContent. update ( with: customer)
0 commit comments