Files
ontime/apps/server/src/api-data/rundown/rundown.validation.ts
T
Alex Christoffer Rasmussen 1a08b39b8b feat: auto cue re-numbering (#2016)
* feat: update auto cue numbering

* feat: renumber from ui

* refactor: patchEntries is not used

* chore: format

* fix: correct cue at top of group

* fix: handle precision

* refactor dialog

* bump limit for performance time test

* extract type

* add class name to lable

* fix rebase

* refator: extract renumering logic

* chore: comments for getIntegerAndFraction function

* chore: add the for renumber mutation

* fix: fraction match precision

* refactor: small cleanup

* refactor: use more narrow validator

---------

Co-authored-by: alex-Arc <omnivox@LAPTOP-RC5SNBVV.localdomain>
2026-05-03 18:39:00 +02:00

96 lines
2.7 KiB
TypeScript

import type { NextFunction, Request, Response } from 'express';
import { body, param } from 'express-validator';
import { requestValidationFunction } from '../validation-utils/validationFunction.js';
import { getCurrentRundown } from './rundown.dao.js';
// #region operations on project rundowns =========================
export const rundownPostValidator = [body('title').isString().trim().notEmpty(), requestValidationFunction];
// #endregion operations on project rundowns ======================
// #region operations on rundown entries ==========================
/**
* Middleware prevents mutating a rundown that is not selected
* This allows our service to still only handle the current rundown
*
* This would need to be removed in favour or rundown selection if we would like
* to implement the mutation of background rundowns
*/
export async function validateRundownMutation(req: Request, res: Response, next: NextFunction) {
const { rundownId } = req.params;
try {
if (getCurrentRundown().id !== rundownId) {
res.status(404).json({ message: 'Cannot mutate not selected rundown' });
return;
}
next();
} catch (error) {
res.status(404).json({ message: 'Rundown not found' });
return;
}
}
export const entryPostValidator = [
body('type').isString().isIn(['event', 'delay', 'group', 'milestone']),
body('after').optional().isString(),
body('before').optional().isString(),
requestValidationFunction,
];
export const clonePostValidator = [
body('after').optional().isString(),
body('before').optional().isString(),
requestValidationFunction,
];
export const entryPutValidator = [body('id').isString().trim().notEmpty(), requestValidationFunction];
export const entryBatchPutValidator = [
body('data').isObject(),
body('ids').isArray().notEmpty(),
body('ids.*').isString(),
requestValidationFunction,
];
export const entryReorderValidator = [
body('entryId').isString().notEmpty(),
body('destinationId').isString().notEmpty(),
body('order').isIn(['before', 'after', 'insert']),
requestValidationFunction,
];
export const entrySwapValidator = [
body('from').isString().notEmpty(),
body('to').isString().notEmpty(),
requestValidationFunction,
];
export const paramsMustHaveEntryId = [param('entryId').isString().notEmpty(), requestValidationFunction];
export const rundownArrayOfIds = [
body('ids').isArray().notEmpty(),
body('ids.*').isString(),
requestValidationFunction,
];
export const entryRenumberValidator = [
body('ids').isArray().notEmpty(),
body('ids.*').isString(),
body('prefix').isString(),
body('start').isDecimal(),
body('increment').isDecimal(),
requestValidationFunction,
];
// #endregion operations on rundown entries =======================