This commit is contained in:
seb
2026-09-30 22:37:34 +02:00
parent 71c92e0718
commit 120e59631e
16 changed files with 137 additions and 35 deletions

View File

@@ -35,6 +35,7 @@ function articleSupplierErrorStatus(error) {
if (error.message === 'Company not found') return 404;
if (error.message === 'Article not found') return 404;
if (error.message === 'Supplier not found') return 404;
if (error.message === 'Invalid supplierId') return 400;
if (error.message === 'Supplier assignment not found') return 404;
if (error.message === 'Supplier already assigned') return 409;
if (error.message === 'Supplier required' || error.message === 'entityId is required') return 400;
@@ -245,21 +246,30 @@ export function register(app, basePath = '') {
}
const { entityId, sku: supplierSku, pu, stock, sort, netPrice, taxId, taxRate } = req.body ?? {};
if (entityId == null || !Number.isFinite(entityId)) {
if (entityId == null) {
return res.status(400).json({ error: 'entityId is required' });
}
if (pu !== undefined && pu !== null && (!Number.isFinite(pu) || pu <= 0)) {
if (typeof entityId !== 'number' || !Number.isInteger(entityId) || entityId <= 0) {
return res.status(400).json({ error: 'entityId must be an integer' });
}
if (pu !== undefined && pu !== null && (typeof pu !== 'number' || !Number.isFinite(pu) || pu <= 0)) {
return res.status(400).json({ error: 'pu must be greater than 0' });
}
if (stock !== undefined && stock !== null && !Number.isFinite(stock)) {
if (stock !== undefined && stock !== null && (typeof stock !== 'number' || !Number.isFinite(stock))) {
return res.status(400).json({ error: 'Invalid stock' });
}
if (sort !== undefined && sort !== null && (!Number.isInteger(sort) || sort < 0)) {
if (sort !== undefined && sort !== null && (typeof sort !== 'number' || !Number.isInteger(sort) || sort < 0)) {
return res.status(400).json({ error: 'Invalid sort' });
}
if (netPrice !== undefined && netPrice !== null && !Number.isFinite(netPrice)) {
if (netPrice !== undefined && netPrice !== null && (typeof netPrice !== 'number' || !Number.isFinite(netPrice) || netPrice < 0)) {
return res.status(400).json({ error: 'Invalid price' });
}
if (taxId !== undefined && taxId !== null && (typeof taxId !== 'number' || !Number.isInteger(taxId) || taxId <= 0)) {
return res.status(400).json({ error: 'Invalid taxId' });
}
if (taxRate !== undefined && taxRate !== null && (typeof taxRate !== 'number' || !Number.isFinite(taxRate) || taxRate < 0)) {
return res.status(400).json({ error: 'Invalid taxRate' });
}
try {
const supplier = await db.create(req.user.id, skuParsed.sku, {
@@ -465,8 +475,18 @@ export function register(app, basePath = '') {
}
patch.netPrice = body.netPrice;
}
if (body.taxId !== undefined) patch.taxId = body.taxId;
if (body.taxRate !== undefined) patch.taxRate = body.taxRate;
if (body.taxId !== undefined) {
if (body.taxId !== null && (typeof body.taxId !== 'number' || !Number.isInteger(body.taxId) || body.taxId <= 0)) {
return res.status(400).json({ error: 'Invalid taxId' });
}
patch.taxId = body.taxId;
}
if (body.taxRate !== undefined) {
if (body.taxRate !== null && (typeof body.taxRate !== 'number' || !Number.isFinite(body.taxRate) || body.taxRate < 0)) {
return res.status(400).json({ error: 'Invalid taxRate' });
}
patch.taxRate = body.taxRate;
}
try {
const supplier = await db.update(req.user.id, skuParsed.sku, idParsed.id, patch);