Add name validation to PATCH /tags/:id

This commit is contained in:
Iván Ovejero 2021-04-12 15:28:55 +02:00
parent 5047c10ee3
commit 85efe0424b
2 changed files with 2 additions and 1 deletions

View file

@ -816,6 +816,7 @@ class App {
TagHelpers.validateRequestBody(req.body); TagHelpers.validateRequestBody(req.body);
const { name } = req.body; const { name } = req.body;
await TagHelpers.validateName(name);
TagHelpers.validateLength(name); TagHelpers.validateLength(name);
const id = Number(req.params.id); const id = Number(req.params.id);

View file

@ -2,7 +2,7 @@ import { FindOneOptions, getConnection } from "typeorm";
import { Db, ResponseHelper } from "."; import { Db, ResponseHelper } from ".";
/** /**
* Validate whether a tag name exists so that it cannot be used for a create operation. * Validate whether a tag name exists so that it cannot be used for a create/update operation.
*/ */
export async function validateName(name: string): Promise<void> | never { export async function validateName(name: string): Promise<void> | never {
const findQuery = { where: { name } } as FindOneOptions; const findQuery = { where: { name } } as FindOneOptions;