u
This commit is contained in:
@@ -17,6 +17,7 @@ function attributeErrorStatus(error) {
|
||||
if (error.message === 'Name required') return 400;
|
||||
if (error.message === 'Invalid attribute name order') return 400;
|
||||
if (error.message === 'Invalid id') return 400;
|
||||
if (error.message === 'Attribute name in use' || error.message?.includes('FOREIGN KEY constraint')) return 409;
|
||||
return 500;
|
||||
}
|
||||
|
||||
@@ -200,6 +201,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 name not found
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
* 409:
|
||||
* description: Attribute 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}/attributename/:id`, async (req, res) => {
|
||||
const selected = requireSelectedCompany(req);
|
||||
@@ -213,7 +250,9 @@ export function register(app, basePath = '') {
|
||||
emit('attributename', { companyId: selected.companyId });
|
||||
res.json({ attributename });
|
||||
} catch (error) {
|
||||
res.status(attributeErrorStatus(error)).json({ error: error.message });
|
||||
const status = attributeErrorStatus(error);
|
||||
if (status === 500) console.error('Update attribute name failed:', error);
|
||||
res.status(status).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -229,7 +268,12 @@ export function register(app, basePath = '') {
|
||||
emit('attributename', { companyId: selected.companyId });
|
||||
res.json({ ok: true });
|
||||
} catch (error) {
|
||||
res.status(attributeErrorStatus(error)).json({ error: error.message });
|
||||
const status = attributeErrorStatus(error);
|
||||
const message = (error.message === 'Attribute name in use' || error.message?.includes('FOREIGN KEY constraint'))
|
||||
? 'Attribute name in use'
|
||||
: error.message;
|
||||
if (status === 500) console.error('Delete attribute name failed:', error);
|
||||
res.status(status).json({ error: message });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user