This commit is contained in:
seb
2026-10-10 02:08:10 +02:00
parent d4e2b05cb0
commit 7f8661be3e
43 changed files with 3312 additions and 2339 deletions

View File

@@ -1,5 +1,7 @@
import * as db from '../../db/shipping.js';
// #region Helpers
function requireSelectedCompany(req) {
const companyId = req.user?.selectedCompanyId;
if (companyId == null) {
@@ -24,6 +26,8 @@ function shippingErrorStatus(error) {
return 500;
}
// #endregion
/**
* Registers shipping routes (shippings belong to an order / manifest).
* @param {import('express').Application} app
@@ -77,6 +81,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region GET /order/:id/shipping
app.get(`${basePath}/order/:id/shipping`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -98,6 +104,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /order/{id}/shipping:
@@ -163,6 +171,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region POST /order/:id/shipping
app.post(`${basePath}/order/:id/shipping`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -187,6 +197,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /shipping/{id}:
@@ -225,6 +237,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region DELETE /shipping/:id
app.delete(`${basePath}/shipping/:id`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -245,4 +259,6 @@ export function register(app, basePath = '') {
res.status(status).json({ error: error.message });
}
});
// #endregion
}