mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-11 02:13:48 +00:00
e6e00c0d4a
* add frozen flag to runtime store * add middleware for when frozen * prevent rundown editing when frozen * add endpoint to router to set frozen state * add frozen property to rundown placeholder in client
98 lines
2.8 KiB
TypeScript
98 lines
2.8 KiB
TypeScript
import { body, param, query, validationResult } from 'express-validator';
|
|
import { Request, Response, NextFunction } from 'express';
|
|
|
|
export const rundownPostValidator = [
|
|
body('type').isString().exists().isIn(['event', 'delay', 'block']),
|
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
const errors = validationResult(req);
|
|
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
|
next();
|
|
},
|
|
];
|
|
|
|
export const rundownPutValidator = [
|
|
body('id').isString().exists(),
|
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
const errors = validationResult(req);
|
|
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
|
next();
|
|
},
|
|
];
|
|
|
|
export const rundownFrozenPostValidator = [
|
|
body('frozen').isBoolean().exists(),
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
const errors = validationResult(req);
|
|
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
|
next();
|
|
},
|
|
]
|
|
|
|
export const rundownBatchPutValidator = [
|
|
body('data').isObject().exists(),
|
|
body('ids').isArray().exists(),
|
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
const errors = validationResult(req);
|
|
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
|
next();
|
|
},
|
|
];
|
|
|
|
export const rundownReorderValidator = [
|
|
body('eventId').isString().exists(),
|
|
body('from').isNumeric().exists(),
|
|
body('to').isNumeric().exists(),
|
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
const errors = validationResult(req);
|
|
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
|
next();
|
|
},
|
|
];
|
|
|
|
export const rundownSwapValidator = [
|
|
body('from').isString().exists(),
|
|
body('to').isString().exists(),
|
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
const errors = validationResult(req);
|
|
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
|
next();
|
|
},
|
|
];
|
|
|
|
export const paramsMustHaveEventId = [
|
|
param('eventId').exists(),
|
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
const errors = validationResult(req);
|
|
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
|
next();
|
|
},
|
|
];
|
|
|
|
export const rundownArrayOfIds = [
|
|
body('ids').isArray().exists(),
|
|
body('ids.*').isString(),
|
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
const errors = validationResult(req);
|
|
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
|
next();
|
|
},
|
|
];
|
|
|
|
export const rundownGetPaginatedQueryParams = [
|
|
query('offset').isNumeric().optional(),
|
|
query('limit').isNumeric().optional(),
|
|
|
|
(req: Request, res: Response, next: NextFunction) => {
|
|
const errors = validationResult(req);
|
|
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
|
next();
|
|
},
|
|
];
|