u
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user