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/entity.js';
// #region Helpers
function requireSelectedCompany(req) {
const companyId = req.user.selectedCompanyId;
if (companyId == null) {
@@ -22,6 +24,8 @@ function entityErrorStatus(error) {
return 500;
}
// #endregion
/**
* Registers entity routes for the authenticated user's selected company.
* @param {import('express').Application} app
@@ -162,6 +166,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region GET /entity
app.get(`${basePath}/entity`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -190,6 +196,10 @@ export function register(app, basePath = '') {
}
});
// #endregion
// #region POST /entity
app.post(`${basePath}/entity`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -219,6 +229,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /entity/next-number:
@@ -269,6 +281,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region GET /entity/next-number
app.get(`${basePath}/entity/next-number`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -285,6 +299,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /entity/{id}:
@@ -451,6 +467,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region GET /entity/:id
app.get(`${basePath}/entity/:id`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -472,6 +490,10 @@ export function register(app, basePath = '') {
}
});
// #endregion
// #region PATCH /entity/:id
app.patch(`${basePath}/entity/:id`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -505,6 +527,10 @@ export function register(app, basePath = '') {
}
});
// #endregion
// #region DELETE /entity/:id
app.delete(`${basePath}/entity/:id`, async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -525,4 +551,6 @@ export function register(app, basePath = '') {
res.status(status).json({ error: error.message });
}
});
// #endregion
}