@@ -14,7 +14,6 @@ import {
14
14
} from '@restorecommerce/acs-client' ;
15
15
import { database } from '@restorecommerce/chassis-srv' ;
16
16
import { Topic } from '@restorecommerce/kafka-client' ;
17
- import { DeepPartial } from '@restorecommerce/kafka-client/lib/protos.js' ;
18
17
import {
19
18
DeleteRequest ,
20
19
ReadRequest
@@ -46,49 +45,46 @@ import {
46
45
FulfillmentId ,
47
46
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/fulfillment.js' ;
48
47
import { Subject } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/auth.js' ;
49
- import { AddressServiceDefinition } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/address.js' ;
48
+ import { Address , AddressServiceDefinition } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/address.js' ;
50
49
import {
50
+ Country ,
51
51
CountryServiceDefinition ,
52
52
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/country.js' ;
53
- import { TaxServiceDefinition } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/tax.js' ;
53
+ import { Tax , TaxServiceDefinition } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/tax.js' ;
54
54
import { InvoiceListResponse } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/invoice.js' ;
55
55
import {
56
+ ContactPoint ,
56
57
ContactPointResponse ,
57
58
ContactPointServiceDefinition
58
59
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/contact_point.js' ;
59
- import { CustomerServiceDefinition } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/customer.js' ;
60
- import { ShopServiceDefinition } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/shop.js' ;
61
- import { OrganizationServiceDefinition } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/organization.js' ;
60
+ import { Customer , CustomerServiceDefinition } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/customer.js' ;
61
+ import { Shop , ShopServiceDefinition } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/shop.js' ;
62
+ import { Organization , OrganizationServiceDefinition } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/organization.js' ;
62
63
import { VAT } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/amount.js' ;
64
+ import { FulfillmentProduct } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/fulfillment_product.js' ;
63
65
import { FulfillmentCourierService } from './fulfillment_courier.js' ;
64
66
import { FulfillmentProductService } from './fulfillment_product.js' ;
65
67
import {
66
- ProductResponseMap ,
67
68
AggregatedFulfillment ,
68
69
mergeFulfillments ,
69
70
flatMapAggregatedFulfillments ,
70
- CourierResponseMap ,
71
71
StateRank ,
72
- CountryResponseMap ,
73
- TaxResponseMap ,
74
72
CRUDClient ,
75
- CustomerResponseMap ,
76
- ShopResponseMap ,
77
- OrganizationResponseMap ,
78
- ContactPointResponseMap ,
79
- AddressResponseMap ,
80
73
filterTax ,
81
74
throwOperationStatusCode ,
82
75
throwStatusCode ,
83
76
createStatusCode ,
84
77
createOperationStatusCode ,
78
+ ResponseMap ,
79
+ Courier ,
85
80
} from './../utils.js' ;
86
81
import { Stub } from './../stub.js' ;
87
82
88
83
@access_controlled_service
89
84
export class FulfillmentService
90
85
extends ServiceBase < FulfillmentListResponse , FulfillmentList >
91
- implements FulfillmentServiceImplementation {
86
+ implements FulfillmentServiceImplementation
87
+ {
92
88
private static async ACSContextFactory (
93
89
self : FulfillmentService ,
94
90
request : FulfillmentList & FulfillmentIdList & FulfillmentInvoiceRequestList ,
@@ -259,7 +255,7 @@ export class FulfillmentService
259
255
) ;
260
256
}
261
257
262
- protected handleStatusError < T > ( id : string , e : any , payload = null ) : T {
258
+ protected handleStatusError < T > ( id : string , e : any , payload ?: any ) : T {
263
259
this . logger ?. warn ( e ) ;
264
260
return {
265
261
payload,
@@ -288,9 +284,9 @@ export class FulfillmentService
288
284
service : CRUDClient ,
289
285
subject ?: Subject ,
290
286
context ?: any ,
291
- ) : Promise < T > {
292
- ids = [ ...new Set < string > ( ids ) ] ;
293
- const entity = typeof ( { } as T ) ;
287
+ ) : Promise < ResponseMap < T > > {
288
+ ids = [ ...new Set ( ids ) ] ;
289
+ const entity = ( { } as new ( ) => T ) . name ;
294
290
295
291
if ( ids . length > 1000 ) {
296
292
throwOperationStatusCode (
@@ -318,13 +314,14 @@ export class FulfillmentService
318
314
request ,
319
315
context ,
320
316
) . then (
321
- response => {
317
+ ( response : any ) => {
322
318
if ( response . operation_status ?. code === 200 ) {
323
319
return response . items ?. reduce (
324
- ( a , b ) => {
320
+ ( a : ResponseMap < T > , b : any ) => {
325
321
a [ b . payload ?. id ] = b ;
326
322
return a ;
327
- } , { } as T
323
+ } ,
324
+ { } as ResponseMap < T >
328
325
) ;
329
326
}
330
327
else {
@@ -357,8 +354,8 @@ export class FulfillmentService
357
354
ids : string [ ] ,
358
355
subject ?: Subject ,
359
356
context ?: any
360
- ) : Promise < DeepPartial < FulfillmentListResponse > > {
361
- ids = [ ...new Set ( ids ) . values ( ) ] ;
357
+ ) : Promise < FulfillmentListResponse > {
358
+ ids = [ ...new Set ( ids ) ] ;
362
359
if ( ids . length > 1000 ) {
363
360
throw {
364
361
code : 500 ,
@@ -386,21 +383,21 @@ export class FulfillmentService
386
383
context ?: any ,
387
384
evaluate ?: boolean ,
388
385
) : Promise < AggregatedFulfillment [ ] > {
389
- const customer_map = await this . get < CustomerResponseMap > (
386
+ const customer_map = await this . get < Customer > (
390
387
fulfillments . map ( q => q . customer_id ) ,
391
388
this . customer_service ,
392
389
subject ,
393
390
context ,
394
391
) ;
395
392
396
- const shop_map = await this . get < ShopResponseMap > (
393
+ const shop_map = await this . get < Shop > (
397
394
fulfillments . map ( q => q . shop_id ) ,
398
395
this . shop_service ,
399
396
subject ,
400
397
context ,
401
398
) ;
402
399
403
- const orga_map = await this . get < OrganizationResponseMap > (
400
+ const orga_map = await this . get < Organization > (
404
401
[
405
402
...Object . values ( shop_map ) . map (
406
403
item => item . payload ?. organization_id
@@ -415,7 +412,7 @@ export class FulfillmentService
415
412
context ,
416
413
) ;
417
414
418
- const contact_point_map = await this . get < ContactPointResponseMap > (
415
+ const contact_point_map = await this . get < ContactPoint > (
419
416
[
420
417
...Object . values ( orga_map ) . flatMap (
421
418
item => item . payload ?. contact_point_ids
@@ -429,7 +426,7 @@ export class FulfillmentService
429
426
context ,
430
427
) ;
431
428
432
- const address_map = await this . get < AddressResponseMap > (
429
+ const address_map = await this . get < Address > (
433
430
Object . values ( contact_point_map ) . map (
434
431
item => item . payload ?. physical_address_id
435
432
) ,
@@ -438,7 +435,7 @@ export class FulfillmentService
438
435
context ,
439
436
) ;
440
437
441
- const country_map = await this . get < CountryResponseMap > (
438
+ const country_map = await this . get < Country > (
442
439
Object . values ( address_map ) . map (
443
440
item => item . payload ?. country_id
444
441
) ,
@@ -447,7 +444,7 @@ export class FulfillmentService
447
444
context ,
448
445
) ;
449
446
450
- const product_map = await this . get < ProductResponseMap > (
447
+ const product_map = await this . get < FulfillmentProduct > (
451
448
fulfillments . flatMap (
452
449
f => f . packaging . parcels . map ( p => p . product_id )
453
450
) ,
@@ -456,7 +453,7 @@ export class FulfillmentService
456
453
context ,
457
454
) ;
458
455
459
- const courier_map = await this . get < CourierResponseMap > (
456
+ const courier_map = await this . get < Courier > (
460
457
Object . values ( product_map ) . map (
461
458
p => p . payload ?. courier_id
462
459
) ,
@@ -465,7 +462,7 @@ export class FulfillmentService
465
462
context ,
466
463
) ;
467
464
468
- const tax_map = await this . get < TaxResponseMap > (
465
+ const tax_map = await this . get < Tax > (
469
466
Object . values ( product_map ) . flatMap (
470
467
p => p . payload ?. tax_ids
471
468
) ,
@@ -712,14 +709,14 @@ export class FulfillmentService
712
709
action : AuthZAction . EXECUTE ,
713
710
operation : Operation . isAllowed ,
714
711
context : DefaultACSClientContextFactory ,
715
- resource : DefaultResourceFactory ( 'fulfillment ' ) ,
712
+ resource : DefaultResourceFactory ( 'execution.evaluateFulfillments ' ) ,
716
713
database : 'arangoDB' ,
717
714
useCache : true ,
718
715
} )
719
716
public async evaluate (
720
717
request : FulfillmentList ,
721
718
context ?: any ,
722
- ) : Promise < DeepPartial < FulfillmentListResponse > > {
719
+ ) : Promise < FulfillmentListResponse > {
723
720
try {
724
721
const fulfillments = await this . aggregateFulfillments ( request . items , request . subject , context ) ;
725
722
const flat_fulfillments = flatMapAggregatedFulfillments ( fulfillments ) ;
@@ -756,7 +753,7 @@ export class FulfillmentService
756
753
public async submit (
757
754
request : FulfillmentList ,
758
755
context ?: any
759
- ) : Promise < DeepPartial < FulfillmentListResponse > > {
756
+ ) : Promise < FulfillmentListResponse > {
760
757
try {
761
758
const fulfillments = await this . aggregateFulfillments ( request . items , request . subject , context ) ;
762
759
const flattened = flatMapAggregatedFulfillments ( fulfillments ) ;
@@ -831,7 +828,7 @@ export class FulfillmentService
831
828
public async track (
832
829
request : FulfillmentIdList ,
833
830
context ?: any
834
- ) : Promise < DeepPartial < FulfillmentListResponse > > {
831
+ ) : Promise < FulfillmentListResponse > {
835
832
try {
836
833
const request_map : { [ id : string ] : FulfillmentId } = request . items . reduce (
837
834
( a , b ) => {
@@ -983,7 +980,7 @@ export class FulfillmentService
983
980
database : 'arangoDB' ,
984
981
useCache : true ,
985
982
} )
986
- public async withdraw ( request : FulfillmentIdList , context ?: any ) : Promise < DeepPartial < FulfillmentListResponse > > {
983
+ public async withdraw ( request : FulfillmentIdList , context ?: any ) : Promise < FulfillmentListResponse > {
987
984
return null ;
988
985
}
989
986
@@ -995,14 +992,14 @@ export class FulfillmentService
995
992
database : 'arangoDB' ,
996
993
useCache : true ,
997
994
} )
998
- public async cancel ( request : FulfillmentIdList , context ?: any ) : Promise < DeepPartial < FulfillmentListResponse > > {
995
+ public async cancel ( request : FulfillmentIdList , context ?: any ) : Promise < FulfillmentListResponse > {
999
996
try {
1000
- const request_map = request . items . reduce (
997
+ const request_map = request . items ! . reduce (
1001
998
( a , b ) => {
1002
999
a [ b . id ] = b . shipment_numbers ;
1003
1000
return a ;
1004
1001
} ,
1005
- { }
1002
+ { } as { [ key : string ] : string [ ] }
1006
1003
) ;
1007
1004
1008
1005
const fulfillments = await this . getFulfillmentsByIds (
@@ -1111,7 +1108,7 @@ export class FulfillmentService
1111
1108
action : AuthZAction . DELETE ,
1112
1109
operation : Operation . isAllowed ,
1113
1110
context : FulfillmentService . ACSContextFactory ,
1114
- resource : DefaultResourceFactory ( 'order ' ) ,
1111
+ resource : DefaultResourceFactory ( 'fulfillment ' ) ,
1115
1112
database : 'arangoDB' ,
1116
1113
useCache : true ,
1117
1114
} )
@@ -1133,14 +1130,14 @@ export class FulfillmentService
1133
1130
async createInvoice (
1134
1131
request : FulfillmentInvoiceRequestList ,
1135
1132
context : any
1136
- ) : Promise < DeepPartial < InvoiceListResponse > > {
1133
+ ) : Promise < InvoiceListResponse > {
1137
1134
return null ;
1138
1135
}
1139
1136
1140
1137
async triggerInvoice (
1141
1138
request : FulfillmentInvoiceRequestList ,
1142
1139
context : any
1143
- ) : Promise < DeepPartial < StatusListResponse > > {
1140
+ ) : Promise < StatusListResponse > {
1144
1141
return null ;
1145
1142
}
1146
1143
}
0 commit comments