Skip to content

Commit 9947d96

Browse files
author
Gerald Baulig
committed
feat(dummy): add dummy courier
1 parent d1f2f77 commit 9947d96

9 files changed

+322
-178
lines changed

src/services/fulfillment.ts

+42-45
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
} from '@restorecommerce/acs-client';
1515
import { database } from '@restorecommerce/chassis-srv';
1616
import { Topic } from '@restorecommerce/kafka-client';
17-
import { DeepPartial } from '@restorecommerce/kafka-client/lib/protos.js';
1817
import {
1918
DeleteRequest,
2019
ReadRequest
@@ -46,49 +45,46 @@ import {
4645
FulfillmentId,
4746
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/fulfillment.js';
4847
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';
5049
import {
50+
Country,
5151
CountryServiceDefinition,
5252
} 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';
5454
import { InvoiceListResponse } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/invoice.js';
5555
import {
56+
ContactPoint,
5657
ContactPointResponse,
5758
ContactPointServiceDefinition
5859
} 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';
6263
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';
6365
import { FulfillmentCourierService } from './fulfillment_courier.js';
6466
import { FulfillmentProductService } from './fulfillment_product.js';
6567
import {
66-
ProductResponseMap,
6768
AggregatedFulfillment,
6869
mergeFulfillments,
6970
flatMapAggregatedFulfillments,
70-
CourierResponseMap,
7171
StateRank,
72-
CountryResponseMap,
73-
TaxResponseMap,
7472
CRUDClient,
75-
CustomerResponseMap,
76-
ShopResponseMap,
77-
OrganizationResponseMap,
78-
ContactPointResponseMap,
79-
AddressResponseMap,
8073
filterTax,
8174
throwOperationStatusCode,
8275
throwStatusCode,
8376
createStatusCode,
8477
createOperationStatusCode,
78+
ResponseMap,
79+
Courier,
8580
} from './../utils.js';
8681
import { Stub } from './../stub.js';
8782

8883
@access_controlled_service
8984
export class FulfillmentService
9085
extends ServiceBase<FulfillmentListResponse, FulfillmentList>
91-
implements FulfillmentServiceImplementation {
86+
implements FulfillmentServiceImplementation
87+
{
9288
private static async ACSContextFactory(
9389
self: FulfillmentService,
9490
request: FulfillmentList & FulfillmentIdList & FulfillmentInvoiceRequestList,
@@ -259,7 +255,7 @@ export class FulfillmentService
259255
);
260256
}
261257

262-
protected handleStatusError<T>(id: string, e: any, payload = null): T {
258+
protected handleStatusError<T>(id: string, e: any, payload?: any): T {
263259
this.logger?.warn(e);
264260
return {
265261
payload,
@@ -288,9 +284,9 @@ export class FulfillmentService
288284
service: CRUDClient,
289285
subject?: Subject,
290286
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;
294290

295291
if (ids.length > 1000) {
296292
throwOperationStatusCode(
@@ -318,13 +314,14 @@ export class FulfillmentService
318314
request,
319315
context,
320316
).then(
321-
response => {
317+
(response: any) => {
322318
if (response.operation_status?.code === 200) {
323319
return response.items?.reduce(
324-
(a, b) => {
320+
(a: ResponseMap<T>, b: any) => {
325321
a[b.payload?.id] = b;
326322
return a;
327-
}, {} as T
323+
},
324+
{} as ResponseMap<T>
328325
);
329326
}
330327
else {
@@ -357,8 +354,8 @@ export class FulfillmentService
357354
ids: string[],
358355
subject?: Subject,
359356
context?: any
360-
): Promise<DeepPartial<FulfillmentListResponse>> {
361-
ids = [...new Set(ids).values()];
357+
): Promise<FulfillmentListResponse> {
358+
ids = [...new Set(ids)];
362359
if (ids.length > 1000) {
363360
throw {
364361
code: 500,
@@ -386,21 +383,21 @@ export class FulfillmentService
386383
context?: any,
387384
evaluate?: boolean,
388385
): Promise<AggregatedFulfillment[]> {
389-
const customer_map = await this.get<CustomerResponseMap>(
386+
const customer_map = await this.get<Customer>(
390387
fulfillments.map(q => q.customer_id),
391388
this.customer_service,
392389
subject,
393390
context,
394391
);
395392

396-
const shop_map = await this.get<ShopResponseMap>(
393+
const shop_map = await this.get<Shop>(
397394
fulfillments.map(q => q.shop_id),
398395
this.shop_service,
399396
subject,
400397
context,
401398
);
402399

403-
const orga_map = await this.get<OrganizationResponseMap>(
400+
const orga_map = await this.get<Organization>(
404401
[
405402
...Object.values(shop_map).map(
406403
item => item.payload?.organization_id
@@ -415,7 +412,7 @@ export class FulfillmentService
415412
context,
416413
);
417414

418-
const contact_point_map = await this.get<ContactPointResponseMap>(
415+
const contact_point_map = await this.get<ContactPoint>(
419416
[
420417
...Object.values(orga_map).flatMap(
421418
item => item.payload?.contact_point_ids
@@ -429,7 +426,7 @@ export class FulfillmentService
429426
context,
430427
);
431428

432-
const address_map = await this.get<AddressResponseMap>(
429+
const address_map = await this.get<Address>(
433430
Object.values(contact_point_map).map(
434431
item => item.payload?.physical_address_id
435432
),
@@ -438,7 +435,7 @@ export class FulfillmentService
438435
context,
439436
);
440437

441-
const country_map = await this.get<CountryResponseMap>(
438+
const country_map = await this.get<Country>(
442439
Object.values(address_map).map(
443440
item => item.payload?.country_id
444441
),
@@ -447,7 +444,7 @@ export class FulfillmentService
447444
context,
448445
);
449446

450-
const product_map = await this.get<ProductResponseMap>(
447+
const product_map = await this.get<FulfillmentProduct>(
451448
fulfillments.flatMap(
452449
f => f.packaging.parcels.map(p => p.product_id)
453450
),
@@ -456,7 +453,7 @@ export class FulfillmentService
456453
context,
457454
);
458455

459-
const courier_map = await this.get<CourierResponseMap>(
456+
const courier_map = await this.get<Courier>(
460457
Object.values(product_map).map(
461458
p => p.payload?.courier_id
462459
),
@@ -465,7 +462,7 @@ export class FulfillmentService
465462
context,
466463
);
467464

468-
const tax_map = await this.get<TaxResponseMap>(
465+
const tax_map = await this.get<Tax>(
469466
Object.values(product_map).flatMap(
470467
p => p.payload?.tax_ids
471468
),
@@ -712,14 +709,14 @@ export class FulfillmentService
712709
action: AuthZAction.EXECUTE,
713710
operation: Operation.isAllowed,
714711
context: DefaultACSClientContextFactory,
715-
resource: DefaultResourceFactory('fulfillment'),
712+
resource: DefaultResourceFactory('execution.evaluateFulfillments'),
716713
database: 'arangoDB',
717714
useCache: true,
718715
})
719716
public async evaluate(
720717
request: FulfillmentList,
721718
context?: any,
722-
): Promise<DeepPartial<FulfillmentListResponse>> {
719+
): Promise<FulfillmentListResponse> {
723720
try {
724721
const fulfillments = await this.aggregateFulfillments(request.items, request.subject, context);
725722
const flat_fulfillments = flatMapAggregatedFulfillments(fulfillments);
@@ -756,7 +753,7 @@ export class FulfillmentService
756753
public async submit(
757754
request: FulfillmentList,
758755
context?: any
759-
): Promise<DeepPartial<FulfillmentListResponse>> {
756+
): Promise<FulfillmentListResponse> {
760757
try {
761758
const fulfillments = await this.aggregateFulfillments(request.items, request.subject, context);
762759
const flattened = flatMapAggregatedFulfillments(fulfillments);
@@ -831,7 +828,7 @@ export class FulfillmentService
831828
public async track(
832829
request: FulfillmentIdList,
833830
context?: any
834-
): Promise<DeepPartial<FulfillmentListResponse>> {
831+
): Promise<FulfillmentListResponse> {
835832
try {
836833
const request_map: { [id: string]: FulfillmentId } = request.items.reduce(
837834
(a, b) => {
@@ -983,7 +980,7 @@ export class FulfillmentService
983980
database: 'arangoDB',
984981
useCache: true,
985982
})
986-
public async withdraw(request: FulfillmentIdList, context?: any): Promise<DeepPartial<FulfillmentListResponse>> {
983+
public async withdraw(request: FulfillmentIdList, context?: any): Promise<FulfillmentListResponse> {
987984
return null;
988985
}
989986

@@ -995,14 +992,14 @@ export class FulfillmentService
995992
database: 'arangoDB',
996993
useCache: true,
997994
})
998-
public async cancel(request: FulfillmentIdList, context?: any): Promise<DeepPartial<FulfillmentListResponse>> {
995+
public async cancel(request: FulfillmentIdList, context?: any): Promise<FulfillmentListResponse> {
999996
try {
1000-
const request_map = request.items.reduce(
997+
const request_map = request.items!.reduce(
1001998
(a, b) => {
1002999
a[b.id] = b.shipment_numbers;
10031000
return a;
10041001
},
1005-
{}
1002+
{} as { [key: string]: string[] }
10061003
);
10071004

10081005
const fulfillments = await this.getFulfillmentsByIds(
@@ -1111,7 +1108,7 @@ export class FulfillmentService
11111108
action: AuthZAction.DELETE,
11121109
operation: Operation.isAllowed,
11131110
context: FulfillmentService.ACSContextFactory,
1114-
resource: DefaultResourceFactory('order'),
1111+
resource: DefaultResourceFactory('fulfillment'),
11151112
database: 'arangoDB',
11161113
useCache: true,
11171114
})
@@ -1133,14 +1130,14 @@ export class FulfillmentService
11331130
async createInvoice(
11341131
request: FulfillmentInvoiceRequestList,
11351132
context: any
1136-
): Promise<DeepPartial<InvoiceListResponse>> {
1133+
): Promise<InvoiceListResponse> {
11371134
return null;
11381135
}
11391136

11401137
async triggerInvoice(
11411138
request: FulfillmentInvoiceRequestList,
11421139
context: any
1143-
): Promise<DeepPartial<StatusListResponse>> {
1140+
): Promise<StatusListResponse> {
11441141
return null;
11451142
}
11461143
}

0 commit comments

Comments
 (0)