Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: release #106

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 23 additions & 41 deletions src/service.ts
Original file line number Diff line number Diff line change
@@ -360,7 +360,7 @@ export class OrderingService
SOLUTION_NOT_FOUND: {
id: '',
code: 404,
message: 'Solution for {entity} {id} not found!',
message: 'Solution for {entity} {id} not found!',
}
};

@@ -1266,7 +1266,17 @@ export class OrderingService
address_map
).map(
item => item.payload?.country_id
)
),
...(
order_list.items?.map(
order => order.billing_address?.address?.country_id
) ?? []
),
...(
order_list.items?.map(
order => order.shipping_address?.address?.country_id
) ?? []
),
],
this.country_service,
'countries',
@@ -1785,11 +1795,12 @@ export class OrderingService
context?: any
): Promise<OrderListResponse> {
try {
return await this.aggregateOrders(
const orders = await this.aggregateOrders(
request,
request.subject,
context
);
return orders;
}
catch (e) {
return this.catchOperationError(e);
@@ -1901,7 +1912,7 @@ export class OrderingService
r => {
r.items?.forEach(
fulfillment => {
const id = fulfillment.payload?.references?.[0]?.instance_id ?? fulfillment.status?.id
const id = fulfillment.payload?.references?.[0]?.instance_id ?? fulfillment.status?.id;
const order = response_map[id];
if (order && fulfillment.status?.code !== 200) {
order.status = fulfillment.status;
@@ -2427,23 +2438,21 @@ export class OrderingService
orders?: OrderMap,
): Promise<FulfillmentListResponse> {
try {
orders ??= await this.getOrderMap(
request.items?.map(item => item.order_id!),
request.subject,
context
) ?? {};

const prototypes = await this.toFulfillmentResponsePrototypes(
const evaluated = await this._evaluateFulfillment(
request,
context,
orders,
);

const invalids = prototypes.filter(
if (evaluated?.operation_status?.code >= 300) {
throw evaluated.operation_status;
}

const invalids = evaluated?.items?.filter(
item => item.status?.code !== 200
);

const valids = prototypes.filter(
const valids = evaluated?.items?.filter(
item => item.status?.code === 200
).map(
item => {
@@ -2456,40 +2465,13 @@ export class OrderingService
}
);

const evaluated = valids.length ? await this.fulfillment_service.evaluate(
const created = valids?.length ? await this.fulfillment_service.create(
{
items: valids.map(item => item.payload),
total_count: valids.length,
subject: this.fulfillment_tech_user ?? this.ApiKey ?? request.subject,
},
context
).then(
response => {
if (response.operation_status?.code !== 200) {
throw response.operation_status;
}
response.items = response.items?.filter(
item => {
if (item.status?.code === 200) {
return true;
}
else {
invalids.push(item);
return false;
}
}
);
return response;
}
) : undefined;

const created = evaluated?.items?.length ? await this.fulfillment_service.create(
{
items: evaluated.items.map(item => item.payload),
total_count: evaluated.items.length,
subject: this.fulfillment_tech_user ?? this.ApiKey ?? request.subject,
},
context
).then(
response => {
if (response?.operation_status?.code !== 200) {
15 changes: 15 additions & 0 deletions test/mocks.ts
Original file line number Diff line number Diff line change
@@ -1090,6 +1090,21 @@ export const rules = {
totalCount: 1,
operationStatus
}),
evaluate: (
call: any,
callback: (error: any, response: FulfillmentListResponse) => void,
) => callback(null, {
items: call.request.items.map(
(item: FulfillmentResponse) => ({
payload: item,
status: {
code: 200,
}
})
),
totalCount: 1,
operationStatus
}),
},
invoice: {
create: (