u
This commit is contained in:
@@ -169,8 +169,10 @@ function deliveryErrorStatus(error) {
|
||||
if (error.message === 'File not found') return 404;
|
||||
if (error.message === 'Supplier not found') return 404;
|
||||
if (error.message === 'Warehouse not found') return 404;
|
||||
if (error.message === 'No supplier selected') return 400;
|
||||
if (error.message === 'Invalid supplierId') return 400;
|
||||
if (error.message === 'Article not found') return 404;
|
||||
if (error.message === 'Delivery number already exists') return 409;
|
||||
if (error.message === 'Invalid delivery') return 400;
|
||||
if (error.message === 'Invalid lines') return 400;
|
||||
if (error.message === 'Delivery has no lines') return 400;
|
||||
@@ -305,7 +307,7 @@ export function register(app, basePath = '') {
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required: [externalNumber, date, lines]
|
||||
* required: [externalNumber, date, supplierId, lines]
|
||||
* properties:
|
||||
* externalNumber:
|
||||
* type: string
|
||||
@@ -315,7 +317,6 @@ export function register(app, basePath = '') {
|
||||
* format: date-time
|
||||
* supplierId:
|
||||
* type: integer
|
||||
* nullable: true
|
||||
* lines:
|
||||
* type: array
|
||||
* items:
|
||||
@@ -497,6 +498,9 @@ export function register(app, basePath = '') {
|
||||
|
||||
try {
|
||||
const { externalNumber, date, createdAt, supplierId, lines, files } = parseDeliveryPayload(req);
|
||||
if (supplierId === undefined || supplierId === null) {
|
||||
return res.status(400).json({ error: 'No supplier selected' });
|
||||
}
|
||||
logDeliveryFiles(files, 'create');
|
||||
const delivery = await db.create(req.user.id, {
|
||||
externalNumber,
|
||||
@@ -795,6 +799,9 @@ export function register(app, basePath = '') {
|
||||
patch.createdAt = parsed.createdAt;
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(parsed.payload, 'supplierId')) {
|
||||
if (parsed.supplierId === null) {
|
||||
return res.status(400).json({ error: 'No supplier selected' });
|
||||
}
|
||||
patch.supplierId = parsed.supplierId;
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(parsed.payload, 'lines')) {
|
||||
|
||||
@@ -21,6 +21,8 @@ function orderErrorStatus(error) {
|
||||
if (error.message === 'Attachment not found') return 404;
|
||||
if (error.message === 'Entity not found') return 404;
|
||||
if (error.message === 'Article not found') return 404;
|
||||
if (error.message === 'No entity selected') return 400;
|
||||
if (error.message === 'Order number already exists') return 409;
|
||||
if (error.message === 'Invalid entityId') return 400;
|
||||
if (error.message === 'Invalid order') return 400;
|
||||
if (error.message === 'Invalid lines') return 400;
|
||||
@@ -148,7 +150,7 @@ export function register(app, basePath = '') {
|
||||
* description: |
|
||||
* Creates a sales order with header and lines in one transaction.
|
||||
* `date` is the document date (expected delivery).
|
||||
* `entityId` must be a company customer (not Lieferanten), or null.
|
||||
* `entityId` must be a company customer (not Lieferanten).
|
||||
* Each line requires `sku` or `name`, `amount`, `net`, and `taxrate` (rate); `pu` defaults to `1`; `rebate` defaults to `0`.
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
@@ -159,7 +161,7 @@ export function register(app, basePath = '') {
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required: [number, date, lines]
|
||||
* required: [number, date, entityId, lines]
|
||||
* properties:
|
||||
* number:
|
||||
* type: string
|
||||
@@ -169,7 +171,6 @@ export function register(app, basePath = '') {
|
||||
* description: Document date / expected delivery
|
||||
* entityId:
|
||||
* type: integer
|
||||
* nullable: true
|
||||
* description: Customer entity (manifest.entity_id)
|
||||
* externalNumber:
|
||||
* type: string
|
||||
@@ -297,7 +298,10 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
|
||||
const { number, date, createdAt, entityId, externalNumber, lines } = req.body ?? {};
|
||||
if (entityId !== undefined && entityId !== null && (typeof entityId !== 'number' || !Number.isInteger(entityId) || entityId <= 0)) {
|
||||
if (entityId === undefined || entityId === null) {
|
||||
return res.status(400).json({ error: 'No entity selected' });
|
||||
}
|
||||
if (typeof entityId !== 'number' || !Number.isInteger(entityId) || entityId <= 0) {
|
||||
return res.status(400).json({ error: 'Invalid entityId' });
|
||||
}
|
||||
|
||||
@@ -538,7 +542,10 @@ export function register(app, basePath = '') {
|
||||
patch.createdAt = body.createdAt;
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(body, 'entityId')) {
|
||||
if (body.entityId !== null && (typeof body.entityId !== 'number' || !Number.isInteger(body.entityId) || body.entityId <= 0)) {
|
||||
if (body.entityId === null) {
|
||||
return res.status(400).json({ error: 'No entity selected' });
|
||||
}
|
||||
if (typeof body.entityId !== 'number' || !Number.isInteger(body.entityId) || body.entityId <= 0) {
|
||||
return res.status(400).json({ error: 'Invalid entityId' });
|
||||
}
|
||||
patch.entityId = body.entityId;
|
||||
|
||||
@@ -26,6 +26,7 @@ function quoteErrorStatus(error) {
|
||||
if (error.message === 'Entity not found') return 404;
|
||||
if (error.message === 'Article not found') return 404;
|
||||
if (error.message === 'Invalid entityId') return 400;
|
||||
if (error.message === 'Quote number already exists') return 409;
|
||||
if (error.message === 'Invalid quote') return 400;
|
||||
if (error.message === 'Invalid order') return 400;
|
||||
if (error.message === 'Invalid lines') return 400;
|
||||
|
||||
@@ -37,6 +37,7 @@ function shipmentErrorStatus(error) {
|
||||
}
|
||||
if (
|
||||
error.message?.startsWith('Shipment amount exceeds') ||
|
||||
error.message === 'Shipment number already exists' ||
|
||||
error.message?.includes('cannot be deleted') ||
|
||||
error.message?.includes('cannot be undone') ||
|
||||
error.message?.includes('already shipped')
|
||||
|
||||
Reference in New Issue
Block a user