feat(manifest): add externalNumber reference to quote/order/delivery

- 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.
This commit is contained in:
seb
2026-08-08 09:13:20 +02:00
parent f302cda39e
commit 29099b2a16
23 changed files with 210 additions and 143 deletions

View File

@@ -17,13 +17,14 @@ export default function create(pool) {
* @param {string} body.number - The order number.
* @param {string} body.date - The order date.
* @param {number} [body.entityId] - The id of the customer entity.
* @param {string} [body.externalNumber] - An external (customer) reference number.
* @param {Array<object>} [body.lines] - The order lines.
* @returns {Promise<{id: number, number: string, type: string, entityId: number|null, date: string, lines: Array<object>}>} The created order.
* @returns {Promise<{id: number, number: string, type: string, entityId: number|null, externalNumber: string|null, date: string, lines: Array<object>}>} The created order.
* @throws {Error} If the order is invalid.
*
* @example
* const order = await store.order.create(42, { number: 'B-2026-001', date: '2026-09-15', entityId: 12, lines: [...] });
* // => { id, number, type, entityId, date, lines: [...] }
* // => { id, number, type, entityId, externalNumber, date, lines: [...] }
*/
return async (googleAuthId, body = {}) => {
const number = body.number?.trim?.() ? body.number.trim() : null;
@@ -31,6 +32,9 @@ export default function create(pool) {
if (!number || !date) {
throw new Error('Invalid order');
}
const externalNumber = body.externalNumber?.trim?.()
? body.externalNumber.trim()
: null;
const lines = normalizeLines(body.lines ?? []);
const { companyId, rootCategoryId } = await access(googleAuthId);
@@ -51,6 +55,7 @@ export default function create(pool) {
.input('number', number)
.input('type', ORDER_TYPE)
.input('entityId', entityId)
.input('externalNumber', externalNumber)
.input('date', date)
.query(CREATE_MANIFEST);

View File

@@ -10,12 +10,12 @@ export default function getById(pool) {
*
* @param {number} googleAuthId - The id of the Google auth user.
* @param {number} id - The id of the order.
* @returns {Promise<{id: number, number: string, type: string, entityId: number|null, date: string, lines: Array<object>}>} The order with its lines.
* @returns {Promise<{id: number, number: string, type: string, entityId: number|null, externalNumber: string|null, date: string, lines: Array<object>}>} The order with its lines.
* @throws {Error} If the order is not found.
*
* @example
* const order = await store.order.getById(42, 5);
* // => { id, number, type, entityId, date, lines: [...] }
* // => { id, number, type, entityId, externalNumber, date, lines: [...] }
*/
return async (googleAuthId, id) => {
if (!Number.isFinite(id)) {

View File

@@ -9,11 +9,11 @@ export default function list(pool) {
* Lists the orders of the user's selected company.
*
* @param {number} googleAuthId - The id of the Google auth user.
* @returns {Promise<Array<{id: number, number: string, type: string, entityId: number|null, date: string}>>} The orders.
* @returns {Promise<Array<{id: number, number: string, type: string, entityId: number|null, externalNumber: string|null, date: string}>>} The orders.
*
* @example
* const orders = await store.order.list(42);
* // => [{ id, number, type, entityId, date }]
* // => [{ id, number, type, entityId, externalNumber, date }]
*/
return async (googleAuthId) => {
const { companyId } = await access(googleAuthId);

View File

@@ -23,8 +23,9 @@ export default function update(pool) {
* @param {string} [patch.number] - The new order number.
* @param {string} [patch.date] - The new order date.
* @param {number} [patch.entityId] - The new customer entity id.
* @param {string} [patch.externalNumber] - The new external (customer) reference number.
* @param {Array<object>} [patch.lines] - The new order lines.
* @returns {Promise<{id: number, number: string, type: string, entityId: number|null, date: string, lines: Array<object>}>} The updated order.
* @returns {Promise<{id: number, number: string, type: string, entityId: number|null, externalNumber: string|null, date: string, lines: Array<object>}>} The updated order.
* @throws {Error} If the order is not found.
*
* @example
@@ -39,9 +40,10 @@ export default function update(pool) {
const hasNumber = Object.prototype.hasOwnProperty.call(patch, 'number');
const hasDate = Object.prototype.hasOwnProperty.call(patch, 'date');
const hasEntityId = Object.prototype.hasOwnProperty.call(patch, 'entityId');
const hasExternalNumber = Object.prototype.hasOwnProperty.call(patch, 'externalNumber');
const hasLines = Object.prototype.hasOwnProperty.call(patch, 'lines');
if (!hasNumber && !hasDate && !hasEntityId && !hasLines) {
if (!hasNumber && !hasDate && !hasEntityId && !hasExternalNumber && !hasLines) {
throw new Error('Invalid order');
}
@@ -95,12 +97,20 @@ export default function update(pool) {
);
}
let externalNumber = summary.externalNumber;
if (hasExternalNumber) {
externalNumber = patch.externalNumber?.trim?.()
? patch.externalNumber.trim()
: null;
}
await request(pool, tx)
.input('id', id)
.input('companyId', companyId)
.input('type', ORDER_TYPE)
.input('number', number)
.input('entityId', entityId)
.input('externalNumber', externalNumber)
.input('date', date)
.query(UPDATE_MANIFEST);