u
This commit is contained in:
@@ -5,6 +5,8 @@ import * as picDb from '../../db/pic.js';
|
||||
import { emit } from '../sse.js';
|
||||
import { buildKategorienCsv, toWindows1252 } from '../../util/kategorienCsv.js';
|
||||
|
||||
// #region Helpers
|
||||
|
||||
const AVIF_BODY_LIMIT = '20mb';
|
||||
|
||||
/** Notify SSE subscribers of the actor's selected company after a real category change. */
|
||||
@@ -52,6 +54,8 @@ function categoryErrorStatus(error) {
|
||||
return 500;
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* Registers category routes (requires auth middleware).
|
||||
* @param {import('express').Application} app - Express app
|
||||
@@ -111,6 +115,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region GET /category/tree
|
||||
|
||||
app.get(`${basePath}/category/tree`, async (req, res) => {
|
||||
const companyId = req.user.selectedCompanyId;
|
||||
if (companyId == null) {
|
||||
@@ -127,6 +133,8 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /category/export.zip:
|
||||
@@ -174,6 +182,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region GET /category/export.zip
|
||||
|
||||
app.get(`${basePath}/category/export.zip`, async (req, res) => {
|
||||
const companyId = req.user.selectedCompanyId;
|
||||
if (companyId == null) {
|
||||
@@ -212,6 +222,8 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /category:
|
||||
@@ -273,6 +285,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region POST /category
|
||||
|
||||
app.post(`${basePath}/category`, async (req, res) => {
|
||||
const rawParent = req.body?.parentId;
|
||||
if (rawParent === undefined || rawParent === null) {
|
||||
@@ -303,6 +317,8 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /category/{id}/articles:
|
||||
@@ -351,6 +367,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region GET /category/:id/articles
|
||||
|
||||
app.get(`${basePath}/category/:id/articles`, async (req, res) => {
|
||||
const parsed = parsePositiveInt(req.params.id, 'id');
|
||||
if (parsed.error) {
|
||||
@@ -375,6 +393,8 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /category/{id}:
|
||||
@@ -512,6 +532,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region DELETE /category/:id
|
||||
|
||||
app.delete(`${basePath}/category/:id`, async (req, res) => {
|
||||
const parsed = parsePositiveInt(req.params.id, 'id');
|
||||
if (parsed.error) {
|
||||
@@ -537,6 +559,10 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region PATCH /category/:id
|
||||
|
||||
app.patch(`${basePath}/category/:id`, async (req, res) => {
|
||||
const parsed = parsePositiveInt(req.params.id, 'id');
|
||||
if (parsed.error) {
|
||||
@@ -588,6 +614,8 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /category/order:
|
||||
@@ -658,6 +686,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region PUT /category/order
|
||||
|
||||
app.put(`${basePath}/category/order`, async (req, res) => {
|
||||
const parentId = Number(req.body?.parentId);
|
||||
if (!Number.isInteger(parentId) || parentId <= 0) {
|
||||
@@ -688,6 +718,8 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /category/{id}/image:
|
||||
@@ -823,6 +855,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region POST /category/:id/image
|
||||
|
||||
app.post(
|
||||
`${basePath}/category/:id/image`,
|
||||
express.raw({ type: ['image/avif', 'image/webp', 'application/octet-stream'], limit: AVIF_BODY_LIMIT }),
|
||||
@@ -849,6 +883,10 @@ export function register(app, basePath = '') {
|
||||
},
|
||||
);
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region DELETE /category/:id/image
|
||||
|
||||
app.delete(`${basePath}/category/:id/image`, async (req, res) => {
|
||||
const parsed = parsePositiveInt(req.params.id, 'id');
|
||||
if (parsed.error) {
|
||||
@@ -865,4 +903,6 @@ export function register(app, basePath = '') {
|
||||
res.status(status).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user