This commit is contained in:
seb
2026-10-04 11:25:17 +02:00
parent e5ff4ef307
commit 43fa8ea105
24 changed files with 1016 additions and 214 deletions

View File

@@ -16,6 +16,7 @@ function attributeValueErrorStatus(error) {
if (error.message === 'Value required') return 400;
if (error.message === 'Invalid attribute value order') return 400;
if (error.message === 'Invalid id' || error.message === 'Invalid attributeId') return 400;
if (error.message === 'Attribute value in use' || error.message?.includes('FOREIGN KEY constraint')) return 409;
return 500;
}
@@ -216,6 +217,42 @@ export function register(app, basePath = '') {
* responses:
* 200:
* description: Deleted successfully
* 400:
* description: Bad request or no company selected
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 401:
* description: Unauthorized
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 403:
* description: Forbidden
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 404:
* description: Attribute value not found
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 409:
* description: Attribute value in use
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 500:
* description: Server error
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
*/
app.patch(`${basePath}/attributevalue/:id`, async (req, res) => {
const selected = requireSelectedCompany(req);
@@ -229,7 +266,9 @@ export function register(app, basePath = '') {
emit('attributename', { companyId: selected.companyId });
res.json({ attributevalue });
} catch (error) {
res.status(attributeValueErrorStatus(error)).json({ error: error.message });
const status = attributeValueErrorStatus(error);
if (status === 500) console.error('Update attribute value failed:', error);
res.status(status).json({ error: error.message });
}
});
@@ -245,7 +284,12 @@ export function register(app, basePath = '') {
emit('attributename', { companyId: selected.companyId });
res.json({ ok: true });
} catch (error) {
res.status(attributeValueErrorStatus(error)).json({ error: error.message });
const status = attributeValueErrorStatus(error);
const message = (error.message === 'Attribute value in use' || error.message?.includes('FOREIGN KEY constraint'))
? 'Attribute value in use'
: error.message;
if (status === 500) console.error('Delete attribute value failed:', error);
res.status(status).json({ error: message });
}
});
}