This commit is contained in:
seb
2026-09-30 22:37:34 +02:00
parent 71c92e0718
commit 120e59631e
16 changed files with 137 additions and 35 deletions

View File

@@ -261,10 +261,14 @@ export function register(app, basePath = '') {
* $ref: '#/components/schemas/Error'
*/
app.post(`${basePath}/category`, async (req, res) => {
const parent = parsePositiveInt(req.body?.parentId, 'parentId');
if (parent.error) {
return res.status(400).json({ error: parent.error });
const rawParent = req.body?.parentId;
if (rawParent === undefined || rawParent === null) {
return res.status(400).json({ error: 'parentId is required' });
}
if (typeof rawParent !== 'number' || !Number.isInteger(rawParent) || rawParent <= 0) {
return res.status(400).json({ error: 'parentId must be an integer' });
}
const parentId = rawParent;
const name = typeof req.body?.name === 'string' ? req.body.name.trim() : '';
if (!name) {
@@ -274,7 +278,7 @@ export function register(app, basePath = '') {
try {
const category = await db.createUnderParent({
googleAuthId: req.user.id,
parentId: parent.id,
parentId,
name,
});
emitCategorySignal(req);