Skip to content

Commit 6310dda

Browse files
author
Gerald Baulig
committed
fix(submit): preserve meta in submit
1 parent 703c300 commit 6310dda

File tree

1 file changed

+50
-21
lines changed

1 file changed

+50
-21
lines changed

src/services/fulfillment.ts

+50-21
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,19 @@ export class FulfillmentService
148148
},
149149
CONTENT_NOT_SUPPORTED: {
150150
code: 400,
151-
message: '{entity} {id}: Content type {error} is not supported!',
151+
message: '{entity} {id}: Content type {details} is not supported!',
152+
},
153+
REQUIRED_FIELD_MISSING: {
154+
code: 400,
155+
message: '{entity} {id}: Is missing required field {details}!',
152156
},
153157
PROTOCOL_NOT_SUPPORTED: {
154158
code: 400,
155-
message: '{entity} {id}: Protocol of {error} is not supported!',
159+
message: '{entity} {id}: Protocol of {details} is not supported!',
156160
},
157161
FETCH_FAILED: {
158162
code: 500,
159-
message: '{entity} {id}: {error}!',
163+
message: '{entity} {id}: {details}!',
160164
},
161165
};
162166

@@ -402,23 +406,23 @@ export class FulfillmentService
402406
[
403407
{
404408
service: ShopServiceDefinition,
405-
map_by_ids: (fulfillments) => fulfillments.items?.map(
409+
map_by_ids: (fulfillments) => fulfillments.items.map(
406410
i => i.payload.shop_id
407411
),
408412
container: 'shops',
409413
entity: 'Shop',
410414
},
411415
{
412416
service: CustomerServiceDefinition,
413-
map_by_ids: (fulfillments) => fulfillments.items?.map(
417+
map_by_ids: (fulfillments) => fulfillments.items.map(
414418
i => i.payload.customer_id
415419
),
416420
container: 'customers',
417421
entity: 'Customer',
418422
},
419423
{
420424
service: ProductServiceDefinition,
421-
map_by_ids: (fulfillments) => fulfillments.items?.flatMap(
425+
map_by_ids: (fulfillments) => fulfillments.items.flatMap(
422426
item => item.payload.packaging?.parcels
423427
)?.flatMap(
424428
parcel => parcel?.items
@@ -443,10 +447,15 @@ export class FulfillmentService
443447
subject,
444448
context,
445449
).then(
446-
response => new ResourceMap(
447-
response.items.map(item => item.payload),
448-
'FulfillmentProduct'
449-
)
450+
response => {
451+
if (response.operation_status?.code !== 200) {
452+
throw response.operation_status;
453+
}
454+
return new ResourceMap(
455+
response.items?.map(item => item.payload),
456+
'FulfillmentProduct'
457+
);
458+
}
450459
);
451460

452461
aggregation.fulfillment_couriers= await this.fulfillmentCourierSrv.get(
@@ -456,10 +465,15 @@ export class FulfillmentService
456465
subject,
457466
context,
458467
).then(
459-
response => new ResourceMap(
460-
response.items.map(item => item.payload),
461-
'FulfillmentCourier'
462-
)
468+
response => {
469+
if (response.operation_status?.code !== 200) {
470+
throw response.operation_status;
471+
}
472+
return new ResourceMap(
473+
response.items?.map(item => item.payload),
474+
'FulfillmentCourier'
475+
);
476+
}
463477
);
464478

465479
await this.aggregateProductBundles(
@@ -491,9 +505,14 @@ export class FulfillmentService
491505
},
492506
{
493507
service: SettingServiceDefinition,
494-
map_by_ids: (aggregation) => aggregation.shops?.all.map(
495-
shop => shop?.setting_id
496-
),
508+
map_by_ids: (aggregation) => [
509+
aggregation.shops?.all.map(
510+
shop => shop?.setting_id
511+
),
512+
aggregation.customers?.all.map(
513+
customer => customer?.setting_id
514+
)
515+
].flatMap(ids => ids),
497516
container: 'settings',
498517
entity: 'Setting',
499518
},
@@ -630,6 +649,14 @@ export class FulfillmentService
630649
): Promise<AggregatedFulfillmentListResponse> {
631650
const promises = aggregation.items.map(async (item): Promise<FulfillmentResponse> => {
632651
try {
652+
if (!item.payload.packaging) {
653+
throwStatusCode(
654+
'Fulfillment',
655+
item.payload.id,
656+
this.status_codes.REQUIRED_FIELD_MISSING,
657+
'packaging'
658+
);
659+
}
633660
item.payload.packaging.sender ??= resolveSenderAddress(
634661
item.payload.shop_id,
635662
aggregation,
@@ -872,7 +899,7 @@ export class FulfillmentService
872899
return {
873900
operation_status: createOperationStatusCode(
874901
this.operation_status_codes.NO_ITEM,
875-
'fulfillment',
902+
'Fulfillment',
876903
)
877904
};
878905
}
@@ -886,8 +913,8 @@ export class FulfillmentService
886913

887914
try {
888915
const response_map = new Map<string, FulfillmentResponse>(
889-
request.items.map(
890-
payload => [payload.id, {payload}]
916+
response.items.map(
917+
item => [item.payload.id, item]
891918
)
892919
);
893920
await this.get(
@@ -905,14 +932,16 @@ export class FulfillmentService
905932
const entry = response_map.get(item.payload?.id);
906933
entry.payload = {
907934
...item.payload,
908-
...entry.payload
935+
...entry.payload,
936+
meta: item.payload.meta,
909937
};
910938
entry.status = item.status;
911939
}
912940
)
913941
}
914942
}
915943
);
944+
this.logger.info(response);
916945
const aggregation = await this.aggregate(response, request.subject, context).then(
917946
aggregation => this.validateFulfillmentListResponse(aggregation, request.subject)
918947
);

0 commit comments

Comments
 (0)