Skip to content

Commit ead1d31

Browse files
author
Gerald Baulig
committed
fix(credentials): fulfillment courier now supports credentials as seperate resource
1 parent 729da43 commit ead1d31

File tree

9 files changed

+262
-131
lines changed

9 files changed

+262
-131
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ WORKDIR $APP_HOME
2323

2424
COPY --chown=node:node ./cfg $APP_HOME/cfg
2525
COPY --chown=node:node ./queries $APP_HOME/queries
26+
COPY --chown=node:node ./wsdl $APP_HOME/wsdl
2627
COPY --chown=node:node --from=build $APP_HOME/lib $APP_HOME/lib
2728

2829
EXPOSE 50051

cfg/config.json

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
"tax": {
7171
"address": "localhost:50063"
7272
},
73+
"credential": {
74+
"address": "localhost:50063"
75+
},
7376
"product": {
7477
"address": "localhost:50068"
7578
}

cfg/config_test.json

+13
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,19 @@
163163
]
164164
}
165165
}
166+
},
167+
"credential": {
168+
"address": "localhost:50173",
169+
"mock": {
170+
"protoPath": "io/restorecommerce/credential.proto",
171+
"packageName": "io.restorecommerce.credential",
172+
"serviceName": "CredentialService",
173+
"protoLoadOptions": {
174+
"includeDirs": [
175+
"node_modules/@restorecommerce/protos/"
176+
]
177+
}
178+
}
166179
}
167180
}
168181
}

package-lock.json

