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.
31 lines
887 B
JavaScript
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);
|
|
};
|
|
}
|