This commit is contained in:
seb
2026-10-08 16:11:47 +02:00
parent c2d3cdb088
commit 8111c3f377
10 changed files with 190 additions and 11 deletions

View File

@@ -14,6 +14,13 @@ function emitCategorySignal(req) {
emit('category', { companyId });
}
/** Notify SSE subscribers of the actor's selected company after an article change. */
function emitArticlesSignal(req) {
const companyId = req.user?.selectedCompanyId;
if (companyId == null) return;
emit('articles', { companyId });
}
function parsePositiveInt(value, field) {
const id = Number(value);
if (!Number.isInteger(id) || id <= 0) {
@@ -453,10 +460,10 @@ export function register(app, basePath = '') {
* delete:
* tags: [Category]
* summary: Delete category
* description: Deletes a category the user is authorized for (not the company root).
* description: Deletes a category the user is authorized for (not the company root). When recursive=true, recursively deletes all child categories, unassigns POS terminals, and deletes articles that only exist in the deleted subtree (including their children).
* security:
* - cookieAuth: []
* x-signals: [category]
* x-signals: [category, articles]
* x-markdown: category/delete.md
* parameters:
* - in: path
@@ -465,6 +472,12 @@ export function register(app, basePath = '') {
* schema:
* type: integer
* description: Category id
* - in: query
* name: recursive
* required: false
* schema:
* type: boolean
* description: When true, recursively deletes the category subtree and articles that only exist within it.
* responses:
* 204:
* description: Deleted
@@ -504,13 +517,18 @@ export function register(app, basePath = '') {
if (parsed.error) {
return res.status(400).json({ error: parsed.error });
}
const recursive = req.query.recursive === 'true';
try {
await db.deleteCategory({
googleAuthId: req.user.id,
id: parsed.id,
recursive,
});
emitCategorySignal(req);
if (recursive) {
emitArticlesSignal(req);
}
res.sendStatus(204);
} catch (error) {
const status = categoryErrorStatus(error);