file meta
This commit is contained in:
@@ -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) ?? [],
|
||||
}));
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user