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/publicCatalog.js';
// #region Helpers
function parseCompanyId(id) {
const companyId = Number(id);
if (!Number.isInteger(companyId) || companyId <= 0) {
@@ -22,6 +24,8 @@ function publicErrorStatus(error) {
return 500;
}
// #endregion
/**
* Registers public catalog routes (no session/cookie auth required).
* @param {import('express').Application} app
@@ -92,6 +96,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region GET /public/:companyId/categories
app.get(`${basePath}/public/:companyId/categories`, async (req, res) => {
const parsed = parseCompanyId(req.params.companyId);
if (parsed.error) {
@@ -109,6 +115,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /public/{companyId}/articles:
@@ -212,6 +220,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region GET /public/:companyId/articles
app.get(`${basePath}/public/:companyId/articles`, async (req, res) => {
const parsed = parseCompanyId(req.params.companyId);
if (parsed.error) {
@@ -243,6 +253,8 @@ export function register(app, basePath = '') {
}
});
// #endregion
/**
* @openapi
* /public/{companyId}/articles/{sku}:
@@ -340,6 +352,8 @@ export function register(app, basePath = '') {
* schema:
* $ref: '#/components/schemas/Error'
*/
// #region GET /public/:companyId/articles/:sku
app.get(`${basePath}/public/:companyId/articles/:sku`, async (req, res) => {
const parsedCompany = parseCompanyId(req.params.companyId);
if (parsedCompany.error) {
@@ -361,4 +375,6 @@ export function register(app, basePath = '') {
res.status(status).json({ error: error.message });
}
});
// #endregion
}