@@ -148,15 +148,19 @@ export class FulfillmentService
148
148
} ,
149
149
CONTENT_NOT_SUPPORTED : {
150
150
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}!' ,
152
156
} ,
153
157
PROTOCOL_NOT_SUPPORTED : {
154
158
code : 400 ,
155
- message : '{entity} {id}: Protocol of {error } is not supported!' ,
159
+ message : '{entity} {id}: Protocol of {details } is not supported!' ,
156
160
} ,
157
161
FETCH_FAILED : {
158
162
code : 500 ,
159
- message : '{entity} {id}: {error }!' ,
163
+ message : '{entity} {id}: {details }!' ,
160
164
} ,
161
165
} ;
162
166
@@ -402,23 +406,23 @@ export class FulfillmentService
402
406
[
403
407
{
404
408
service : ShopServiceDefinition ,
405
- map_by_ids : ( fulfillments ) => fulfillments . items ? .map (
409
+ map_by_ids : ( fulfillments ) => fulfillments . items . map (
406
410
i => i . payload . shop_id
407
411
) ,
408
412
container : 'shops' ,
409
413
entity : 'Shop' ,
410
414
} ,
411
415
{
412
416
service : CustomerServiceDefinition ,
413
- map_by_ids : ( fulfillments ) => fulfillments . items ? .map (
417
+ map_by_ids : ( fulfillments ) => fulfillments . items . map (
414
418
i => i . payload . customer_id
415
419
) ,
416
420
container : 'customers' ,
417
421
entity : 'Customer' ,
418
422
} ,
419
423
{
420
424
service : ProductServiceDefinition ,
421
- map_by_ids : ( fulfillments ) => fulfillments . items ? .flatMap (
425
+ map_by_ids : ( fulfillments ) => fulfillments . items . flatMap (
422
426
item => item . payload . packaging ?. parcels
423
427
) ?. flatMap (
424
428
parcel => parcel ?. items
@@ -443,10 +447,15 @@ export class FulfillmentService
443
447
subject ,
444
448
context ,
445
449
) . 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
+ }
450
459
) ;
451
460
452
461
aggregation . fulfillment_couriers = await this . fulfillmentCourierSrv . get (
@@ -456,10 +465,15 @@ export class FulfillmentService
456
465
subject ,
457
466
context ,
458
467
) . 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
+ }
463
477
) ;
464
478
465
479
await this . aggregateProductBundles (
@@ -491,9 +505,14 @@ export class FulfillmentService
491
505
} ,
492
506
{
493
507
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 ) ,
497
516
container : 'settings' ,
498
517
entity : 'Setting' ,
499
518
} ,
@@ -630,6 +649,14 @@ export class FulfillmentService
630
649
) : Promise < AggregatedFulfillmentListResponse > {
631
650
const promises = aggregation . items . map ( async ( item ) : Promise < FulfillmentResponse > => {
632
651
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
+ }
633
660
item . payload . packaging . sender ??= resolveSenderAddress (
634
661
item . payload . shop_id ,
635
662
aggregation ,
@@ -872,7 +899,7 @@ export class FulfillmentService
872
899
return {
873
900
operation_status : createOperationStatusCode (
874
901
this . operation_status_codes . NO_ITEM ,
875
- 'fulfillment ' ,
902
+ 'Fulfillment ' ,
876
903
)
877
904
} ;
878
905
}
@@ -886,8 +913,8 @@ export class FulfillmentService
886
913
887
914
try {
888
915
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 ]
891
918
)
892
919
) ;
893
920
await this . get (
@@ -905,14 +932,16 @@ export class FulfillmentService
905
932
const entry = response_map . get ( item . payload ?. id ) ;
906
933
entry . payload = {
907
934
...item . payload ,
908
- ...entry . payload
935
+ ...entry . payload ,
936
+ meta : item . payload . meta ,
909
937
} ;
910
938
entry . status = item . status ;
911
939
}
912
940
)
913
941
}
914
942
}
915
943
) ;
944
+ this . logger . info ( response ) ;
916
945
const aggregation = await this . aggregate ( response , request . subject , context ) . then (
917
946
aggregation => this . validateFulfillmentListResponse ( aggregation , request . subject )
918
947
) ;
0 commit comments