This commit is contained in:
seb
2026-10-15 00:30:23 +02:00
parent bdd7ebf5b8
commit 8c55f899b5
27 changed files with 136 additions and 46 deletions

View File

@@ -1,4 +1,5 @@
import { getStore } from './store.js';
import { formatAttachments } from '../util/manifestAttachment.js';
function round2(num) {
return Math.round((Number(num) || 0) * 100) / 100;
@@ -46,13 +47,14 @@ function calculateShippedQuantity(shipments = []) {
async function enrichSingleOrder(store, googleAuthId, order) {
if (!order) return order;
const [shippings, payments, shipments, files] = await Promise.all([
const [shippings, payments, shipments, rawFiles] = 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 files = await formatAttachments(rawFiles);
const orderLines = Array.isArray(order.lines) ? order.lines : [];
const paymentsList = Array.isArray(payments) ? payments : [];
const shipmentsList = Array.isArray(shipments) ? shipments : [];
@@ -165,12 +167,14 @@ export async function getFile(googleAuthId, orderId, fileId) {
export async function addAttachment(googleAuthId, orderId, data) {
const store = await getStore();
return store.manifestattachment.add(googleAuthId, orderId, data);
const raw = await store.manifestattachment.add(googleAuthId, orderId, data);
return formatAttachments([raw]).then((r) => r[0]);
}
export async function listAttachments(googleAuthId, orderId) {
const store = await getStore();
return store.manifestattachment.listByManifestId(googleAuthId, orderId);
const raw = await store.manifestattachment.listByManifestId(googleAuthId, orderId);
return formatAttachments(raw);
}
export async function removeAttachment(googleAuthId, orderId, fileId) {