refactor: simplify validations

This commit is contained in:
Carlos Valente
2025-06-05 20:13:14 +02:00
committed by arc-alex
parent aebf949883
commit f3b4ea0155
9 changed files with 33 additions and 39 deletions
@@ -2,7 +2,7 @@ import { body, param, validationResult } from 'express-validator';
import type { Request, Response, NextFunction } from 'express';
export const rundownPostValidator = [
body('type').isString().exists().isIn(['event', 'delay', 'block']),
body('type').isString().isIn(['event', 'delay', 'block']),
body('after').optional().isString(),
body('before').optional().isString(),
@@ -14,7 +14,7 @@ export const rundownPostValidator = [
];
export const rundownPutValidator = [
body('id').isString().exists(),
body('id').isString().notEmpty(),
(req: Request, res: Response, next: NextFunction) => {
const errors = validationResult(req);
@@ -24,7 +24,7 @@ export const rundownPutValidator = [
];
export const rundownBatchPutValidator = [
body('data').isObject().exists(),
body('data').isObject(),
body('ids').isArray().notEmpty(),
body('ids.*').isString(),
@@ -36,9 +36,9 @@ export const rundownBatchPutValidator = [
];
export const rundownReorderValidator = [
body('entryId').isString().exists(),
body('destinationId').isString().exists(),
body('order').isIn(['before', 'after', 'insert']).exists(),
body('entryId').isString().notEmpty(),
body('destinationId').isString().notEmpty(),
body('order').isIn(['before', 'after', 'insert']),
(req: Request, res: Response, next: NextFunction) => {
const errors = validationResult(req);
@@ -48,8 +48,8 @@ export const rundownReorderValidator = [
];
export const rundownSwapValidator = [
body('from').isString().exists(),
body('to').isString().exists(),
body('from').isString().notEmpty(),
body('to').isString().notEmpty(),
(req: Request, res: Response, next: NextFunction) => {
const errors = validationResult(req);
@@ -59,7 +59,7 @@ export const rundownSwapValidator = [
];
export const paramsMustHaveEntryId = [
param('entryId').exists(),
param('entryId').isString().notEmpty(),
(req: Request, res: Response, next: NextFunction) => {
const errors = validationResult(req);