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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user