mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-24 16:39:13 +00:00
refactor: extract rundown switching to a single function in rundown.service (#1930)
This commit is contained in:
committed by
GitHub
parent
680273770c
commit
6436e3fda8
@@ -22,6 +22,7 @@ import {
|
|||||||
initRundown,
|
initRundown,
|
||||||
reorderEntry,
|
reorderEntry,
|
||||||
swapEvents,
|
swapEvents,
|
||||||
|
loadRundown,
|
||||||
ungroupEntries,
|
ungroupEntries,
|
||||||
} from './rundown.service.js';
|
} from './rundown.service.js';
|
||||||
import {
|
import {
|
||||||
@@ -62,19 +63,7 @@ router.get('/current', async (_req: Request, res: Response<Rundown>) => {
|
|||||||
*/
|
*/
|
||||||
router.post('/:id/load', paramsWithId, async (req: Request, res: Response<ProjectRundownsList | ErrorResponse>) => {
|
router.post('/:id/load', paramsWithId, async (req: Request, res: Response<ProjectRundownsList | ErrorResponse>) => {
|
||||||
try {
|
try {
|
||||||
// maybe the rundown is already loaded
|
const projectRundowns = await loadRundown(req.params.id);
|
||||||
if (req.params.id === getCurrentRundown().id) {
|
|
||||||
const projectRundowns = getDataProvider().getProjectRundowns();
|
|
||||||
res.status(200).json({ loaded: getCurrentRundown().id, rundowns: normalisedToRundownArray(projectRundowns) });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const dataProvider = getDataProvider();
|
|
||||||
const rundown = dataProvider.getRundown(req.params.id);
|
|
||||||
const customField = dataProvider.getCustomFields();
|
|
||||||
await initRundown(rundown, customField);
|
|
||||||
|
|
||||||
const projectRundowns = getDataProvider().getProjectRundowns();
|
|
||||||
res.status(200).json({ loaded: getCurrentRundown().id, rundowns: normalisedToRundownArray(projectRundowns) });
|
res.status(200).json({ loaded: getCurrentRundown().id, rundowns: normalisedToRundownArray(projectRundowns) });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = getErrorMessage(error);
|
const message = getErrorMessage(error);
|
||||||
|
|||||||
@@ -27,12 +27,14 @@ import { logger } from '../../classes/Logger.js';
|
|||||||
import {
|
import {
|
||||||
createTransaction,
|
createTransaction,
|
||||||
customFieldMutation,
|
customFieldMutation,
|
||||||
|
getCurrentRundown,
|
||||||
rundownCache,
|
rundownCache,
|
||||||
rundownMutation,
|
rundownMutation,
|
||||||
updateBackgroundRundown,
|
updateBackgroundRundown,
|
||||||
} from './rundown.dao.js';
|
} from './rundown.dao.js';
|
||||||
import type { RundownMetadata } from './rundown.types.js';
|
import type { RundownMetadata } from './rundown.types.js';
|
||||||
import { generateEvent, getInsertAfterId, hasChanges } from './rundown.utils.js';
|
import { generateEvent, getInsertAfterId, hasChanges } from './rundown.utils.js';
|
||||||
|
import { getDataProvider } from '../../classes/data-provider/DataProvider.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a new entry with given data
|
* creates a new entry with given data
|
||||||
@@ -596,6 +598,20 @@ function notifyChanges(rundownMetadata: RundownMetadata, revision: number, optio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws if the provided id does not exist
|
||||||
|
*/
|
||||||
|
export async function loadRundown(id: string) {
|
||||||
|
const dataProvider = getDataProvider();
|
||||||
|
if (id === getCurrentRundown().id) {
|
||||||
|
return dataProvider.getProjectRundowns();
|
||||||
|
}
|
||||||
|
const rundown = dataProvider.getRundown(id);
|
||||||
|
const customField = dataProvider.getCustomFields();
|
||||||
|
await initRundown(rundown, customField);
|
||||||
|
return dataProvider.getProjectRundowns();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a new rundown in the cache
|
* Sets a new rundown in the cache
|
||||||
* and marks it as the currently loaded one
|
* and marks it as the currently loaded one
|
||||||
|
|||||||
Reference in New Issue
Block a user