file meta

This commit is contained in:
seb
2026-09-18 05:19:47 +02:00
parent e10a8d10e7
commit 9e9d3154ca
17 changed files with 896 additions and 623 deletions

View File

@@ -1,6 +1,8 @@
import { DELIVERY_TYPE, LIST_DELIVERIES } from '../../sql/delivery.js';
import { DELIVERY_TYPE, LIST_DELIVERIES, LIST_DELIVERY_FILES } from '../../sql/delivery.js';
import request from '../request.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
import { shapeSummary } from './helpers.js';
import { shapeAttachmentMeta } from './attachments.js';
export default function list(pool) {
const access = resolveSelectedCompanyAccess(pool);
@@ -24,6 +26,22 @@ export default function list(pool) {
.input('type', DELIVERY_TYPE)
.query(LIST_DELIVERIES);
return result.recordset.map(shapeSummary);
const filesResult = await pool
.request()
.input('companyId', companyId)
.input('type', DELIVERY_TYPE)
.query(LIST_DELIVERY_FILES);
const filesByManifest = new Map();
for (const row of filesResult.recordset) {
const list = filesByManifest.get(row.manifestId) ?? [];
list.push(shapeAttachmentMeta(row));
filesByManifest.set(row.manifestId, list);
}
return result.recordset.map((row) => ({
...shapeSummary(row),
files: filesByManifest.get(row.id) ?? [],
}));
};
}