u
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import multer from 'multer';
|
||||
import * as db from '../../db/delivery.js';
|
||||
import { createAndAttachManifestPdf } from '../../services/manifestPdf.js';
|
||||
import { writeErrorLog } from '../../util/errorLog.js';
|
||||
|
||||
// #region Helpers
|
||||
@@ -902,4 +903,97 @@ export function register(app, basePath = '') {
|
||||
app.get(`${basePath}/delivery/:id/files/:fileId`, handleGetDeliveryFile);
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /delivery/{id}/pdf:
|
||||
* post:
|
||||
* tags: [Delivery]
|
||||
* summary: Generate and attach delivery note PDF (goods receipt)
|
||||
* description: |
|
||||
* Generates an A4 PDF document for the goods receipt / delivery note with line items and quantities.
|
||||
* Attaches the PDF as a `manifestattachment` to the delivery.
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* x-signals: [delivery]
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: Delivery ID
|
||||
* responses:
|
||||
* 201:
|
||||
* description: PDF generated and attached to delivery
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required: [attachment, fileUrl]
|
||||
* properties:
|
||||
* attachment:
|
||||
* $ref: '#/components/schemas/DeliveryFile'
|
||||
* fileUrl:
|
||||
* type: string
|
||||
* example: /delivery/1/file/5
|
||||
* 400:
|
||||
* description: Invalid ID 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 not found
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region POST /delivery/:id/pdf
|
||||
|
||||
app.post(`${basePath}/delivery/:id/pdf`, 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' });
|
||||
}
|
||||
|
||||
try {
|
||||
const { attachment } = await createAndAttachManifestPdf(
|
||||
req.user.id,
|
||||
selected.companyId,
|
||||
id,
|
||||
'delivery'
|
||||
);
|
||||
|
||||
res.status(201).json({
|
||||
attachment,
|
||||
fileUrl: `/delivery/${id}/file/${attachment.fileId}`,
|
||||
});
|
||||
} catch (error) {
|
||||
const status = deliveryErrorStatus(error);
|
||||
if (status === 500) console.error('Create delivery PDF failed:', error);
|
||||
res.status(status).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user