- Add `external_number NVARCHAR(100)` column to the `manifest` table. - Thread `externalNumber` through manifestDoc and delivery SQL (list, header, create, update). - Include `externalNumber` in shapeSummary and quote/order/delivery create/update/list/getById handlers (optional, clearable on update). - Update README type definitions and regenerate API/schema docs.
33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
|
|
import { loadDelivery } from './helpers.js';
|
|
|
|
export default function getById(pool) {
|
|
const access = resolveSelectedCompanyAccess(pool);
|
|
|
|
/**
|
|
* Returns a single delivery by its id within the user's selected company.
|
|
*
|
|
* @param {number} googleAuthId - The id of the Google auth user.
|
|
* @param {number} id - The id of the delivery.
|
|
* @returns {Promise<{id: number, number: string, type: string, entityId: number, externalNumber: string|null, date: string, lines: Array<object>}>} The delivery.
|
|
* @throws {Error} If the delivery is not found.
|
|
*
|
|
* @example
|
|
* const delivery = await store.delivery.getById(42, 5);
|
|
* // => { id, number, type, entityId, externalNumber, date, lines: [...] }
|
|
*/
|
|
return async (googleAuthId, id) => {
|
|
if (!Number.isFinite(id)) {
|
|
throw new Error('Delivery not found');
|
|
}
|
|
|
|
const { companyId } = await access(googleAuthId);
|
|
|
|
const delivery = await loadDelivery(pool, null, companyId, id);
|
|
if (!delivery) {
|
|
throw new Error('Delivery not found');
|
|
}
|
|
return delivery;
|
|
};
|
|
}
|