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

@@ -2,6 +2,7 @@ import multer from 'multer';
import * as db from '../../db/delivery.js';
import { createAndAttachManifestPdf } from '../../services/manifestPdf.js';
import { writeErrorLog } from '../../util/errorLog.js';
import { emit } from '../sse.js';
// #region Helpers
@@ -995,5 +996,89 @@ export function register(app, basePath = '') {
});
// #endregion
/**
* @openapi
* /delivery/{id}/file/{fileId}:
* delete:
* tags: [Delivery]
* summary: Delete delivery file attachment
* description: |
* Removes a file attachment from the delivery and deletes the underlying file.
* security:
* - cookieAuth: []
* x-signals: [delivery]
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: integer
* description: Delivery 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: Delivery or attachment not found
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region DELETE /delivery/:id/file/:fileId
app.delete(`${basePath}/delivery/: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);
emit('delivery', { companyId: selected.companyId });
res.sendStatus(204);
} catch (error) {
const status = deliveryErrorStatus(error);
if (status === 500) console.error('Delete delivery attachment failed:', error);
res.status(status).json({ error: error.message });
}
});
// #endregion
}