refactor: improve reorder logic

This commit is contained in:
Carlos Valente
2025-05-27 15:38:23 +02:00
committed by arc-alex
parent b66c19769d
commit 421183fe55
12 changed files with 560 additions and 147 deletions
@@ -13,7 +13,6 @@ import {
editEvent,
ungroupEntries,
groupEntries,
reorderEntry,
swapEvents,
cloneEntry,
} from '../../services/rundown-service/RundownService.js';
@@ -89,21 +88,6 @@ export async function rundownBatchPut(req: Request, res: Response<MessageRespons
}
}
export async function rundownReorder(req: Request, res: Response<Rundown | ErrorResponse>) {
if (failEmptyObjects(req.body, res)) {
return;
}
try {
const { eventId, from, to } = req.body;
const newRundown = await reorderEntry(eventId, from, to);
res.status(200).send(newRundown);
} catch (error) {
const message = getErrorMessage(error);
res.status(400).send({ message });
}
}
export async function rundownSwap(req: Request, res: Response<MessageResponse | ErrorResponse>) {
if (failEmptyObjects(req.body, res)) {
return;
@@ -1,5 +1,11 @@
import { ErrorResponse, Rundown } from 'ontime-types';
import { getErrorMessage } from 'ontime-utils';
import type { Request, Response } from 'express';
import express from 'express';
import { reorderEntry } from '../../services/rundown-service/RundownService.js';
import {
deletesEventById,
rundownAddToBlock,
@@ -13,7 +19,6 @@ import {
rundownGetCurrent,
rundownPost,
rundownPut,
rundownReorder,
rundownSwap,
} from './rundown.controller.js';
import {
@@ -37,7 +42,16 @@ router.post('/', rundownPostValidator, rundownPost);
router.put('/', rundownPutValidator, rundownPut);
router.put('/batch', rundownBatchPutValidator, rundownBatchPut);
router.patch('/reorder/', rundownReorderValidator, rundownReorder);
router.patch('/reorder', rundownReorderValidator, async (req: Request, res: Response<Rundown | ErrorResponse>) => {
try {
const { entryId, destinationId, order } = req.body;
const newRundown = await reorderEntry(entryId, destinationId, order);
res.status(200).send(newRundown);
} catch (error) {
const message = getErrorMessage(error);
res.status(400).send({ message });
}
});
router.patch('/swap', rundownSwapValidator, rundownSwap);
router.patch('/applydelay/:entryId', paramsMustHaveEntryId, rundownApplyDelay);
router.post('/clone/:entryId', paramsMustHaveEntryId, rundownCloneEntry);
@@ -35,9 +35,9 @@ export const rundownBatchPutValidator = [
];
export const rundownReorderValidator = [
body('eventId').isString().exists(),
body('from').isNumeric().exists(),
body('to').isNumeric().exists(),
body('entryId').isString().exists(),
body('destinationId').isString().exists(),
body('order').isIn(['before', 'after', 'insert']).exists(),
(req: Request, res: Response, next: NextFunction) => {
const errors = validationResult(req);