refactor: generate ids for new rundowns

This commit is contained in:
Carlos Valente
2025-12-11 18:22:28 +01:00
committed by Carlos Valente
parent b70ef80320
commit f2b78e0f32
13 changed files with 146 additions and 73 deletions
@@ -1,9 +1,14 @@
import { ErrorResponse, OntimeEntry, ProjectRundownsList, Rundown } from 'ontime-types';
import { generateId, getErrorMessage } from 'ontime-utils';
import { getErrorMessage } from 'ontime-utils';
import type { Request, Response } from 'express';
import express from 'express';
import { getDataProvider } from '../../classes/data-provider/DataProvider.js';
import { makeNewRundown } from '../../models/dataModel.js';
import { paramsWithId } from '../validation-utils/validationFunction.js';
import { getCurrentRundown } from './rundown.dao.js';
import {
addEntry,
@@ -30,9 +35,6 @@ import {
validateRundownMutation,
clonePostValidator,
} from './rundown.validation.js';
import { paramsWithId } from '../validation-utils/validationFunction.js';
import { getDataProvider } from '../../classes/data-provider/DataProvider.js';
import { defaultRundown } from '../../models/dataModel.js';
import { duplicateRundown, normalisedToRundownArray } from './rundown.utils.js';
export const router = express.Router();
@@ -85,8 +87,9 @@ router.post('/:id/load', paramsWithId, async (req: Request, res: Response<Projec
*/
router.post('/', rundownPostValidator, async (req: Request, res: Response<ProjectRundownsList | ErrorResponse>) => {
try {
const id = generateId();
await getDataProvider().setRundown(id, { ...defaultRundown, id, title: req.body.title });
const emptyRundown = makeNewRundown();
emptyRundown.title = req.body.title;
await getDataProvider().setRundown(emptyRundown.id, emptyRundown);
const projectRundowns = getDataProvider().getProjectRundowns();
res.status(201).json({ loaded: getCurrentRundown().id, rundowns: normalisedToRundownArray(projectRundowns) });