This commit is contained in:
seb
2026-10-14 23:26:09 +02:00
parent 0ea7da4f3a
commit 507dffa567
18 changed files with 552 additions and 9 deletions

View File

@@ -591,5 +591,89 @@ export function register(app, basePath = '') {
});
// #endregion
/**
* @openapi
* /shipment/{id}/file/{fileId}:
* delete:
* tags: [Shipment]
* summary: Delete shipment file attachment
* description: |
* Removes a file attachment from the shipment and deletes the underlying file.
* security:
* - cookieAuth: []
* x-signals: [shipment, order]
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: integer
* description: Shipment ID
* - in: path
* name: fileId
* required: true
* schema:
* type: integer
* description: File ID or attachment ID
* responses:
* 204:
* description: Attachment deleted
* 400:
* description: Invalid parameters 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: Not authorized
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* 404:
* description: Shipment or attachment not found
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region DELETE /shipment/:id/file/:fileId
app.delete(`${basePath}/shipment/:id/file/:fileId`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
return res.status(400).json({ error: selected.error });
}
const id = Number(req.params.id);
if (!Number.isInteger(id) || id <= 0) {
return res.status(400).json({ error: 'id is required' });
}
const fileId = Number(req.params.fileId);
if (!Number.isInteger(fileId) || fileId <= 0) {
return res.status(400).json({ error: 'fileId is required' });
}
try {
await db.removeAttachment(req.user.id, id, fileId);
emitShipmentEvents(selected.companyId);
res.sendStatus(204);
} catch (error) {
const status = shipmentErrorStatus(error);
if (status === 500) console.error('Delete shipment attachment failed:', error);
res.status(status).json({ error: error.message });
}
});
// #endregion
}