Skip to content

Commit c4c7359

Browse files
author
Gerald Baulig
committed
fix(aggregation): aggregate countries from custom addresses
1 parent fa23c41 commit c4c7359

File tree

1 file changed

+22
-40
lines changed

1 file changed

+22
-40
lines changed

src/service.ts

+22-40
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,17 @@ export class OrderingService
12661266
address_map
12671267
).map(
12681268
item => item.payload?.country_id
1269-
)
1269+
),
1270+
...(
1271+
order_list.items?.map(
1272+
order => order.billing_address?.address?.country_id
1273+
) ?? []
1274+
),
1275+
...(
1276+
order_list.items?.map(
1277+
order => order.shipping_address?.address?.country_id
1278+
) ?? []
1279+
),
12701280
],
12711281
this.country_service,
12721282
'countries',
@@ -1785,11 +1795,12 @@ export class OrderingService
17851795
context?: any
17861796
): Promise<OrderListResponse> {
17871797
try {
1788-
return await this.aggregateOrders(
1798+
const orders = await this.aggregateOrders(
17891799
request,
17901800
request.subject,
17911801
context
17921802
);
1803+
return orders;
17931804
}
17941805
catch (e) {
17951806
return this.catchOperationError(e);
@@ -2427,23 +2438,21 @@ export class OrderingService
24272438
orders?: OrderMap,
24282439
): Promise<FulfillmentListResponse> {
24292440
try {
2430-
orders ??= await this.getOrderMap(
2431-
request.items?.map(item => item.order_id!),
2432-
request.subject,
2433-
context
2434-
) ?? {};
2435-
2436-
const prototypes = await this.toFulfillmentResponsePrototypes(
2441+
const evaluated = await this._evaluateFulfillment(
24372442
request,
24382443
context,
24392444
orders,
24402445
);
24412446

2442-
const invalids = prototypes.filter(
2447+
if (evaluated?.operation_status?.code >= 300) {
2448+
throw evaluated.operation_status;
2449+
}
2450+
2451+
const invalids = evaluated?.items?.filter(
24432452
item => item.status?.code !== 200
24442453
);
24452454

2446-
const valids = prototypes.filter(
2455+
const valids = evaluated?.items?.filter(
24472456
item => item.status?.code === 200
24482457
).map(
24492458
item => {
@@ -2455,41 +2464,14 @@ export class OrderingService
24552464
return item;
24562465
}
24572466
);
2458-
2459-
const evaluated = valids.length ? await this.fulfillment_service.evaluate(
2467+
2468+
const created = valids?.length ? await this.fulfillment_service.create(
24602469
{
24612470
items: valids.map(item => item.payload),
24622471
total_count: valids.length,
24632472
subject: this.fulfillment_tech_user ?? this.ApiKey ?? request.subject,
24642473
},
24652474
context
2466-
).then(
2467-
response => {
2468-
if (response.operation_status?.code !== 200) {
2469-
throw response.operation_status;
2470-
}
2471-
response.items = response.items?.filter(
2472-
item => {
2473-
if (item.status?.code === 200) {
2474-
return true;
2475-
}
2476-
else {
2477-
invalids.push(item);
2478-
return false;
2479-
}
2480-
}
2481-
);
2482-
return response;
2483-
}
2484-
) : undefined;
2485-
2486-
const created = evaluated?.items?.length ? await this.fulfillment_service.create(
2487-
{
2488-
items: evaluated.items.map(item => item.payload),
2489-
total_count: evaluated.items.length,
2490-
subject: this.fulfillment_tech_user ?? this.ApiKey ?? request.subject,
2491-
},
2492-
context
24932475
).then(
24942476
response => {
24952477
if (response?.operation_status?.code !== 200) {

0 commit comments

Comments
 (0)