@@ -8,12 +8,14 @@ import {
8
8
access_controlled_function ,
9
9
access_controlled_service ,
10
10
DefaultACSClientContextFactory ,
11
- Operation
11
+ Operation ,
12
+ DefaultResourceFactory ,
13
+ injects_meta_data
12
14
} from '@restorecommerce/acs-client' ;
13
15
import { DatabaseProvider } from '@restorecommerce/chassis-srv' ;
14
16
import { Topic } from '@restorecommerce/kafka-client' ;
15
17
import { DeepPartial } from '@restorecommerce/kafka-client/lib/protos' ;
16
- import { ReadRequest } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/resource_base' ;
18
+ import { DeleteRequest , ReadRequest } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/resource_base' ;
17
19
import {
18
20
OperationStatus ,
19
21
Status ,
@@ -89,15 +91,18 @@ export class FulfillmentService
89
91
{
90
92
private static async ACSContextFactory (
91
93
self : FulfillmentService ,
92
- request : FulfillmentList | FulfillmentIdList | FulfillmentInvoiceRequestList ,
94
+ request : FulfillmentList & FulfillmentIdList & FulfillmentInvoiceRequestList ,
93
95
context : any ,
94
96
) : Promise < ACSClientContext > {
95
97
const ids = request . items ?. map ( ( item : any ) => item . id ) ;
96
98
const resources = await self . getFulfillmentsByIds ( ids , request . subject , context ) ;
97
99
return {
98
100
...context ,
99
101
subject : request . subject ,
100
- resources,
102
+ resources : [
103
+ ...resources . items ?? [ ] ,
104
+ ...request . items ?? [ ] ,
105
+ ] ,
101
106
} ;
102
107
}
103
108
@@ -348,7 +353,11 @@ export class FulfillmentService
348
353
) ) ;
349
354
}
350
355
351
- protected getFulfillmentsByIds ( ids : string [ ] , subject ?: Subject , context ?: any ) : Promise < DeepPartial < FulfillmentListResponse > > {
356
+ protected getFulfillmentsByIds (
357
+ ids : string [ ] ,
358
+ subject ?: Subject ,
359
+ context ?: any
360
+ ) : Promise < DeepPartial < FulfillmentListResponse > > {
352
361
ids = [ ...new Set ( ids ) . values ( ) ] ;
353
362
if ( ids . length > 1000 ) {
354
363
throw {
@@ -645,26 +654,34 @@ export class FulfillmentService
645
654
return super . read ( request , context ) ;
646
655
}
647
656
657
+ @injects_meta_data ( )
648
658
@access_controlled_function ( {
649
659
action : AuthZAction . CREATE ,
650
660
operation : Operation . isAllowed ,
651
661
context : FulfillmentService . ACSContextFactory ,
652
- resource : [ { resource : 'fulfillment' } ] ,
662
+ resource : DefaultResourceFactory ( 'fulfillment' ) ,
653
663
database : 'arangoDB' ,
654
664
useCache : true ,
655
665
} )
656
666
public override create (
657
667
request : FulfillmentList ,
658
668
context ?: any
659
669
) {
670
+ request ?. items ?. forEach (
671
+ item => {
672
+ if ( ! item . state || item . state === State . UNRECOGNIZED ) {
673
+ item . state = State . CREATED ;
674
+ }
675
+ }
676
+ ) ;
660
677
return super . create ( request , context ) ;
661
678
}
662
679
663
680
@access_controlled_function ( {
664
681
action : AuthZAction . MODIFY ,
665
682
operation : Operation . isAllowed ,
666
683
context : FulfillmentService . ACSContextFactory ,
667
- resource : [ { resource : 'fulfillment' } ] ,
684
+ resource : DefaultResourceFactory ( 'fulfillment' ) ,
668
685
database : 'arangoDB' ,
669
686
useCache : true ,
670
687
} )
@@ -675,11 +692,12 @@ export class FulfillmentService
675
692
return super . update ( request , context ) ;
676
693
}
677
694
695
+ @injects_meta_data ( )
678
696
@access_controlled_function ( {
679
697
action : AuthZAction . MODIFY ,
680
698
operation : Operation . isAllowed ,
681
699
context : FulfillmentService . ACSContextFactory ,
682
- resource : [ { resource : 'fulfillment' } ] ,
700
+ resource : DefaultResourceFactory ( 'fulfillment' ) ,
683
701
database : 'arangoDB' ,
684
702
useCache : true ,
685
703
} )
@@ -693,8 +711,8 @@ export class FulfillmentService
693
711
@access_controlled_function ( {
694
712
action : AuthZAction . EXECUTE ,
695
713
operation : Operation . isAllowed ,
696
- context : FulfillmentService . ACSContextFactory ,
697
- resource : [ { resource : 'fulfillment' } ] ,
714
+ context : DefaultACSClientContextFactory ,
715
+ resource : DefaultResourceFactory ( 'fulfillment' ) ,
698
716
database : 'arangoDB' ,
699
717
useCache : true ,
700
718
} )
@@ -726,11 +744,12 @@ export class FulfillmentService
726
744
}
727
745
}
728
746
747
+ @injects_meta_data ( )
729
748
@access_controlled_function ( {
730
749
action : AuthZAction . EXECUTE ,
731
750
operation : Operation . isAllowed ,
732
751
context : FulfillmentService . ACSContextFactory ,
733
- resource : [ { resource : 'fulfillment' } ] ,
752
+ resource : DefaultResourceFactory ( 'execution.submitFulfillments' ) ,
734
753
database : 'arangoDB' ,
735
754
useCache : true ,
736
755
} )
@@ -805,7 +824,7 @@ export class FulfillmentService
805
824
action : AuthZAction . EXECUTE ,
806
825
operation : Operation . isAllowed ,
807
826
context : FulfillmentService . ACSContextFactory ,
808
- resource : [ { resource : 'fulfillment' } ] ,
827
+ resource : DefaultResourceFactory ( 'execution.trackFulfillments' ) ,
809
828
database : 'arangoDB' ,
810
829
useCache : true ,
811
830
} )
@@ -960,7 +979,7 @@ export class FulfillmentService
960
979
action : AuthZAction . EXECUTE ,
961
980
operation : Operation . isAllowed ,
962
981
context : FulfillmentService . ACSContextFactory ,
963
- resource : [ { resource : 'fulfillment' } ] ,
982
+ resource : DefaultResourceFactory ( 'execution.withdrawOrder' ) ,
964
983
database : 'arangoDB' ,
965
984
useCache : true ,
966
985
} )
@@ -972,7 +991,7 @@ export class FulfillmentService
972
991
action : AuthZAction . EXECUTE ,
973
992
operation : Operation . isAllowed ,
974
993
context : FulfillmentService . ACSContextFactory ,
975
- resource : [ { resource : 'fulfillment' } ] ,
994
+ resource : DefaultResourceFactory ( 'execution.cancelFulfillments' ) ,
976
995
database : 'arangoDB' ,
977
996
useCache : true ,
978
997
} )
@@ -1088,6 +1107,21 @@ export class FulfillmentService
1088
1107
}
1089
1108
}
1090
1109
1110
+ @access_controlled_function ( {
1111
+ action : AuthZAction . DELETE ,
1112
+ operation : Operation . isAllowed ,
1113
+ context : FulfillmentService . ACSContextFactory ,
1114
+ resource : DefaultResourceFactory ( 'order' ) ,
1115
+ database : 'arangoDB' ,
1116
+ useCache : true ,
1117
+ } )
1118
+ public override delete (
1119
+ request : DeleteRequest ,
1120
+ context : any ,
1121
+ ) {
1122
+ return super . delete ( request , context ) ;
1123
+ }
1124
+
1091
1125
@access_controlled_function ( {
1092
1126
action : AuthZAction . CREATE ,
1093
1127
operation : Operation . isAllowed ,
0 commit comments