u
This commit is contained in:
@@ -84,15 +84,39 @@ async function enrichSingleOrder(store, googleAuthId, order) {
|
||||
};
|
||||
}
|
||||
|
||||
function formatEnrichedFromSummary(order) {
|
||||
const grossTotal = Number(order.grossTotal || 0);
|
||||
const paidTotal = Number(order.paidTotal || 0);
|
||||
const orderedQuantity = Number(order.orderedQuantity || 0);
|
||||
const shippedQuantity = Number(order.shippedQuantity || 0);
|
||||
const isPaid = Boolean(order.isPaid);
|
||||
const isShipped = Boolean(order.isShipped);
|
||||
|
||||
return {
|
||||
...order,
|
||||
shipping: null,
|
||||
shippings: [],
|
||||
payment: null,
|
||||
payments: [],
|
||||
shipments: [],
|
||||
orderTotal: grossTotal,
|
||||
paidTotal,
|
||||
orderedQuantity,
|
||||
shippedQuantity,
|
||||
paid: isPaid,
|
||||
shipped: isShipped,
|
||||
delivered: isShipped,
|
||||
};
|
||||
}
|
||||
|
||||
async function enrichOrderResult(store, googleAuthId, result) {
|
||||
if (!result) return result;
|
||||
const enrich = (o) => (o?.grossTotal !== undefined ? formatEnrichedFromSummary(o) : enrichSingleOrder(store, googleAuthId, o));
|
||||
if (Array.isArray(result)) {
|
||||
return Promise.all(result.map((o) => enrichSingleOrder(store, googleAuthId, o)));
|
||||
return Promise.all(result.map(enrich));
|
||||
}
|
||||
if (Array.isArray(result.orders)) {
|
||||
const enrichedOrders = await Promise.all(
|
||||
result.orders.map((o) => enrichSingleOrder(store, googleAuthId, o))
|
||||
);
|
||||
const enrichedOrders = await Promise.all(result.orders.map(enrich));
|
||||
return {
|
||||
...result,
|
||||
orders: enrichedOrders,
|
||||
|
||||
Reference in New Issue
Block a user