+15-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
},
1111
"type": "module",
1212
"dependencies": {
13-
"@restorecommerce/acs-client": "^1.6.6",
13+
"@restorecommerce/acs-client": "^1.6.7",
1414
"@restorecommerce/cart": "^1.0.5",
1515
"@restorecommerce/chassis-srv": "^1.6.0",
1616
"@restorecommerce/cluster-service": "^1.0.3",
1717
"@restorecommerce/grpc-client": "^2.2.1",
18-
"@restorecommerce/kafka-client": "^1.2.1",
18+
"@restorecommerce/kafka-client": "^1.2.6",
1919
"@restorecommerce/logger": "^1.2.10",
20-
"@restorecommerce/rc-grpc-clients": "^5.1.27",
20+
"@restorecommerce/rc-grpc-clients": "^5.1.28",
2121
"@restorecommerce/resource-base-interface": "^1.6.0",
2222
"@restorecommerce/service-config": "^1.0.12",
2323
"@types/soap": "^0.21.0",

src/services/fulfillment.ts

+66-20
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ import {
6161
Customer,
6262
CustomerServiceDefinition
6363
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/customer.js';
64+
import {
65+
Credential,
66+
CredentialServiceDefinition
67+
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/credential.js';
6468
import {
6569
Shop,
6670
ShopServiceDefinition
@@ -173,6 +177,7 @@ export class FulfillmentService
173177
protected readonly address_service: Client<AddressServiceDefinition>;
174178
protected readonly country_service: Client<CountryServiceDefinition>;
175179
protected readonly tax_service: Client<TaxServiceDefinition>;
180+
protected readonly credential_service: Client<CredentialServiceDefinition>;
176181

177182
constructor(
178183
readonly fulfillmentCourierSrv: FulfillmentCourierService,
@@ -272,6 +277,15 @@ export class FulfillmentService
272277
TaxServiceDefinition,
273278
createChannel(cfg.get('client:tax:address'))
274279
);
280+
281+
this.credential_service = createClient(
282+
{
283+
...cfg.get('client:credential'),
284+
logger
285+
} as GrpcClientConfig,
286+
CredentialServiceDefinition,
287+
createChannel(cfg.get('client:credential:address'))
288+
);
275289
}
276290

277291
protected handleStatusError<T>(id: string, e: any, payload?: any): T {
@@ -405,11 +419,10 @@ export class FulfillmentService
405419
context?: any,
406420
): Promise<ResponseMap<T>> {
407421
ids = [...new Set(ids)];
408-
const entity = ({} as new() => T).name;
409422

410423
if (ids.length > 1000) {
411424
throwOperationStatusCode(
412-
entity,
425+
service.constructor?.name,
413426
this.operation_status_codes.LIMIT_EXHAUSTED,
414427
);
415428
}
@@ -450,22 +463,22 @@ export class FulfillmentService
450463
);
451464
}
452465

453-
async getById<T>(map: { [id: string]: T }, id: string): Promise<T> {
454-
if (id in map) {
466+
async getById<T>(map: { [id: string]: T }, id: string, name: string): Promise<T> {
467+
if (map && id in map) {
455468
return map[id];
456469
}
457470
else {
458471
throwStatusCode<T>(
459-
({} as new() => T).name,
472+
name,
460473
id,
461474
this.status_codes.NOT_FOUND
462475
);
463476
}
464477
}
465478

466-
async getByIds<T>(map: { [id: string]: T }, ids: string[]): Promise<T[]> {
479+
async getByIds<T>(map: { [id: string]: T }, ids: string[], name: string): Promise<T[]> {
467480
return Promise.all(ids.map(
468-
id => this.getById(map, id)
481+
id => this.getById(map, id, name)
469482
));
470483
}
471484

@@ -579,6 +592,15 @@ export class FulfillmentService
579592
context,
580593
);
581594

595+
const credential_map = await this.get<Credential>(
596+
Object.values(courier_map).map(
597+
c => c.payload?.credential_id
598+
),
599+
this.credential_service,
600+
subject,
601+
context,
602+
)
603+
582604
const tax_map = await this.get<Tax>(
583605
Object.values(product_map).flatMap(
584606
p => p.payload?.tax_ids
@@ -593,26 +615,30 @@ export class FulfillmentService
593615
const sender_country = await this.getById(
594616
country_map,
595617
item.packaging.sender?.address?.country_id,
618+
'Country'
596619
);
597620

598621
const recipient_country = await this.getById(
599622
country_map,
600623
item.packaging.recipient?.address?.country_id,
624+
'Country'
601625
);
602626

603627
const products = await this.getByIds(
604628
product_map,
605629
item.packaging.parcels.map(
606630
parcel => parcel?.product_id
607631
),
632+
'Product'
608633
);
609634

610635
const couriers = await this.getByIds(
611636
courier_map,
612637
products.map(
613638
product => product.payload?.courier_id
614-
)
615-
)
639+
),
640+
'Courier'
641+
);
616642

617643
couriers.every(
618644
courier => courier.payload?.shop_ids?.includes(
@@ -624,6 +650,16 @@ export class FulfillmentService
624650
this.status_codes.SHOP_ID_NOT_IDENTICAL,
625651
);
626652

653+
const credentials = await this.getByIds(
654+
credential_map,
655+
couriers.map(
656+
c => c.payload?.credential_id
657+
).filter(
658+
id => id
659+
),
660+
'Credential'
661+
);
662+
627663
const status: Status[] = [
628664
sender_country?.status,
629665
recipient_country?.status,
@@ -633,16 +669,19 @@ export class FulfillmentService
633669

634670
const shop_country = await this.getById(
635671
shop_map,
636-
item.shop_id
672+
item.shop_id,
673+
'Shop'
637674
).then(
638675
shop => this.getById(
639676
orga_map,
640-
shop.payload?.organization_id
677+
shop.payload!.organization_id,
678+
'Organization'
641679
)
642680
).then(
643681
orga => this.getByIds(
644682
contact_point_map,
645-
orga.payload?.contact_point_ids
683+
orga.payload!.contact_point_ids,
684+
'ContactPoint'
646685
)
647686
).then(
648687
cpts => cpts.find(
@@ -657,18 +696,21 @@ export class FulfillmentService
657696
).then(
658697
contact_point => this.getById(
659698
address_map,
660-
contact_point.payload?.physical_address_id,
699+
contact_point.payload!.physical_address_id,
700+
'ContactPoint'
661701
)
662702
).then(
663703
address => this.getById(
664704
country_map,
665-
address.payload?.country_id
705+
address.payload!.country_id,
706+
'Country'
666707
)
667708
);
668709

669710
const customer = await this.getById(
670711
customer_map,
671-
item.customer_id
712+
item.customer_id,
713+
'Customer'
672714
);
673715

674716
const customer_country = await this.getByIds(
@@ -677,7 +719,8 @@ export class FulfillmentService
677719
customer.payload.private?.contact_point_ids,
678720
orga_map[customer.payload.commercial?.organization_id]?.payload.contact_point_ids,
679721
orga_map[customer.payload.public_sector?.organization_id]?.payload.contact_point_ids,
680-
].flatMap(id => id).filter(id => id)
722+
].flatMap(id => id).filter(id => id),
723+
'Country'
681724
).then(
682725
cps => cps.find(
683726
cp => cp.payload?.contact_point_type_ids.indexOf(
@@ -692,11 +735,13 @@ export class FulfillmentService
692735
cp => this.getById(
693736
address_map,
694737
cp.payload.physical_address_id,
738+
'Address'
695739
)
696740
).then(
697741
address => this.getById(
698742
country_map,
699-
address.payload.country_id
743+
address.payload.country_id,
744+
'Country'
700745
)
701746
);
702747

@@ -740,6 +785,7 @@ export class FulfillmentService
740785
payload: item,
741786
products,
742787
couriers,
788+
credentials,
743789
sender_country,
744790
recipient_country,
745791
options: null,
@@ -921,7 +967,7 @@ export class FulfillmentService
921967
}, context);
922968

923969
upsert_results.items.forEach(item => {
924-
if (item.payload.fulfillment_state in this.emitters) {
970+
if (this.emitters && item.payload.fulfillment_state in this.emitters) {
925971
switch (item.payload.fulfillment_state) {
926972
case FulfillmentState.INVALID:
927973
case FulfillmentState.FAILED:
@@ -1069,7 +1115,7 @@ export class FulfillmentService
10691115
updates => updates.items.forEach(
10701116
item => {
10711117
response_map[item.payload?.id ?? item.status?.id] = item as FulfillmentResponse;
1072-
if (item.payload.fulfillment_state in this.emitters) {
1118+
if (this.emitters && item.payload.fulfillment_state in this.emitters) {
10731119
switch (item.payload.fulfillment_state) {
10741120
case FulfillmentState.INVALID:
10751121
case FulfillmentState.FAILED:
@@ -1208,7 +1254,7 @@ export class FulfillmentService
12081254
}, context);
12091255

12101256
update_results.items.forEach(item => {
1211-
if (item.payload.fulfillment_state in this.emitters) {
1257+
if (this.emitters && item.payload.fulfillment_state in this.emitters) {
12121258
switch (item.payload.fulfillment_state) {
12131259
case FulfillmentState.INVALID:
12141260
case FulfillmentState.FAILED:

0 commit comments

Comments
 (0)