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

@@ -3,6 +3,8 @@ import * as db from '../../db/labeltemplate.js';
import { renderThumb } from '../../services/labelThumb.js';
import { emit } from '../sse.js';
// #region Helpers
function requireSelectedCompany(req) {
const companyId = req.user?.selectedCompanyId;
if (companyId == null) {
@@ -34,6 +36,8 @@ function labeltemplateErrorStatus(error) {
return 500;
}
// #endregion
/**
* Registers label template routes for the authenticated user's selected company.
* @param {import('express').Application} app
@@ -75,6 +79,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region GET /labeltemplate
app.get(`${basePath}/labeltemplate`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -94,6 +100,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /labeltemplate/{id}:
@@ -140,6 +148,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region GET /labeltemplate/:id
app.get(`${basePath}/labeltemplate/:id`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -164,6 +174,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /labeltemplate:
@@ -207,6 +219,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region POST /labeltemplate
app.post(`${basePath}/labeltemplate`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -240,6 +254,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
async function handleUpdate(req, res) {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -389,9 +405,18 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region PATCH /labeltemplate/:id
app.patch(`${basePath}/labeltemplate/:id`, handleUpdate);
// #endregion
// #region PUT /labeltemplate/:id
app.put(`${basePath}/labeltemplate/:id`, handleUpdate);
// #endregion
/**
* @openapi
* /labeltemplate/{id}:
@@ -432,6 +457,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region DELETE /labeltemplate/:id
app.delete(`${basePath}/labeltemplate/:id`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -453,6 +480,8 @@ export function register(app, basePath = '') {
res.status(status).json({ error: error.message });
}
});
// #endregion
}
/**