mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-15 04:13:47 +00:00
refactor: generate ids for new rundowns
This commit is contained in:
committed by
Carlos Valente
parent
b70ef80320
commit
f2b78e0f32
@@ -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`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user