Skip to content

Commit

Permalink
fix(types): upgrade to new protobufs, courier_ids are now directly pr…
Browse files Browse the repository at this point in the history
…ovided in solution
  • Loading branch information
Gerald Baulig committed Nov 8, 2024
1 parent fda51fc commit 4acf993
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 78 deletions.
127 changes: 68 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
},
"type": "module",
"dependencies": {
"@restorecommerce/acs-client": "^3.0.1",
"@restorecommerce/acs-client": "^3.0.5",
"@restorecommerce/cart": "^1.0.9",
"@restorecommerce/chassis-srv": "^1.6.2",
"@restorecommerce/grpc-client": "^2.2.4",
"@restorecommerce/kafka-client": "^1.2.14",
"@restorecommerce/kafka-client": "^1.2.18",
"@restorecommerce/logger": "^1.3.1",
"@restorecommerce/rc-grpc-clients": "^5.1.36",
"@restorecommerce/rc-grpc-clients": "^5.1.40",
"@restorecommerce/resource-base-interface": "^1.6.2",
"@restorecommerce/service-config": "^1.0.15",
"@types/soap": "^0.21.0",
Expand Down
35 changes: 19 additions & 16 deletions src/services/fulfillment_product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ import {
Item,
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/fulfillment.js';
import {
PackingSolutionQuery,
PackingSolutionQueryList,
PackingSolution,
PackingSolutionListResponse,
FulfillmentSolutionQuery,
FulfillmentSolutionQueryList,
FulfillmentSolution,
FulfillmentSolutionListResponse,
FulfillmentProductList,
FulfillmentProductListResponse,
PackingSolutionResponse,
FulfillmentSolutionResponse,
FulfillmentProductServiceImplementation,
FulfillmentProduct,
} from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/fulfillment_product.js';
Expand All @@ -80,16 +80,16 @@ import {
import { Stub } from './../stub.js';


interface PackageSolutionTotals extends PackingSolutionQuery {
interface PackageSolutionTotals extends FulfillmentSolutionQuery {
volume: number;
total_weight: number;
max_width: number;
max_height: number;
max_length: number;
}

const buildQueryTotals = (queries: PackingSolutionQuery[]): PackageSolutionTotals[] => queries.map(
(item: PackingSolutionQuery): PackageSolutionTotals => item.items.reduce((a: PackageSolutionTotals, b: any) => {
const buildQueryTotals = (queries: FulfillmentSolutionQuery[]): PackageSolutionTotals[] => queries.map(
(item: FulfillmentSolutionQuery): PackageSolutionTotals => item.items.reduce((a: PackageSolutionTotals, b: any) => {
a.volume += b.width_in_cm * b.height_in_cm * b.length_in_cm * b.quantity;
a.total_weight += b.weight_in_kg * b.quantity;
a.max_width = Math.max(a.max_width, b.width_in_cm);
Expand Down Expand Up @@ -495,10 +495,10 @@ export class FulfillmentProductService
value: query.shop_id
},
...(query.preferences?.couriers?.map(
att => ({
field: att.id,
id => ({
field: '_key', // _key is faster
operation: Filter_Operation.eq,
value: att.value,
value: id,
})
).filter(item => !!item) ?? [])
],
Expand Down Expand Up @@ -660,7 +660,7 @@ export class FulfillmentProductService
return super.upsert(request, context);
}

async find(request: PackingSolutionQueryList, context?: any): Promise<PackingSolutionListResponse> {
async find(request: FulfillmentSolutionQueryList, context?: any): Promise<FulfillmentSolutionListResponse> {
try {
const queries = buildQueryTotals(request.items);

Expand Down Expand Up @@ -942,7 +942,8 @@ export class FulfillmentProductService
shipping: null
});

const solutions: PackingSolution[] = offer_lists.map(
const courier_ids = new Set<string>();
const solutions: FulfillmentSolution[] = offer_lists.map(
offers => packer.canFit(offers, goods)
).map(
containers => {
Expand All @@ -969,6 +970,7 @@ export class FulfillmentProductService
vat: gross.multipliedBy(tax.rate).decimalPlaces(2).toNumber(),
}));
const net = vats.reduce((a, b) => a.plus(b.vat), gross).decimalPlaces(2).toNumber();
courier_ids.add(product?.courier_id);

return {
id: randomUUID(),
Expand Down Expand Up @@ -1027,9 +1029,10 @@ export class FulfillmentProductService
});

return {
courier_ids: [...courier_ids.values()],
parcels,
amounts,
};
} as FulfillmentSolution;
}
).sort(
(a, b) => Math.min(
Expand All @@ -1039,7 +1042,7 @@ export class FulfillmentProductService
)
);

const solution: PackingSolutionResponse = {
const solution: FulfillmentSolutionResponse = {
reference: query.reference,
solutions,
status: {
Expand All @@ -1058,7 +1061,7 @@ export class FulfillmentProductService
return solution;
}
catch (e: any) {
const solution: PackingSolutionResponse = {
const solution: FulfillmentSolutionResponse = {
reference: query.reference,
solutions: [],
status: this.catchStatusError(
Expand Down

0 comments on commit 4acf993

Please sign in to comment.