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); }; }