Files
dashlibstorage/src/store/delivery/list.js
seb 70e0a9ddc4 Add entity customer numbers and scope APIs via selected company.
Entity gets an optional unique-per-company number with allocate/peek/isNumberFree helpers. Company-scoped store methods no longer take companyId and resolve google_auth.selected_company instead.
2026-08-07 04:29:35 +02:00

31 lines
887 B
JavaScript

import { DELIVERY_TYPE, LIST_DELIVERIES } from '../../sql/delivery.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
import { shapeSummary } from './helpers.js';
/**
* Lists the deliveries of a company.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that lists deliveries.
*
* @example
* const fn = list(pool);
* const deliveries = await fn(42);
* // => [{ id, number, type, entityId, date }]
*/
export default function list(pool) {
const access = resolveSelectedCompanyAccess(pool);
return async (googleAuthId) => {
const { companyId } = await access(googleAuthId);
const result = await pool
.request()
.input('companyId', companyId)
.input('type', DELIVERY_TYPE)
.query(LIST_DELIVERIES);
return result.recordset.map(shapeSummary);
};
}