This commit is contained in:
seb
2026-10-14 19:43:53 +02:00
parent 04e10cffdb
commit 9c54a8a1d3
3 changed files with 581 additions and 1 deletions

View File

@@ -46,16 +46,18 @@ function calculateShippedQuantity(shipments = []) {
async function enrichSingleOrder(store, googleAuthId, order) {
if (!order) return order;
const [shippings, payments, shipments] = await Promise.all([
const [shippings, payments, shipments, files] = await Promise.all([
store.shipping.listByManifestId(googleAuthId, order.id).catch(() => []),
store.payment.listByManifestId(googleAuthId, order.id).catch(() => []),
store.shipment.listByOrderId(googleAuthId, order.id).catch(() => []),
store.manifestattachment.listByManifestId(googleAuthId, order.id).catch(() => []),
]);
const orderLines = Array.isArray(order.lines) ? order.lines : [];
const paymentsList = Array.isArray(payments) ? payments : [];
const shipmentsList = Array.isArray(shipments) ? shipments : [];
const shippingsList = Array.isArray(shippings) ? shippings : [];
const filesList = Array.isArray(files) ? files : [];
const orderTotal = calculateOrderGrossTotal(orderLines);
const paidTotal = calculatePaidTotal(paymentsList);
@@ -74,6 +76,7 @@ async function enrichSingleOrder(store, googleAuthId, order) {
payment: paymentsList[0] ?? null,
payments: paymentsList,
shipments: shipmentsList,
files: filesList,
orderTotal,
paidTotal,
orderedQuantity,
@@ -99,6 +102,7 @@ function formatEnrichedFromSummary(order) {
payment: null,
payments: [],
shipments: [],
files: [],
orderTotal: grossTotal,
paidTotal,
orderedQuantity,
@@ -154,3 +158,19 @@ export async function remove(googleAuthId, id) {
return store.order.delete(googleAuthId, id);
}
export async function getFile(googleAuthId, orderId, fileId) {
const store = await getStore();
return store.manifestattachment.getById(googleAuthId, orderId, fileId);
}
export async function addAttachment(googleAuthId, orderId, data) {
const store = await getStore();
return store.manifestattachment.add(googleAuthId, orderId, data);
}
export async function listAttachments(googleAuthId, orderId) {
const store = await getStore();
return store.manifestattachment.listByManifestId(googleAuthId, orderId);
}