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
+36 -2
View File
@@ -1,7 +1,8 @@
import { DatabaseModel, Rundown } from 'ontime-types';
import { ONTIME_VERSION } from '../ONTIME_VERSION.js';
import { generateId } from 'ontime-utils';
export const defaultRundown: Rundown = {
const defaultRundown: Rundown = {
id: 'default',
title: 'Default',
order: [],
@@ -10,7 +11,7 @@ export const defaultRundown: Rundown = {
revision: 0,
};
export const dbModel: DatabaseModel = {
const dbModel: DatabaseModel = {
rundowns: {
default: { ...defaultRundown },
},
@@ -46,3 +47,36 @@ export const dbModel: DatabaseModel = {
automations: {},
},
};
/**
* Creates a new project with a single rundown of given Id
*/
export function makeNewProject(defaultRundownId?: string): DatabaseModel {
const rundown = makeNewRundown(defaultRundownId);
const newProject = structuredClone(dbModel);
newProject.rundowns = {
[rundown.id]: rundown,
};
return newProject;
}
/**
* Creates a new rundown with given Id
*/
export function makeNewRundown(id?: string): Rundown {
const rundownId = id || generateId();
const newRundown = structuredClone(defaultRundown);
newRundown.id = rundownId;
return newRundown;
}
/**
* Get a top level property of the DatabaseModel
*/
export function getPartialProject<T extends keyof DatabaseModel>(key: T): DatabaseModel[T] {
if (Object.hasOwn(dbModel, key)) {
return structuredClone(dbModel[key]);
}
throw new Error(`Key ${key} does not exist on DatabaseModel`);
}