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

@@ -17,6 +17,7 @@ function propertyErrorStatus(error) {
if (error.message === 'Name required') return 400;
if (error.message === 'Invalid property name order') return 400;
if (error.message === 'Invalid id') return 400;
if (error.message === 'Property name in use' || error.message?.includes('FOREIGN KEY constraint')) return 409;
return 500;
}
@@ -214,6 +215,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: Property name not found
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 409:
* description: Property name 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}/propertyname/:id`, async (req, res) => {
const selected = requireSelectedCompany(req);
@@ -227,7 +264,9 @@ export function register(app, basePath = '') {
emit('propertyname', { companyId: selected.companyId });
res.json({ propertyname });
} catch (error) {
res.status(propertyErrorStatus(error)).json({ error: error.message });
const status = propertyErrorStatus(error);
if (status === 500) console.error('Update property name failed:', error);
res.status(status).json({ error: error.message });
}
});
@@ -243,7 +282,12 @@ export function register(app, basePath = '') {
emit('propertyname', { companyId: selected.companyId });
res.json({ ok: true });
} catch (error) {
res.status(propertyErrorStatus(error)).json({ error: error.message });
const status = propertyErrorStatus(error);
const message = (error.message === 'Property name in use' || error.message?.includes('FOREIGN KEY constraint'))
? 'Property name in use'
: error.message;
if (status === 500) console.error('Delete property name failed:', error);
res.status(status).json({ error: message });
}
});
}