This commit is contained in:
seb
2026-10-13 13:21:14 +02:00
parent 8acca998bc
commit 2de2bc0d90
9 changed files with 3516 additions and 6 deletions

View File

@@ -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,