mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-13 11:23:50 +00:00
refactor: improve project loading
This commit is contained in:
@@ -146,7 +146,6 @@ describe('test aliases import', () => {
|
||||
const testData = {
|
||||
rundown: [],
|
||||
settings: {
|
||||
app: 'ontime',
|
||||
version: '2.0.0',
|
||||
},
|
||||
urlPresets: [
|
||||
@@ -171,7 +170,6 @@ describe('test views import', () => {
|
||||
const testData = {
|
||||
rundown: [],
|
||||
settings: {
|
||||
app: 'ontime',
|
||||
version: '2.0.0',
|
||||
},
|
||||
viewSettings: {
|
||||
@@ -205,7 +203,6 @@ describe('test views import', () => {
|
||||
const testData = {
|
||||
rundown: [],
|
||||
settings: {
|
||||
app: 'ontime',
|
||||
version: '2.0.0',
|
||||
},
|
||||
} as unknown as DatabaseModel;
|
||||
|
||||
@@ -249,11 +249,10 @@ describe('parseSettings()', () => {
|
||||
expect(() => parseSettings({})).toThrow();
|
||||
});
|
||||
|
||||
it('returns an a base model as long as we have the app and version', () => {
|
||||
const result = parseSettings({ settings: { app: 'ontime', version: '1' } as Settings });
|
||||
it('returns an a base model as long as we have the app version', () => {
|
||||
const result = parseSettings({ settings: { version: '1' } as Settings });
|
||||
expect(result).toBeTypeOf('object');
|
||||
expect(result).toMatchObject({
|
||||
app: 'ontime',
|
||||
version: expect.any(String),
|
||||
serverPort: 4001,
|
||||
editorKey: null,
|
||||
|
||||
@@ -24,6 +24,7 @@ import { createEvent, type ErrorEmitter } from './parser.js';
|
||||
|
||||
/**
|
||||
* Parse a rundowns object along with the project custom fields
|
||||
* Returns a default rundown if none exists
|
||||
*/
|
||||
export function parseRundowns(
|
||||
data: Partial<DatabaseModel>,
|
||||
@@ -32,6 +33,8 @@ export function parseRundowns(
|
||||
// check custom fields first
|
||||
const parsedCustomFields = parseCustomFields(data, emitError);
|
||||
|
||||
// ensure there is always a rundown to import
|
||||
// this is important since the rest of the app assumes this exist
|
||||
if (!data.rundowns || isObjectEmpty(data.rundowns)) {
|
||||
emitError?.('No data found to import');
|
||||
return {
|
||||
@@ -194,14 +197,14 @@ export function parseProject(data: Partial<DatabaseModel>, emitError?: ErrorEmit
|
||||
*/
|
||||
export function parseSettings(data: Partial<DatabaseModel>): Settings {
|
||||
// skip if file definition is missing
|
||||
if (!data.settings || data.settings?.app !== 'ontime' || data.settings?.version == null) {
|
||||
throw new Error('ERROR: unable to parse settings, missing app or version');
|
||||
// TODO: skip parsing if the version is not correct
|
||||
if (!data.settings || data.settings?.version == null) {
|
||||
throw new Error('ERROR: unable to parse settings, missing or incorrect version');
|
||||
}
|
||||
|
||||
console.log('Found settings, importing...');
|
||||
|
||||
return {
|
||||
app: dbModel.settings.app,
|
||||
version: dbModel.settings.version,
|
||||
serverPort: data.settings.serverPort ?? dbModel.settings.serverPort,
|
||||
editorKey: data.settings.editorKey ?? null,
|
||||
|
||||
Reference in New Issue
Block a user