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
@@ -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);