@@ -232,7 +232,11 @@ export class OrderingService
232
232
} ,
233
233
NO_ITEM : {
234
234
code : 400 ,
235
- message : 'No item in cart' ,
235
+ message : 'No item in cart!' ,
236
+ } ,
237
+ ITEM_NOT_FOUND : {
238
+ code : 404 ,
239
+ message : '{entity} not found!' ,
236
240
} ,
237
241
} ;
238
242
@@ -494,7 +498,7 @@ export class OrderingService
494
498
subject ?: Subject ,
495
499
context ?: any
496
500
) : Promise < OrderListResponse > {
497
- const order_ids = [ ... new Set ( ids ) ] ;
501
+ const order_ids = [ ...new Set ( ids ) ] ;
498
502
499
503
if ( order_ids . length > 1000 ) {
500
504
throw this . createOperationStatusCode (
@@ -636,7 +640,13 @@ export class OrderingService
636
640
( id ) => ! ! id
637
641
) ) . values ( ) ] ;
638
642
639
- if ( product_ids . length > 1000 ) {
643
+ if ( ! product_ids . length ) {
644
+ throw this . createOperationStatusCode (
645
+ 'product' ,
646
+ this . operation_status_codes . NO_ITEM ,
647
+ ) ;
648
+ }
649
+ else if ( product_ids . length > 1000 ) {
640
650
throw this . createOperationStatusCode (
641
651
'product' ,
642
652
this . operation_status_codes . LIMIT_EXHAUSTED ,
@@ -662,17 +672,23 @@ export class OrderingService
662
672
context ,
663
673
) . then (
664
674
( response ) => {
665
- if ( response . operation_status ?. code === 200 ) {
675
+ if ( response . operation_status ?. code !== 200 ) {
676
+ throw response . operation_status ;
677
+ }
678
+ else if ( ! response . items ?. length ) {
679
+ throw this . createOperationStatusCode (
680
+ 'products' ,
681
+ this . operation_status_codes . ITEM_NOT_FOUND ,
682
+ ) ;
683
+ }
684
+ else {
666
685
return response . items ! . reduce (
667
686
( a , b ) => {
668
687
a [ b . payload ?. id ! ] = b ;
669
688
return a ;
670
689
} , { } as ProductMap
671
690
) ;
672
691
}
673
- else {
674
- throw response . operation_status ;
675
- }
676
692
}
677
693
) ;
678
694
@@ -733,18 +749,24 @@ export class OrderingService
733
749
context
734
750
) . then (
735
751
response => {
736
- if ( response . operation_status ?. code === 200 ) {
737
- return response . items ?. reduce (
752
+ if ( response . operation_status ?. code !== 200 ) {
753
+ throw response . operation_status ;
754
+ }
755
+ else if ( ! response . items ?. length ) {
756
+ throw this . createOperationStatusCode (
757
+ 'taxes' ,
758
+ this . operation_status_codes . ITEM_NOT_FOUND ,
759
+ ) ;
760
+ }
761
+ else {
762
+ return response . items ! . reduce (
738
763
( a , b ) => {
739
764
a [ b . payload ?. id ! ] = b . payload ! ;
740
765
return a ;
741
766
} ,
742
767
{ } as RatioedTaxMap
743
768
) ?? { } ;
744
769
}
745
- else {
746
- throw response . operation_status ;
747
- }
748
770
}
749
771
) ;
750
772
}
@@ -807,7 +829,7 @@ export class OrderingService
807
829
) ;
808
830
}
809
831
810
- private get < T > (
832
+ private async get < T > (
811
833
ids : ( string | undefined ) [ ] ,
812
834
service : CRUDClient ,
813
835
subject ?: Subject ,
@@ -823,7 +845,7 @@ export class OrderingService
823
845
) ;
824
846
}
825
847
826
- return service . read (
848
+ return await service . read (
827
849
{
828
850
filters : [ {
829
851
filters : [
@@ -841,17 +863,23 @@ export class OrderingService
841
863
context ,
842
864
) . then (
843
865
( response : any ) => {
844
- if ( response . operation_status ?. code === 200 ) {
866
+ if ( response . operation_status ?. code !== 200 ) {
867
+ throw response . operation_status ;
868
+ }
869
+ else if ( ! response . items ?. length ) {
870
+ throw this . createOperationStatusCode (
871
+ entity ,
872
+ this . operation_status_codes . ITEM_NOT_FOUND ,
873
+ ) ;
874
+ }
875
+ else {
845
876
return response . items ?. reduce (
846
877
( a : any , b : any ) => {
847
878
a [ b . payload ?. id ] = b ;
848
879
return a ;
849
880
} , { } as T
850
881
) ;
851
882
}
852
- else {
853
- throw response . operation_status ;
854
- }
855
883
}
856
884
) ;
857
885
}
@@ -892,9 +920,18 @@ export class OrderingService
892
920
order_list : OrderList ,
893
921
subject ?: Subject ,
894
922
context ?: any
895
- ) : Promise < DeepPartial < OrderListResponse > > {
923
+ ) : Promise < OrderListResponse > {
924
+ if ( ! order_list ?. items ?. length ) {
925
+ return {
926
+ operation_status : this . createOperationStatusCode (
927
+ 'order' ,
928
+ this . operation_status_codes . NO_ITEM ,
929
+ )
930
+ } ;
931
+ }
932
+
896
933
const product_map = await this . getProductMap (
897
- order_list . items ?? [ ] ,
934
+ order_list . items ,
898
935
subject ,
899
936
context
900
937
) ;
@@ -1223,7 +1260,7 @@ export class OrderingService
1223
1260
items,
1224
1261
total_count : items . length ?? 0 ,
1225
1262
operation_status,
1226
- } as OrderListResponse ;
1263
+ } ;
1227
1264
}
1228
1265
1229
1266
public async updateState (
@@ -1365,10 +1402,10 @@ export class OrderingService
1365
1402
}
1366
1403
1367
1404
@access_controlled_function ( {
1368
- action : AuthZAction . READ ,
1369
- operation : Operation . whatIsAllowed ,
1405
+ action : AuthZAction . EXECUTE ,
1406
+ operation : Operation . isAllowed ,
1370
1407
context : DefaultACSClientContextFactory ,
1371
- resource : [ { resource : 'order' } ] ,
1408
+ resource : DefaultResourceFactory ( 'execution.evaluateOrders' ) ,
1372
1409
database : 'arangoDB' ,
1373
1410
useCache : true ,
1374
1411
} )
0 commit comments