mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-12 02:43:50 +00:00
refactor: migrate custom fields to transactions
refactor: extract functions to api domain refactor: strict custom field parsing refactor: remove rundown cache utilities refactor: directory restructure
This commit is contained in:
committed by
Carlos Valente
parent
b1d23467a2
commit
62c8319d70
@@ -0,0 +1,22 @@
|
||||
import { Settings } from 'ontime-types';
|
||||
|
||||
import { parseSettings } from '../settings.parser.js';
|
||||
|
||||
describe('parseSettings()', () => {
|
||||
it('throws if settings object does not exist', () => {
|
||||
expect(() => parseSettings({})).toThrow();
|
||||
});
|
||||
|
||||
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({
|
||||
version: expect.any(String),
|
||||
serverPort: 4001,
|
||||
editorKey: null,
|
||||
operatorKey: null,
|
||||
timeFormat: '24',
|
||||
language: 'en',
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import { DatabaseModel, Settings } from 'ontime-types';
|
||||
|
||||
import { dbModel } from '../../models/dataModel.js';
|
||||
|
||||
/**
|
||||
* Parse settings portion of a project file
|
||||
*/
|
||||
export function parseSettings(data: Partial<DatabaseModel>): Settings {
|
||||
// skip if file definition is missing
|
||||
// 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 {
|
||||
version: dbModel.settings.version,
|
||||
serverPort: data.settings.serverPort ?? dbModel.settings.serverPort,
|
||||
editorKey: data.settings.editorKey ?? null,
|
||||
operatorKey: data.settings.operatorKey ?? null,
|
||||
timeFormat: data.settings.timeFormat ?? '24',
|
||||
language: data.settings.language ?? 'en',
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user