mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-12 10:53:51 +00:00
+4
-4
@@ -14,7 +14,7 @@ import http from 'http';
|
||||
import cors from 'cors';
|
||||
|
||||
// Import Routes
|
||||
import { router as eventsRouter } from './routes/eventsRouter.js';
|
||||
import { router as rundownRouter } from './routes/rundownRouter.js';
|
||||
import { router as eventRouter } from './routes/eventRouter.js';
|
||||
import { router as ontimeRouter } from './routes/ontimeRouter.js';
|
||||
import { router as playbackRouter } from './routes/playbackRouter.js';
|
||||
@@ -54,7 +54,7 @@ app.use(express.urlencoded({ extended: true }));
|
||||
app.use(express.json({ limit: '1mb' }));
|
||||
|
||||
// Implement route endpoints
|
||||
app.use('/events', eventsRouter);
|
||||
app.use('/eventlist', rundownRouter);
|
||||
app.use('/event', eventRouter);
|
||||
app.use('/ontime', ontimeRouter);
|
||||
app.use('/playback', playbackRouter);
|
||||
@@ -133,7 +133,7 @@ const server = http.createServer(app);
|
||||
*/
|
||||
export const startServer = async (overrideConfig = null) => {
|
||||
const port = 4001; // port hardcoded
|
||||
const { events, http } = DataProvider.getData();
|
||||
const { rundown, http } = DataProvider.getData();
|
||||
|
||||
// Start server
|
||||
const returnMessage = `Ontime is listening on port ${port}`;
|
||||
@@ -151,7 +151,7 @@ export const startServer = async (overrideConfig = null) => {
|
||||
|
||||
// init timer
|
||||
global.timer = new EventTimer(socket, config.timer, oscConfig, http);
|
||||
global.timer.setupWithEventList(events.filter((entry) => entry.type === 'event'));
|
||||
global.timer.setupWithEventList(rundown.filter((entry) => entry.type === 'event'));
|
||||
|
||||
socket.info('SERVER', returnMessage);
|
||||
socket.startListener();
|
||||
|
||||
@@ -19,35 +19,35 @@ export class DataProvider {
|
||||
return data.event;
|
||||
}
|
||||
|
||||
static async setEvents(newData) {
|
||||
data.events = [...newData];
|
||||
static async setRundown(newData) {
|
||||
data.rundown = [...newData];
|
||||
await this.persist();
|
||||
}
|
||||
|
||||
static getEventById(eventId) {
|
||||
return data.events.find((e) => e.id === eventId);
|
||||
return data.rundown.find((e) => e.id === eventId);
|
||||
}
|
||||
|
||||
static async updateEventById(eventId, newData) {
|
||||
const eventIndex = data.events.findIndex((e) => e.id === eventId);
|
||||
const e = data.events[eventIndex];
|
||||
data.events[eventIndex] = { ...e, ...newData };
|
||||
data.events[eventIndex].revision++;
|
||||
const eventIndex = data.rundown.findIndex((e) => e.id === eventId);
|
||||
const e = data.rundown[eventIndex];
|
||||
data.rundown[eventIndex] = { ...e, ...newData };
|
||||
data.rundown[eventIndex].revision++;
|
||||
await this.persist();
|
||||
return data.events[eventIndex];
|
||||
return data.rundown[eventIndex];
|
||||
}
|
||||
|
||||
static async deleteEvent(eventId) {
|
||||
data.events = Array.from(data.events).filter((e) => e.id !== eventId);
|
||||
data.rundown = Array.from(data.rundown).filter((e) => e.id !== eventId);
|
||||
await this.persist();
|
||||
}
|
||||
|
||||
static getNumEvents() {
|
||||
return data.events.length;
|
||||
return data.rundown.length;
|
||||
}
|
||||
|
||||
static async deleteAllEvents() {
|
||||
data.events = [];
|
||||
static async clearRundown() {
|
||||
data.rundown = [];
|
||||
await db.write();
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ export class DataProvider {
|
||||
*/
|
||||
static async insertEventAt(entry, index) {
|
||||
// get events
|
||||
const events = DataProvider.getEvents();
|
||||
const events = DataProvider.getRundown();
|
||||
const count = events.length;
|
||||
const order = entry.order;
|
||||
|
||||
@@ -83,7 +83,7 @@ export class DataProvider {
|
||||
}
|
||||
|
||||
// save events
|
||||
await DataProvider.setEvents(events);
|
||||
await DataProvider.setRundown(events);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +94,7 @@ export class DataProvider {
|
||||
* @private
|
||||
*/
|
||||
static async insertEventAfterId(entry, id) {
|
||||
const index = [...data.events].findIndex((event) => event.id === id);
|
||||
const index = [...data.rundown].findIndex((event) => event.id === id);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const { _after, ...sanitisedEvent } = entry;
|
||||
await DataProvider.insertEventAt(sanitisedEvent, index + 1);
|
||||
@@ -145,8 +145,8 @@ export class DataProvider {
|
||||
await this.persist();
|
||||
}
|
||||
|
||||
static getEvents() {
|
||||
return [...data.events];
|
||||
static getRundown() {
|
||||
return [...data.rundown];
|
||||
}
|
||||
|
||||
static async persist() {
|
||||
@@ -161,7 +161,7 @@ export class DataProvider {
|
||||
data.http = mergedData.http;
|
||||
data.aliases = mergedData.aliases;
|
||||
data.userFields = mergedData.userFields;
|
||||
data.events = mergedData.events;
|
||||
data.rundown = mergedData.rundown;
|
||||
await this.persist();
|
||||
}
|
||||
|
||||
@@ -173,8 +173,8 @@ export class DataProvider {
|
||||
static safeMerge(existing, newData) {
|
||||
const mergedData = { ...existing };
|
||||
|
||||
if (typeof newData?.events !== 'undefined') {
|
||||
mergedData.events = newData.events;
|
||||
if (typeof newData?.rundown !== 'undefined') {
|
||||
mergedData.rundown = newData.rundown;
|
||||
}
|
||||
if (typeof newData?.event !== 'undefined') {
|
||||
mergedData.event = { ...newData.event };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
let instance;
|
||||
|
||||
export class MessageManager {
|
||||
class MessageManager {
|
||||
constructor() {
|
||||
if (instance) {
|
||||
throw new Error('There can be only one');
|
||||
|
||||
@@ -320,8 +320,8 @@ class SocketController {
|
||||
* */
|
||||
|
||||
// 1. EVENT LIST
|
||||
socket.on('get-ontime-feat-eventlist', () => {
|
||||
global.timer._broadcastFeatureEventList();
|
||||
socket.on('get-ontime-feat-rundown', () => {
|
||||
global.timer._broadcastFeatureRundown();
|
||||
});
|
||||
|
||||
// 2. MESSAGE CONTROL
|
||||
|
||||
@@ -50,7 +50,7 @@ export class EventTimer extends Timer {
|
||||
// call general title reset
|
||||
this._resetSelection();
|
||||
|
||||
this._eventlist = [];
|
||||
this.rundown = [];
|
||||
|
||||
// set recurrent emits
|
||||
this._interval = setInterval(() => this.runCycle(), timerConfig?.refresh || 1000);
|
||||
@@ -130,13 +130,13 @@ export class EventTimer extends Timer {
|
||||
* @description Broadcast data for Event List feature
|
||||
* @private
|
||||
*/
|
||||
_broadcastFeatureEventList() {
|
||||
_broadcastFeatureRundown() {
|
||||
const featureData = {
|
||||
selectedEventId: this.selectedEventId,
|
||||
nextEventId: this.nextEventId,
|
||||
playback: this.state,
|
||||
};
|
||||
this.socket.send('ontime-feat-eventlist', featureData);
|
||||
this.socket.send('ontime-feat-rundown', featureData);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,7 +147,7 @@ export class EventTimer extends Timer {
|
||||
const featureData = {
|
||||
playback: this.state,
|
||||
selectedEventId: this.selectedEventId,
|
||||
numEvents: this._eventlist.length,
|
||||
numEvents: this.rundown.length,
|
||||
};
|
||||
this.socket.send('ontime-feat-playbackcontrol', featureData);
|
||||
}
|
||||
@@ -162,7 +162,7 @@ export class EventTimer extends Timer {
|
||||
playback: this.state,
|
||||
selectedEventId: this.selectedEventId,
|
||||
selectedEventIndex: this.selectedEventIndex,
|
||||
numEvents: this._eventlist.length,
|
||||
numEvents: this.rundown.length,
|
||||
};
|
||||
this.socket.send('ontime-feat-info', featureData);
|
||||
}
|
||||
@@ -172,7 +172,7 @@ export class EventTimer extends Timer {
|
||||
playback: this.state,
|
||||
selectedEventId: this.selectedEventId,
|
||||
selectedEventIndex: this.selectedEventIndex,
|
||||
numEvents: this._eventlist.length,
|
||||
numEvents: this.rundown.length,
|
||||
titleNow: this.titles.titleNow,
|
||||
};
|
||||
this.socket.send('ontime-feat-cuesheet', featureData);
|
||||
@@ -183,13 +183,13 @@ export class EventTimer extends Timer {
|
||||
*/
|
||||
broadcastState() {
|
||||
// feature sync
|
||||
this._broadcastFeatureEventList();
|
||||
this._broadcastFeatureRundown();
|
||||
this._broadcastFeaturePlaybackControl();
|
||||
this._broadcastFeatureInfo();
|
||||
this._broadcastFeatureCuesheet();
|
||||
this._broadcastFeatureTimer();
|
||||
|
||||
const numEvents = this._eventlist.length;
|
||||
const numEvents = this.rundown.length;
|
||||
this.broadcastTimer();
|
||||
this.socket.send('playstate', this.state);
|
||||
this.socket.send('selected', {
|
||||
@@ -214,7 +214,7 @@ export class EventTimer extends Timer {
|
||||
*/
|
||||
trigger(action, payload) {
|
||||
let success = true;
|
||||
const numEvents = this._eventlist.length;
|
||||
const numEvents = this.rundown.length;
|
||||
switch (action) {
|
||||
case 'start': {
|
||||
if (!numEvents) return false;
|
||||
@@ -537,13 +537,13 @@ export class EventTimer extends Timer {
|
||||
this.unload();
|
||||
|
||||
// set general
|
||||
this._eventlist = [];
|
||||
this.rundown = [];
|
||||
|
||||
// update lifecycle: onStop
|
||||
this.ontimeCycle = this.cycleState.onStop;
|
||||
|
||||
// update clients
|
||||
this.socket.send('numevents', this._eventlist.length);
|
||||
this.socket.send('numevents', this.rundown.length);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -558,7 +558,7 @@ export class EventTimer extends Timer {
|
||||
const numEvents = events.length;
|
||||
|
||||
// set general
|
||||
this._eventlist = events;
|
||||
this.rundown = events;
|
||||
|
||||
// list may contain no events
|
||||
if (numEvents < 1) return;
|
||||
@@ -585,7 +585,7 @@ export class EventTimer extends Timer {
|
||||
const numEvents = events.length;
|
||||
|
||||
// set general
|
||||
this._eventlist = events;
|
||||
this.rundown = events;
|
||||
|
||||
// list may be empty
|
||||
if (numEvents < 1) {
|
||||
@@ -594,12 +594,12 @@ export class EventTimer extends Timer {
|
||||
}
|
||||
|
||||
// auto load if is the there was nothing before
|
||||
if (!this._eventlist.length) {
|
||||
if (!this.rundown.length) {
|
||||
this.loadEvent(0);
|
||||
} else if (this.selectedEventId != null) {
|
||||
// handle reload selected
|
||||
// Look for event (order might have changed)
|
||||
const eventIndex = this._eventlist.findIndex((e) => e.id === this.selectedEventId);
|
||||
const eventIndex = this.rundown.findIndex((e) => e.id === this.selectedEventId);
|
||||
|
||||
// Maybe is missing
|
||||
if (eventIndex === -1) {
|
||||
@@ -627,7 +627,7 @@ export class EventTimer extends Timer {
|
||||
*/
|
||||
updateSingleEvent(id, entry) {
|
||||
// find object in events
|
||||
const eventIndex = this._eventlist.findIndex((e) => e.id === id);
|
||||
const eventIndex = this.rundown.findIndex((e) => e.id === id);
|
||||
if (eventIndex === -1) {
|
||||
throw new Error('Event not found');
|
||||
}
|
||||
@@ -644,8 +644,8 @@ export class EventTimer extends Timer {
|
||||
}
|
||||
|
||||
// update event in memory
|
||||
const e = this._eventlist[eventIndex];
|
||||
this._eventlist[eventIndex] = { ...e, ...entry };
|
||||
const e = this.rundown[eventIndex];
|
||||
this.rundown[eventIndex] = { ...e, ...entry };
|
||||
|
||||
try {
|
||||
// check if entry is running
|
||||
@@ -685,18 +685,18 @@ export class EventTimer extends Timer {
|
||||
insertEventAfterId(event, previousId) {
|
||||
if (typeof previousId === 'undefined') {
|
||||
// Insert at beginning
|
||||
this._eventlist.unshift(event);
|
||||
this.rundown.unshift(event);
|
||||
} else {
|
||||
// find object in events
|
||||
const previousIndex = this._eventlist.findIndex((e) => e.id === previousId);
|
||||
const previousIndex = this.rundown.findIndex((e) => e.id === previousId);
|
||||
if (previousIndex === -1) {
|
||||
throw 'Event not found';
|
||||
}
|
||||
|
||||
if (previousIndex + 1 >= this._eventlist.length) {
|
||||
this._eventlist.push(event);
|
||||
if (previousIndex + 1 >= this.rundown.length) {
|
||||
this.rundown.push(event);
|
||||
} else {
|
||||
this._eventlist.splice(previousIndex + 1, 0, event);
|
||||
this.rundown.splice(previousIndex + 1, 0, event);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -737,11 +737,11 @@ export class EventTimer extends Timer {
|
||||
*/
|
||||
deleteId(eventId) {
|
||||
// find object in events
|
||||
const eventIndex = this._eventlist.findIndex((e) => e.id === eventId);
|
||||
const eventIndex = this.rundown.findIndex((e) => e.id === eventId);
|
||||
if (eventIndex === -1) return;
|
||||
|
||||
// delete event and update count
|
||||
this._eventlist.splice(eventIndex, 1);
|
||||
this.rundown.splice(eventIndex, 1);
|
||||
|
||||
// reload data if necessary
|
||||
if (eventId === this.selectedEventId) {
|
||||
@@ -750,7 +750,7 @@ export class EventTimer extends Timer {
|
||||
}
|
||||
|
||||
// update selected event index
|
||||
this.selectedEventIndex = this._eventlist.findIndex((e) => e.id === this.selectedEventId);
|
||||
this.selectedEventIndex = this.rundown.findIndex((e) => e.id === this.selectedEventId);
|
||||
|
||||
// reload titles if necessary
|
||||
if (eventId === this.nextEventId || eventId === this.nextPublicEventId) {
|
||||
@@ -771,7 +771,7 @@ export class EventTimer extends Timer {
|
||||
* @param {string} eventId - ID of event in eventlist
|
||||
*/
|
||||
loadEventById(eventId) {
|
||||
const eventIndex = this._eventlist.findIndex((e) => e.id === eventId);
|
||||
const eventIndex = this.rundown.findIndex((e) => e.id === eventId);
|
||||
|
||||
if (eventIndex === -1) return false;
|
||||
this.pause();
|
||||
@@ -786,7 +786,7 @@ export class EventTimer extends Timer {
|
||||
* @param {number} eventIndex - Index of event in eventlist
|
||||
*/
|
||||
loadEventByIndex(eventIndex) {
|
||||
if (eventIndex === -1 || eventIndex > this._eventlist.length) return false;
|
||||
if (eventIndex === -1 || eventIndex > this.rundown.length) return false;
|
||||
this.pause();
|
||||
this.loadEvent(eventIndex, 'load');
|
||||
// run cycle
|
||||
@@ -800,7 +800,7 @@ export class EventTimer extends Timer {
|
||||
* @param {string} [type='load'] - 'load' or 'reload', whether we are keeping running time
|
||||
*/
|
||||
loadEvent(eventIndex, type = 'load') {
|
||||
const e = this._eventlist?.[eventIndex];
|
||||
const e = this.rundown?.[eventIndex];
|
||||
if (e == null) return;
|
||||
|
||||
const start = e.timeStart == null || e.timeStart === '' ? 0 : e.timeStart;
|
||||
@@ -840,7 +840,7 @@ export class EventTimer extends Timer {
|
||||
* @private
|
||||
*/
|
||||
_loadTitlesNow() {
|
||||
const e = this._eventlist[this.selectedEventIndex];
|
||||
const e = this.rundown[this.selectedEventIndex];
|
||||
if (e == null) return;
|
||||
|
||||
// private title is always current
|
||||
@@ -861,8 +861,8 @@ export class EventTimer extends Timer {
|
||||
|
||||
// iterate backwards to find it
|
||||
for (let i = this.selectedEventIndex; i >= 0; i--) {
|
||||
if (this._eventlist[i].type === 'event' && this._eventlist[i].isPublic) {
|
||||
this._loadThisTitles(this._eventlist[i], 'now-public');
|
||||
if (this.rundown[i].type === 'event' && this.rundown[i].isPublic) {
|
||||
this._loadThisTitles(this.rundown[i], 'now-public');
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -963,7 +963,7 @@ export class EventTimer extends Timer {
|
||||
this.titlesPublic.presenterNext = null;
|
||||
this.nextPublicEventId = null;
|
||||
|
||||
const numEvents = this._eventlist.length;
|
||||
const numEvents = this.rundown.length;
|
||||
|
||||
if (this.selectedEventIndex < numEvents - 1) {
|
||||
let nextPublic = false;
|
||||
@@ -971,16 +971,16 @@ export class EventTimer extends Timer {
|
||||
|
||||
for (let i = this.selectedEventIndex + 1; i < numEvents; i++) {
|
||||
// check that is the right type
|
||||
if (this._eventlist[i].type === 'event') {
|
||||
if (this.rundown[i].type === 'event') {
|
||||
// if we have not set private
|
||||
if (!nextPrivate) {
|
||||
this._loadThisTitles(this._eventlist[i], 'next-private');
|
||||
this._loadThisTitles(this.rundown[i], 'next-private');
|
||||
nextPrivate = true;
|
||||
}
|
||||
|
||||
// if event is public
|
||||
if (this._eventlist[i].isPublic) {
|
||||
this._loadThisTitles(this._eventlist[i], 'next-public');
|
||||
if (this.rundown[i].isPublic) {
|
||||
this._loadThisTitles(this.rundown[i], 'next-public');
|
||||
nextPublic = true;
|
||||
}
|
||||
}
|
||||
@@ -1098,7 +1098,7 @@ export class EventTimer extends Timer {
|
||||
}
|
||||
|
||||
const { nowIndex, nowId, publicIndex, nextIndex, publicNextIndex, timers, timeToNext } =
|
||||
getSelectionByRoll(this._eventlist, now);
|
||||
getSelectionByRoll(this.rundown, now);
|
||||
|
||||
// nothing to play, unload
|
||||
if (nowIndex === null && nextIndex === null) {
|
||||
@@ -1139,25 +1139,25 @@ export class EventTimer extends Timer {
|
||||
|
||||
// timer counts to next event
|
||||
this.secondaryTimer = timeToNext;
|
||||
this._secondaryTarget = this._eventlist[nextIndex].timeStart;
|
||||
this._secondaryTarget = this.rundown[nextIndex].timeStart;
|
||||
}
|
||||
|
||||
// TITLES: Load next private
|
||||
this._loadThisTitles(this._eventlist[nextIndex], 'next-private');
|
||||
this._loadThisTitles(this.rundown[nextIndex], 'next-private');
|
||||
}
|
||||
|
||||
// TITLES: Load next public
|
||||
if (publicNextIndex !== null) {
|
||||
this._loadThisTitles(this._eventlist[publicNextIndex], 'next-public');
|
||||
this._loadThisTitles(this.rundown[publicNextIndex], 'next-public');
|
||||
}
|
||||
|
||||
// TITLES: Load now private
|
||||
if (nowIndex !== null) {
|
||||
this._loadThisTitles(this._eventlist[nowIndex], 'now-private');
|
||||
this._loadThisTitles(this.rundown[nowIndex], 'now-private');
|
||||
}
|
||||
// TITLES: Load now public
|
||||
if (publicIndex !== null) {
|
||||
this._loadThisTitles(this._eventlist[publicIndex], 'now-public');
|
||||
this._loadThisTitles(this.rundown[publicIndex], 'now-public');
|
||||
}
|
||||
|
||||
if (prevLoaded !== this.selectedEventId) {
|
||||
@@ -1172,7 +1172,7 @@ export class EventTimer extends Timer {
|
||||
// do we need to change
|
||||
if (this.state === 'roll') return;
|
||||
|
||||
if (!this._eventlist.length) return;
|
||||
if (!this.rundown.length) return;
|
||||
|
||||
// set state
|
||||
this.state = 'roll';
|
||||
@@ -1186,7 +1186,7 @@ export class EventTimer extends Timer {
|
||||
|
||||
previous() {
|
||||
// check that we have events to run
|
||||
if (!this._eventlist.length) return;
|
||||
if (!this.rundown.length) return;
|
||||
|
||||
// maybe this is the first event?
|
||||
if (this.selectedEventIndex === 0) return;
|
||||
@@ -1208,7 +1208,7 @@ export class EventTimer extends Timer {
|
||||
}
|
||||
|
||||
next() {
|
||||
const numEvents = this._eventlist.length;
|
||||
const numEvents = this.rundown.length;
|
||||
// check that we have events to run
|
||||
if (!numEvents) return;
|
||||
|
||||
@@ -1250,7 +1250,7 @@ export class EventTimer extends Timer {
|
||||
* @description reloads current event
|
||||
*/
|
||||
reload() {
|
||||
if (!this._eventlist.length) return;
|
||||
if (!this.rundown.length) return;
|
||||
|
||||
// change playstate
|
||||
this.pause();
|
||||
|
||||
@@ -60,8 +60,8 @@ test('object instantiates correctly', async () => {
|
||||
expect(t.nextEventId).toBeNull();
|
||||
expect(t.selectedPublicEventId).toBeNull();
|
||||
expect(t.nextPublicEventId).toBeNull();
|
||||
expect(t._eventlist.length).toBe(0);
|
||||
expect(t._eventlist).toStrictEqual([]);
|
||||
expect(t.rundown.length).toBe(0);
|
||||
expect(t.rundown).toStrictEqual([]);
|
||||
expect(t.onAir).toBeFalsy();
|
||||
|
||||
t.shutdown();
|
||||
@@ -77,7 +77,7 @@ describe('test triggers behaviour', () => {
|
||||
});
|
||||
|
||||
test('does not allow triggering events with an empty list', (done) => {
|
||||
expect(t._eventlist.length).toBe(0);
|
||||
expect(t.rundown.length).toBe(0);
|
||||
|
||||
expect(t.trigger('start')).toBeFalsy();
|
||||
expect(t.trigger('pause')).toBeFalsy();
|
||||
@@ -90,7 +90,7 @@ describe('test triggers behaviour', () => {
|
||||
});
|
||||
|
||||
test('...and is consistent by calling the class methods', (done) => {
|
||||
expect(t._eventlist.length).toBe(0);
|
||||
expect(t.rundown.length).toBe(0);
|
||||
expect(t.state).toBe('stop');
|
||||
|
||||
t.start();
|
||||
|
||||
@@ -24,7 +24,7 @@ export const poll = async (req, res) => {
|
||||
// Returns -
|
||||
export const dbDownload = async (req, res) => {
|
||||
const { title } = DataProvider.getEventData();
|
||||
const fileTitle = title || 'ontime events';
|
||||
const fileTitle = title || 'ontime data';
|
||||
const dbInDisk = resolveDbPath();
|
||||
|
||||
res.download(dbInDisk, `${fileTitle}.json`, (err) => {
|
||||
@@ -50,13 +50,13 @@ const uploadAndParse = async (file, req, res, options) => {
|
||||
} else if (result.message === 'success') {
|
||||
// explicitly write objects
|
||||
if (typeof result !== 'undefined') {
|
||||
const newEvents = result.data.events || [];
|
||||
if (options?.onlyEvents === 'true') {
|
||||
await DataProvider.setEvents(newEvents);
|
||||
const newRundown = result.data.rundown || [];
|
||||
if (options?.onlyRundown === 'true') {
|
||||
await DataProvider.setRundown(newRundown);
|
||||
} else {
|
||||
await DataProvider.mergeIntoData(result.data);
|
||||
}
|
||||
global.timer.setupWithEventList(newEvents.filter((entry) => entry.type === 'event'));
|
||||
global.timer.setupWithEventList(newRundown.filter((entry) => entry.type === 'event'));
|
||||
}
|
||||
res.sendStatus(200);
|
||||
} else {
|
||||
|
||||
+37
-45
@@ -24,8 +24,8 @@ async function _insertAndSync(newEvent) {
|
||||
delete newEvent.after;
|
||||
await DataProvider.insertEventAfterId(newEvent, afterId);
|
||||
if (newEvent.type === 'event') {
|
||||
const events = DataProvider.getEvents();
|
||||
const { id } = getPreviousPlayable(events, newEvent.id);
|
||||
const rundown = DataProvider.getRundown();
|
||||
const { id } = getPreviousPlayable(rundown, newEvent.id);
|
||||
_insertEventInTimerAfterId(newEvent, id);
|
||||
}
|
||||
}
|
||||
@@ -37,8 +37,8 @@ async function _insertAndSync(newEvent) {
|
||||
*/
|
||||
function getEventEvents() {
|
||||
// return data.events.filter((e) => e.type === 'event');
|
||||
const events = DataProvider.getEvents();
|
||||
return Array.from(events).filter((e) => e.type === 'event');
|
||||
const rundown = DataProvider.getRundown();
|
||||
return Array.from(rundown).filter((e) => e.type === 'event');
|
||||
}
|
||||
|
||||
// Updates timer object
|
||||
@@ -76,15 +76,15 @@ function _deleteTimerId(entryId) {
|
||||
global.timer.deleteId(entryId);
|
||||
}
|
||||
|
||||
// Create controller for GET request to '/events'
|
||||
// Create controller for GET request to '/eventlist'
|
||||
// Returns -
|
||||
export const eventsGetAll = async (req, res) => {
|
||||
res.json(DataProvider.getEvents());
|
||||
export const rundownGetAll = async (req, res) => {
|
||||
res.json(DataProvider.getRundown());
|
||||
};
|
||||
|
||||
// Create controller for GET request to '/events/:eventId'
|
||||
// Create controller for GET request to '/eventlist/:eventId'
|
||||
// Returns -
|
||||
export const eventsGetById = async (req, res) => {
|
||||
export const getEventById = async (req, res) => {
|
||||
const id = req.params?.eventId;
|
||||
|
||||
if (id == null) {
|
||||
@@ -95,9 +95,9 @@ export const eventsGetById = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Create controller for POST request to '/events/'
|
||||
// Create controller for POST request to '/eventlist/'
|
||||
// Returns -
|
||||
export const eventsPost = async (req, res) => {
|
||||
export const rundownPost = async (req, res) => {
|
||||
if (failEmptyObjects(req.body, res)) {
|
||||
return;
|
||||
}
|
||||
@@ -137,9 +137,9 @@ export const eventsPost = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Create controller for PUT request to '/events/'
|
||||
// Create controller for PUT request to '/eventlist/'
|
||||
// Returns -
|
||||
export const eventsPut = async (req, res) => {
|
||||
export const rundownPut = async (req, res) => {
|
||||
if (failEmptyObjects(req.body, res)) {
|
||||
return;
|
||||
}
|
||||
@@ -163,8 +163,8 @@ export const eventsPut = async (req, res) => {
|
||||
} else {
|
||||
if (eventInMemory.skip) {
|
||||
// if it was skipped before we add it to the timer
|
||||
const events = DataProvider.getEvents();
|
||||
const { id } = getPreviousPlayable(events, patchedObject.id);
|
||||
const rundown = DataProvider.getRundown();
|
||||
const { id } = getPreviousPlayable(rundown, patchedObject.id);
|
||||
_insertEventInTimerAfterId(patchedObject, id);
|
||||
} else {
|
||||
// otherwise update as normal
|
||||
@@ -178,24 +178,16 @@ export const eventsPut = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Create controller for PATCH request to '/events/'
|
||||
// Returns -
|
||||
// DEPRECATED
|
||||
export const eventsPatch = async (req, res) => {
|
||||
// Code is the same as put, call that
|
||||
await eventsPut(req, res);
|
||||
};
|
||||
|
||||
export const eventsReorder = async (req, res) => {
|
||||
export const rundownReorder = async (req, res) => {
|
||||
if (failEmptyObjects(req.body, res)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { index, from, to } = req.body;
|
||||
|
||||
// get events
|
||||
const events = DataProvider.getEvents();
|
||||
const idx = events.findIndex((e) => e.id === index, from);
|
||||
// get rundown
|
||||
const rundown = DataProvider.getRundown();
|
||||
const idx = rundown.findIndex((e) => e.id === index, from);
|
||||
|
||||
// Check if item is at given index
|
||||
if (idx !== from) {
|
||||
@@ -205,13 +197,13 @@ export const eventsReorder = async (req, res) => {
|
||||
|
||||
try {
|
||||
// remove item at from
|
||||
const [reorderedItem] = events.splice(from, 1);
|
||||
const [reorderedItem] = rundown.splice(from, 1);
|
||||
|
||||
// reinsert item at to
|
||||
events.splice(to, 0, reorderedItem);
|
||||
rundown.splice(to, 0, reorderedItem);
|
||||
|
||||
// save events
|
||||
await DataProvider.setEventData(events);
|
||||
// save rundown
|
||||
await DataProvider.setEventData(rundown);
|
||||
|
||||
// update timer
|
||||
_updateTimers();
|
||||
@@ -222,19 +214,19 @@ export const eventsReorder = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Create controller for PATCH request to '/events/applydelay/:eventId'
|
||||
// Create controller for PATCH request to '/eventlist/applydelay/:eventId'
|
||||
// Returns -
|
||||
export const eventsApplyDelay = async (req, res) => {
|
||||
export const rundownApplyDelay = async (req, res) => {
|
||||
try {
|
||||
// get events
|
||||
const events = DataProvider.getEvents();
|
||||
// get rundown
|
||||
const rundown = DataProvider.getRundown();
|
||||
|
||||
// AUX
|
||||
let delayIndex = null;
|
||||
let blockIndex = null;
|
||||
let delayValue = 0;
|
||||
|
||||
for (const [index, e] of events.entries()) {
|
||||
for (const [index, e] of rundown.entries()) {
|
||||
if (delayIndex == null) {
|
||||
// look for delay
|
||||
if (e.id === req.params.eventId && e.type === 'delay') {
|
||||
@@ -261,14 +253,14 @@ export const eventsApplyDelay = async (req, res) => {
|
||||
}
|
||||
|
||||
// delete delay
|
||||
events.splice(delayIndex, 1);
|
||||
rundown.splice(delayIndex, 1);
|
||||
|
||||
// delete block
|
||||
// index would have moved down since we deleted delay
|
||||
if (blockIndex) events.splice(blockIndex - 1, 1);
|
||||
if (blockIndex) rundown.splice(blockIndex - 1, 1);
|
||||
|
||||
// update events
|
||||
await DataProvider.setEvents(events);
|
||||
// update rundown
|
||||
await DataProvider.setRundown(rundown);
|
||||
|
||||
// update timer
|
||||
_updateTimers();
|
||||
@@ -279,9 +271,9 @@ export const eventsApplyDelay = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Create controller for DELETE request to '/events/:eventId'
|
||||
// Create controller for DELETE request to '/eventlist/:eventId'
|
||||
// Returns -
|
||||
export const eventsDelete = async (req, res) => {
|
||||
export const deleteEventById = async (req, res) => {
|
||||
try {
|
||||
const eventId = req.params.eventId;
|
||||
|
||||
@@ -296,11 +288,11 @@ export const eventsDelete = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Create controller for DELETE request to '/events/:eventId'
|
||||
// Create controller for DELETE request to '/eventlist/:eventId'
|
||||
// Returns -
|
||||
export const eventsDeleteAll = async (req, res) => {
|
||||
export const rundownDelete = async (req, res) => {
|
||||
try {
|
||||
await DataProvider.deleteAllEvents();
|
||||
await DataProvider.clearRundown();
|
||||
global.timer.clearEventList();
|
||||
res.sendStatus(204);
|
||||
} catch (error) {
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import { body, param, validationResult } from 'express-validator';
|
||||
|
||||
export const eventsPostValidator = [
|
||||
export const rundownPostValidator = [
|
||||
body('type').isString().exists().isIn(['event', 'delay', 'block']),
|
||||
(req, res, next) => {
|
||||
const errors = validationResult(req);
|
||||
@@ -9,7 +9,7 @@ export const eventsPostValidator = [
|
||||
},
|
||||
];
|
||||
|
||||
export const eventsPutValidator = [
|
||||
export const rundownPutValidator = [
|
||||
body('id').isString().exists(),
|
||||
(req, res, next) => {
|
||||
const errors = validationResult(req);
|
||||
@@ -1,5 +1,5 @@
|
||||
export const dbModelv1 = {
|
||||
events: [],
|
||||
export const dbModel = {
|
||||
rundown: [],
|
||||
event: {
|
||||
title: '',
|
||||
url: '',
|
||||
@@ -9,7 +9,7 @@ export const dbModelv1 = {
|
||||
},
|
||||
settings: {
|
||||
app: 'ontime',
|
||||
version: 1,
|
||||
version: 2,
|
||||
serverPort: 4001,
|
||||
lock: null,
|
||||
pinCode: null,
|
||||
|
||||
@@ -4,8 +4,8 @@ import { copyFileSync, existsSync } from 'fs';
|
||||
import { ensureDirectory, getAppDataPath } from '../utils/fileManagement.js';
|
||||
import { config } from '../config/config.js';
|
||||
import { validateFile } from '../utils/parserUtils.js';
|
||||
import { dbModelv1 as dbModel } from '../models/dataModel.js';
|
||||
import { parseJson_v1 as parseJson } from '../utils/parser.js';
|
||||
import { dbModel as dbModel } from '../models/dataModel.js';
|
||||
import { parseJson as parseJson } from '../utils/parser.js';
|
||||
|
||||
/**
|
||||
* @description Decides which path the database is in
|
||||
|
||||
+6
-6
@@ -30,15 +30,15 @@ const eventFromDb = {
|
||||
};
|
||||
|
||||
describe('When a POST request is sent', () => {
|
||||
test('POST /event should return a 201', async () => {
|
||||
await supertest(server).post('/events').send(testEvent).expect(201);
|
||||
test('POST /eventlist should return a 201', async () => {
|
||||
await supertest(server).post('/eventlist').send(testEvent).expect(201);
|
||||
});
|
||||
});
|
||||
|
||||
describe('When a GET request request is sent', () => {
|
||||
test('GET /events returns a valid object', async () => {
|
||||
test('GET /eventlist returns a valid object', async () => {
|
||||
await supertest(server)
|
||||
.get('/events')
|
||||
.get('/eventlist')
|
||||
.expect(200)
|
||||
.then((response) => {
|
||||
expect(response.text.includes('<!doctype html>')).toBe(false);
|
||||
@@ -46,9 +46,9 @@ describe('When a GET request request is sent', () => {
|
||||
expect(typeof response.body).toBe('object');
|
||||
});
|
||||
});
|
||||
test('GET /events/:eventId returns a valid object', async () => {
|
||||
test('GET /eventlist/:eventId returns a valid object', async () => {
|
||||
await supertest(server)
|
||||
.get(`/events/${eventFromDb.id}`)
|
||||
.get(`/eventlist/${eventFromDb.id}`)
|
||||
.expect(200)
|
||||
.then((response) => {
|
||||
expect(response.text.includes('<!doctype html>')).toBe(false);
|
||||
@@ -1,48 +0,0 @@
|
||||
import express from 'express';
|
||||
// import events controller
|
||||
import {
|
||||
eventsApplyDelay,
|
||||
eventsDelete,
|
||||
eventsDeleteAll,
|
||||
eventsGetAll,
|
||||
eventsGetById,
|
||||
eventsPatch,
|
||||
eventsPost,
|
||||
eventsPut,
|
||||
eventsReorder,
|
||||
} from '../controllers/eventsController.js';
|
||||
import {
|
||||
eventsPostValidator,
|
||||
eventsPutValidator,
|
||||
paramsMustHaveEventId,
|
||||
} from '../controllers/eventsController.validate.js';
|
||||
|
||||
export const router = express.Router();
|
||||
|
||||
// create route between controller and '/events/' endpoint
|
||||
router.get('/', eventsGetAll);
|
||||
|
||||
// create route between controller and '/events/:eventId' endpoint
|
||||
router.get('/:eventId', eventsGetById);
|
||||
|
||||
// create route between controller and '/events/' endpoint
|
||||
router.post('/', eventsPostValidator, eventsPost);
|
||||
|
||||
// create route between controller and '/events/' endpoint
|
||||
router.put('/', eventsPutValidator, eventsPut);
|
||||
|
||||
// create route between controller and '/events/' endpoint
|
||||
// DEPRECATED
|
||||
router.patch('/', eventsPatch);
|
||||
|
||||
// create route between controller and '/events/reorder' endpoint
|
||||
router.patch('/reorder/', eventsReorder);
|
||||
|
||||
// create route between controller and '/events/applydelay/:eventId' endpoint
|
||||
router.patch('/applydelay/:eventId', paramsMustHaveEventId, eventsApplyDelay);
|
||||
|
||||
// create route between controller and '/events/all' endpoint
|
||||
router.delete('/all', eventsDeleteAll);
|
||||
|
||||
// create route between controller and '/events/:eventId' endpoint
|
||||
router.delete('/:eventId', paramsMustHaveEventId, eventsDelete);
|
||||
@@ -0,0 +1,42 @@
|
||||
import express from 'express';
|
||||
import {
|
||||
deleteEventById,
|
||||
getEventById,
|
||||
rundownApplyDelay,
|
||||
rundownDelete,
|
||||
rundownGetAll,
|
||||
rundownPost,
|
||||
rundownPut,
|
||||
rundownReorder,
|
||||
} from '../controllers/rundownController.js';
|
||||
import {
|
||||
paramsMustHaveEventId,
|
||||
rundownPostValidator,
|
||||
rundownPutValidator,
|
||||
} from '../controllers/rundownController.validate.js';
|
||||
|
||||
export const router = express.Router();
|
||||
|
||||
// create route between controller and '/eventlist/' endpoint
|
||||
router.get('/', rundownGetAll);
|
||||
|
||||
// create route between controller and '/eventlist/:eventId' endpoint
|
||||
router.get('/:eventId', getEventById);
|
||||
|
||||
// create route between controller and '/eventlist/' endpoint
|
||||
router.post('/', rundownPostValidator, rundownPost);
|
||||
|
||||
// create route between controller and '/eventlist/' endpoint
|
||||
router.put('/', rundownPutValidator, rundownPut);
|
||||
|
||||
// create route between controller and '/eventlist/reorder' endpoint
|
||||
router.patch('/reorder/', rundownReorder);
|
||||
|
||||
// create route between controller and '/eventlist/applydelay/:eventId' endpoint
|
||||
router.patch('/applydelay/:eventId', paramsMustHaveEventId, rundownApplyDelay);
|
||||
|
||||
// create route between controller and '/eventlist/all' endpoint
|
||||
router.delete('/all', rundownDelete);
|
||||
|
||||
// create route between controller and '/eventlist/:eventId' endpoint
|
||||
router.delete('/:eventId', paramsMustHaveEventId, deleteEventById);
|
||||
@@ -1,12 +1,22 @@
|
||||
import jest from 'jest-mock';
|
||||
import { dbModelv1, dbModelv1 as dbModel } from '../../models/dataModel.js';
|
||||
import { isStringEmpty, parseExcel_v1, parseJson_v1, validateEvent_v1 } from '../parser.js';
|
||||
import { dbModel } from '../../models/dataModel.js';
|
||||
import { isStringEmpty, parseExcel, parseJson, validateEvent } from '../parser.js';
|
||||
import { makeString, validateDuration } from '../parserUtils.js';
|
||||
import { parseAliases_v1, parseUserFields_v1, parseViews_v1 } from '../parserUtils_v1.js';
|
||||
import { parseAliases, parseUserFields, parseViews } from '../parserFunctions.js';
|
||||
|
||||
describe('refuses import of old / unknown versions', () => {
|
||||
test('a v1 file', () => {
|
||||
const testFile = {
|
||||
settings: {
|
||||
version: 1,
|
||||
},
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
describe('test json parser with valid def', () => {
|
||||
const testData = {
|
||||
events: [
|
||||
rundown: [
|
||||
{
|
||||
title: 'Guest Welcoming',
|
||||
subtitle: '',
|
||||
@@ -183,7 +193,7 @@ describe('test json parser with valid def', () => {
|
||||
},
|
||||
settings: {
|
||||
app: 'ontime',
|
||||
version: 1,
|
||||
version: 2,
|
||||
timeFormat: '24',
|
||||
},
|
||||
};
|
||||
@@ -191,16 +201,16 @@ describe('test json parser with valid def', () => {
|
||||
let parseResponse;
|
||||
|
||||
beforeEach(async () => {
|
||||
parseResponse = await parseJson_v1(testData);
|
||||
parseResponse = await parseJson(testData);
|
||||
});
|
||||
|
||||
it('has 7 events', () => {
|
||||
const length = parseResponse?.events.length;
|
||||
const length = parseResponse?.rundown.length;
|
||||
expect(length).toBe(7);
|
||||
});
|
||||
|
||||
it('first event is as a match', () => {
|
||||
const first = parseResponse?.events[0];
|
||||
const first = parseResponse?.rundown[0];
|
||||
const expected = {
|
||||
title: 'Guest Welcoming',
|
||||
subtitle: '',
|
||||
@@ -231,7 +241,7 @@ describe('test json parser with valid def', () => {
|
||||
});
|
||||
|
||||
it('second event is as a match', () => {
|
||||
const second = parseResponse?.events[1];
|
||||
const second = parseResponse?.rundown[1];
|
||||
const expected = {
|
||||
title: 'Good Morning',
|
||||
subtitle: 'Days schedule',
|
||||
@@ -275,7 +285,7 @@ describe('test json parser with valid def', () => {
|
||||
it('settings are for right app and version', () => {
|
||||
const settings = parseResponse?.settings;
|
||||
expect(settings.app).toBe('ontime');
|
||||
expect(settings.version).toBe(1);
|
||||
expect(settings.version).toBe(2);
|
||||
});
|
||||
|
||||
it('missing settings', () => {
|
||||
@@ -287,7 +297,7 @@ describe('test json parser with valid def', () => {
|
||||
describe('test parser edge cases', () => {
|
||||
it('generates missing ids', async () => {
|
||||
const testData = {
|
||||
events: [
|
||||
rundown: [
|
||||
{
|
||||
title: 'Test Event',
|
||||
type: 'event',
|
||||
@@ -295,14 +305,14 @@ describe('test parser edge cases', () => {
|
||||
],
|
||||
};
|
||||
|
||||
const parseResponse = await parseJson_v1(testData);
|
||||
expect(parseResponse.events[0].id).toBeDefined();
|
||||
const parseResponse = await parseJson(testData);
|
||||
expect(parseResponse.rundown[0].id).toBeDefined();
|
||||
});
|
||||
|
||||
it('detects duplicate Ids', async () => {
|
||||
console.log = jest.fn();
|
||||
const testData = {
|
||||
events: [
|
||||
rundown: [
|
||||
{
|
||||
title: 'Test Event 1',
|
||||
type: 'event',
|
||||
@@ -316,15 +326,15 @@ describe('test parser edge cases', () => {
|
||||
],
|
||||
};
|
||||
|
||||
const parseResponse = await parseJson_v1(testData);
|
||||
const parseResponse = await parseJson(testData);
|
||||
expect(console.log).toHaveBeenCalledWith('ERROR: ID collision on import, skipping');
|
||||
expect(parseResponse?.events.length).toBe(1);
|
||||
expect(parseResponse?.rundown.length).toBe(1);
|
||||
});
|
||||
|
||||
it('handles incomplete datasets', async () => {
|
||||
console.log = jest.fn();
|
||||
const testData = {
|
||||
events: [
|
||||
rundown: [
|
||||
{
|
||||
title: 'Test Event 1',
|
||||
id: '1',
|
||||
@@ -336,9 +346,9 @@ describe('test parser edge cases', () => {
|
||||
],
|
||||
};
|
||||
|
||||
const parseResponse = await parseJson_v1(testData);
|
||||
const parseResponse = await parseJson(testData);
|
||||
expect(console.log).toHaveBeenCalledWith('ERROR: undefined event type, skipping');
|
||||
expect(parseResponse?.events.length).toBe(0);
|
||||
expect(parseResponse?.rundown.length).toBe(0);
|
||||
});
|
||||
|
||||
it('skips unknown app and version settings', async () => {
|
||||
@@ -349,7 +359,7 @@ describe('test parser edge cases', () => {
|
||||
},
|
||||
};
|
||||
|
||||
await parseJson_v1(testData);
|
||||
await parseJson(testData);
|
||||
expect(console.log).toHaveBeenCalledWith('ERROR: unknown app version, skipping');
|
||||
});
|
||||
});
|
||||
@@ -357,7 +367,7 @@ describe('test parser edge cases', () => {
|
||||
describe('test corrupt data', () => {
|
||||
it('handles some empty events', async () => {
|
||||
const emptyEvents = {
|
||||
events: [
|
||||
rundown: [
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
@@ -384,20 +394,20 @@ describe('test corrupt data', () => {
|
||||
},
|
||||
settings: {
|
||||
app: 'ontime',
|
||||
version: 1,
|
||||
version: 2,
|
||||
serverPort: 4001,
|
||||
lock: null,
|
||||
timeFormat: '24',
|
||||
},
|
||||
};
|
||||
|
||||
const parsedDef = await parseJson_v1(emptyEvents);
|
||||
expect(parsedDef.events.length).toBe(2);
|
||||
const parsedDef = await parseJson(emptyEvents);
|
||||
expect(parsedDef.rundown.length).toBe(2);
|
||||
});
|
||||
|
||||
it('handles all empty events', async () => {
|
||||
const emptyEvents = {
|
||||
events: [{}, {}, {}, {}, {}, {}, {}, {}],
|
||||
rundown: [{}, {}, {}, {}, {}, {}, {}, {}],
|
||||
event: {
|
||||
title: 'All about Carlos demo event',
|
||||
url: 'www.carlosvalente.com',
|
||||
@@ -407,52 +417,52 @@ describe('test corrupt data', () => {
|
||||
},
|
||||
settings: {
|
||||
app: 'ontime',
|
||||
version: 1,
|
||||
version: 2,
|
||||
serverPort: 4001,
|
||||
lock: null,
|
||||
timeFormat: '24',
|
||||
},
|
||||
};
|
||||
|
||||
const parsedDef = await parseJson_v1(emptyEvents);
|
||||
expect(parsedDef.events.length).toBe(0);
|
||||
const parsedDef = await parseJson(emptyEvents);
|
||||
expect(parsedDef.rundown.length).toBe(0);
|
||||
});
|
||||
|
||||
it('handles missing event data', async () => {
|
||||
const emptyEventData = {
|
||||
events: [{}, {}, {}, {}, {}, {}, {}, {}],
|
||||
rundown: [{}, {}, {}, {}, {}, {}, {}, {}],
|
||||
event: {},
|
||||
settings: {
|
||||
app: 'ontime',
|
||||
version: 1,
|
||||
version: 2,
|
||||
serverPort: 4001,
|
||||
lock: null,
|
||||
timeFormat: '24',
|
||||
},
|
||||
};
|
||||
|
||||
const parsedDef = await parseJson_v1(emptyEventData);
|
||||
const parsedDef = await parseJson(emptyEventData);
|
||||
expect(parsedDef.event).toStrictEqual(dbModel.event);
|
||||
});
|
||||
|
||||
it('handles missing settings', async () => {
|
||||
const missingSettings = {
|
||||
events: [{}, {}, {}, {}, {}, {}, {}, {}],
|
||||
rundown: [{}, {}, {}, {}, {}, {}, {}, {}],
|
||||
event: {},
|
||||
settings: {
|
||||
app: 'ontime',
|
||||
version: 1,
|
||||
version: 2,
|
||||
},
|
||||
};
|
||||
|
||||
const parsedDef = await parseJson_v1(missingSettings);
|
||||
const parsedDef = await parseJson(missingSettings);
|
||||
expect(parsedDef.settings).toStrictEqual(dbModel.settings);
|
||||
});
|
||||
|
||||
it('fails with invalid JSON', async () => {
|
||||
console.log = jest.fn();
|
||||
const invalidJSON = 'some random dataset';
|
||||
const parsedDef = await parseJson_v1(invalidJSON);
|
||||
const parsedDef = await parseJson(invalidJSON);
|
||||
expect(console.log).toHaveBeenCalledWith('ERROR: Invalid JSON format');
|
||||
expect(parsedDef).toBe(-1);
|
||||
});
|
||||
@@ -463,7 +473,7 @@ describe('test event validator', () => {
|
||||
const event = {
|
||||
title: 'test',
|
||||
};
|
||||
const validated = validateEvent_v1(event);
|
||||
const validated = validateEvent(event);
|
||||
|
||||
expect(validated).toEqual(
|
||||
expect.objectContaining({
|
||||
@@ -489,13 +499,13 @@ describe('test event validator', () => {
|
||||
user7: expect.any(String),
|
||||
user8: expect.any(String),
|
||||
user9: expect.any(String),
|
||||
})
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('fails an empty object', () => {
|
||||
const event = {};
|
||||
const validated = validateEvent_v1(event);
|
||||
const validated = validateEvent(event);
|
||||
expect(validated).toEqual(null);
|
||||
});
|
||||
|
||||
@@ -506,7 +516,7 @@ describe('test event validator', () => {
|
||||
presenter: 3.2,
|
||||
note: '1899-12-30T08:00:10.000Z',
|
||||
};
|
||||
const validated = validateEvent_v1(event);
|
||||
const validated = validateEvent(event);
|
||||
expect(typeof validated.title).toEqual('string');
|
||||
expect(typeof validated.subtitle).toEqual('string');
|
||||
expect(typeof validated.presenter).toEqual('string');
|
||||
@@ -518,7 +528,7 @@ describe('test event validator', () => {
|
||||
timeStart: false,
|
||||
timeEnd: '2',
|
||||
};
|
||||
const validated = validateEvent_v1(event);
|
||||
const validated = validateEvent(event);
|
||||
expect(typeof validated.timeStart).toEqual('number');
|
||||
expect(validated.timeStart).toEqual(0);
|
||||
expect(typeof validated.timeEnd).toEqual('number');
|
||||
@@ -529,7 +539,7 @@ describe('test event validator', () => {
|
||||
const event = {
|
||||
title: {},
|
||||
};
|
||||
const validated = validateEvent_v1(event);
|
||||
const validated = validateEvent(event);
|
||||
expect(typeof validated.title).toEqual('string');
|
||||
});
|
||||
});
|
||||
@@ -651,7 +661,7 @@ describe('test parseExcel function', () => {
|
||||
endMessage: 'test end message',
|
||||
};
|
||||
|
||||
const expectedParsedEvents = [
|
||||
const expectedParsedRundown = [
|
||||
{
|
||||
timeStart: 25200000,
|
||||
timeEnd: 28810000,
|
||||
@@ -690,27 +700,27 @@ describe('test parseExcel function', () => {
|
||||
},
|
||||
];
|
||||
|
||||
const parsedData = await parseExcel_v1(testdata);
|
||||
const parsedData = await parseExcel(testdata);
|
||||
|
||||
expect(parsedData.event).toStrictEqual(expectedParsedEvent);
|
||||
expect(parsedData.events).toBeDefined();
|
||||
expect(parsedData.events.title).toBe(expectedParsedEvents.title);
|
||||
expect(parsedData.events.presenter).toBe(expectedParsedEvents.presenter);
|
||||
expect(parsedData.events.subtitle).toBe(expectedParsedEvents.subtitle);
|
||||
expect(parsedData.events.isPublic).toBe(expectedParsedEvents.isPublic);
|
||||
expect(parsedData.events.skip).toBe(expectedParsedEvents.skip);
|
||||
expect(parsedData.events.note).toBe(expectedParsedEvents.note);
|
||||
expect(parsedData.events.type).toBe(expectedParsedEvents.type);
|
||||
expect(parsedData.rundown).toBeDefined();
|
||||
expect(parsedData.rundown.title).toBe(expectedParsedRundown.title);
|
||||
expect(parsedData.rundown.presenter).toBe(expectedParsedRundown.presenter);
|
||||
expect(parsedData.rundown.subtitle).toBe(expectedParsedRundown.subtitle);
|
||||
expect(parsedData.rundown.isPublic).toBe(expectedParsedRundown.isPublic);
|
||||
expect(parsedData.rundown.skip).toBe(expectedParsedRundown.skip);
|
||||
expect(parsedData.rundown.note).toBe(expectedParsedRundown.note);
|
||||
expect(parsedData.rundown.type).toBe(expectedParsedRundown.type);
|
||||
});
|
||||
});
|
||||
|
||||
describe('test aliases import', () => {
|
||||
it('imports a well defined alias', () => {
|
||||
const testData = {
|
||||
events: [],
|
||||
rundown: [],
|
||||
settings: {
|
||||
app: 'ontime',
|
||||
version: 1,
|
||||
version: 2,
|
||||
},
|
||||
aliases: [
|
||||
{
|
||||
@@ -721,7 +731,7 @@ describe('test aliases import', () => {
|
||||
],
|
||||
};
|
||||
|
||||
const parsed = parseAliases_v1(testData);
|
||||
const parsed = parseAliases(testData);
|
||||
expect(parsed.length).toBe(1);
|
||||
|
||||
// generates missing id
|
||||
@@ -730,7 +740,7 @@ describe('test aliases import', () => {
|
||||
});
|
||||
|
||||
describe('test userFields import', () => {
|
||||
const model = dbModelv1.userFields;
|
||||
const model = dbModel.userFields;
|
||||
it('imports a fully defined user fields', () => {
|
||||
const testUserFields = {
|
||||
user0: 'test0',
|
||||
@@ -746,15 +756,15 @@ describe('test userFields import', () => {
|
||||
};
|
||||
|
||||
const testData = {
|
||||
events: [],
|
||||
rundown: [],
|
||||
settings: {
|
||||
app: 'ontime',
|
||||
version: 1,
|
||||
version: 2,
|
||||
},
|
||||
userFields: testUserFields,
|
||||
};
|
||||
|
||||
const parsed = parseUserFields_v1(testData);
|
||||
const parsed = parseUserFields(testData);
|
||||
expect(parsed).toStrictEqual(testUserFields);
|
||||
});
|
||||
|
||||
@@ -773,38 +783,38 @@ describe('test userFields import', () => {
|
||||
};
|
||||
|
||||
const testData = {
|
||||
events: [],
|
||||
rundown: [],
|
||||
settings: {
|
||||
app: 'ontime',
|
||||
version: 1,
|
||||
version: 2,
|
||||
},
|
||||
userFields: testUserFields,
|
||||
};
|
||||
|
||||
const parsed = parseUserFields_v1(testData);
|
||||
const parsed = parseUserFields(testData);
|
||||
expect(parsed).toStrictEqual(expected);
|
||||
});
|
||||
|
||||
it('handles missing user fields', () => {
|
||||
const testData = {
|
||||
events: [],
|
||||
rundown: [],
|
||||
settings: {
|
||||
app: 'ontime',
|
||||
version: 1,
|
||||
version: 2,
|
||||
},
|
||||
};
|
||||
|
||||
const parsed = parseUserFields_v1(testData);
|
||||
const parsed = parseUserFields(testData);
|
||||
expect(parsed).toStrictEqual(model);
|
||||
expect(parsed).toStrictEqual(model);
|
||||
});
|
||||
|
||||
it('ignores badly defined fields', () => {
|
||||
const testData = {
|
||||
events: [],
|
||||
rundown: [],
|
||||
settings: {
|
||||
app: 'ontime',
|
||||
version: 1,
|
||||
version: 2,
|
||||
},
|
||||
userFields: {
|
||||
notThis: 'this shouldng be accepted',
|
||||
@@ -812,7 +822,7 @@ describe('test userFields import', () => {
|
||||
},
|
||||
};
|
||||
|
||||
const parsed = parseUserFields_v1(testData);
|
||||
const parsed = parseUserFields(testData);
|
||||
expect(parsed).toStrictEqual(model);
|
||||
});
|
||||
});
|
||||
@@ -820,29 +830,29 @@ describe('test userFields import', () => {
|
||||
describe('test views import', () => {
|
||||
it('imports data from file', () => {
|
||||
const testData = {
|
||||
events: [],
|
||||
rundown: [],
|
||||
settings: {
|
||||
app: 'ontime',
|
||||
version: 1,
|
||||
version: 2,
|
||||
},
|
||||
views: {
|
||||
overrideStyles: true,
|
||||
},
|
||||
};
|
||||
const parsed = parseViews_v1(testData);
|
||||
const parsed = parseViews(testData);
|
||||
expect(parsed).toStrictEqual(testData.views);
|
||||
});
|
||||
|
||||
it('imports defaults to model', () => {
|
||||
const testData = {
|
||||
events: [],
|
||||
rundown: [],
|
||||
settings: {
|
||||
app: 'ontime',
|
||||
version: 1,
|
||||
version: 2,
|
||||
},
|
||||
};
|
||||
const parsed = parseViews_v1(testData, true);
|
||||
expect(parsed).toStrictEqual(dbModelv1.views);
|
||||
const parsed = parseViews(testData, true);
|
||||
expect(parsed).toStrictEqual(dbModel.views);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+31
-31
@@ -1,18 +1,18 @@
|
||||
import fs from 'fs';
|
||||
import xlsx from 'node-xlsx';
|
||||
import { event as eventDef } from '../models/eventsDefinition.js';
|
||||
import { dbModelv1 } from '../models/dataModel.js';
|
||||
import { dbModel } from '../models/dataModel.js';
|
||||
import { deleteFile, makeString, validateDuration } from './parserUtils.js';
|
||||
import {
|
||||
parseAliases_v1,
|
||||
parseEvent_v1,
|
||||
parseEvents_v1,
|
||||
parseHttp_v1,
|
||||
parseOsc_v1,
|
||||
parseSettings_v1,
|
||||
parseUserFields_v1,
|
||||
parseViews_v1,
|
||||
} from './parserUtils_v1.js';
|
||||
parseAliases,
|
||||
parseEvent,
|
||||
parseHttp,
|
||||
parseOsc,
|
||||
parseRundown,
|
||||
parseSettings,
|
||||
parseUserFields,
|
||||
parseViews,
|
||||
} from './parserFunctions.js';
|
||||
import { parseExcelDate } from './time.js';
|
||||
import { generateId } from './generate_id.js';
|
||||
|
||||
@@ -37,13 +37,13 @@ export const isStringEmpty = (value) => {
|
||||
* @param {array} excelData - array with excel sheet
|
||||
* @returns {object} - parsed object
|
||||
*/
|
||||
export const parseExcel_v1 = async (excelData) => {
|
||||
export const parseExcel = async (excelData) => {
|
||||
const eventData = {
|
||||
title: '',
|
||||
url: '',
|
||||
};
|
||||
const customUserFields = {};
|
||||
const events = [];
|
||||
const rundown = [];
|
||||
let timeStartIndex = null;
|
||||
let timeEndIndex = null;
|
||||
let titleIndex = null;
|
||||
@@ -238,17 +238,17 @@ export const parseExcel_v1 = async (excelData) => {
|
||||
if (Object.keys(event).length > 0) {
|
||||
// if any data was found, push to array
|
||||
// take care of it in the next step
|
||||
events.push({ ...event, type: 'event' });
|
||||
rundown.push({ ...event, type: 'event' });
|
||||
}
|
||||
});
|
||||
return {
|
||||
events,
|
||||
rundown,
|
||||
event: eventData,
|
||||
settings: {
|
||||
app: 'ontime',
|
||||
version: 1,
|
||||
version: 2,
|
||||
},
|
||||
userFields: { ...dbModelv1.userFields, ...customUserFields },
|
||||
userFields: { ...dbModel.userFields, ...customUserFields },
|
||||
};
|
||||
};
|
||||
|
||||
@@ -258,7 +258,7 @@ export const parseExcel_v1 = async (excelData) => {
|
||||
* @param {boolean} [enforce=false] - flag, tells to create an object anyway
|
||||
* @returns {object} - parsed object
|
||||
*/
|
||||
export const parseJson_v1 = async (jsonData, enforce = false) => {
|
||||
export const parseJson = async (jsonData, enforce = false) => {
|
||||
if (!jsonData || typeof jsonData !== 'object') {
|
||||
console.log('ERROR: Invalid JSON format');
|
||||
return -1;
|
||||
@@ -268,21 +268,21 @@ export const parseJson_v1 = async (jsonData, enforce = false) => {
|
||||
const returnData = {};
|
||||
|
||||
// parse Events
|
||||
returnData.events = parseEvents_v1(jsonData);
|
||||
returnData.rundown = parseRundown(jsonData);
|
||||
// parse Event
|
||||
returnData.event = parseEvent_v1(jsonData, enforce);
|
||||
returnData.event = parseEvent(jsonData, enforce);
|
||||
// Settings handled partially
|
||||
returnData.settings = parseSettings_v1(jsonData, enforce);
|
||||
returnData.settings = parseSettings(jsonData, enforce);
|
||||
// View settings handled partially
|
||||
returnData.views = parseViews_v1(jsonData, enforce);
|
||||
returnData.views = parseViews(jsonData, enforce);
|
||||
// Import OSC settings if any
|
||||
returnData.osc = parseOsc_v1(jsonData, enforce);
|
||||
returnData.osc = parseOsc(jsonData, enforce);
|
||||
// Import HTTP settings if any
|
||||
returnData.http = parseHttp_v1(jsonData, enforce);
|
||||
returnData.http = parseHttp(jsonData, enforce);
|
||||
// Import Aliases if any
|
||||
returnData.aliases = parseAliases_v1(jsonData);
|
||||
returnData.aliases = parseAliases(jsonData);
|
||||
// Import user fields if any
|
||||
returnData.userFields = parseUserFields_v1(jsonData);
|
||||
returnData.userFields = parseUserFields(jsonData);
|
||||
|
||||
return returnData;
|
||||
};
|
||||
@@ -293,7 +293,7 @@ export const parseJson_v1 = async (jsonData, enforce = false) => {
|
||||
* @returns {object|null} - formatted object or null in case is invalid
|
||||
*/
|
||||
|
||||
export const validateEvent_v1 = (eventArgs) => {
|
||||
export const validateEvent = (eventArgs) => {
|
||||
// ensure id is defined and unique
|
||||
const id = eventArgs.id || generateId();
|
||||
let event = null;
|
||||
@@ -363,11 +363,11 @@ export const fileHandler = async (file) => {
|
||||
|
||||
// we only look at worksheets called ontime or event schedule
|
||||
if (excelData?.data) {
|
||||
const dataFromExcel = await parseExcel_v1(excelData.data);
|
||||
const dataFromExcel = await parseExcel(excelData.data);
|
||||
res.data = {};
|
||||
res.data.events = parseEvents_v1(dataFromExcel);
|
||||
res.data.event = parseEvent_v1(dataFromExcel, true);
|
||||
res.data.userFields = parseUserFields_v1(dataFromExcel);
|
||||
res.data.events = parseRundown(dataFromExcel);
|
||||
res.data.event = parseEvent(dataFromExcel, true);
|
||||
res.data.userFields = parseUserFields(dataFromExcel);
|
||||
res.message = 'success';
|
||||
} else {
|
||||
console.log('Error: No sheets found named ontime or event schedule');
|
||||
@@ -394,7 +394,7 @@ export const fileHandler = async (file) => {
|
||||
|
||||
if (uploadedJson.settings.version === 1) {
|
||||
try {
|
||||
res.data = await parseJson_v1(uploadedJson);
|
||||
res.data = await parseJson(uploadedJson);
|
||||
res.message = 'success';
|
||||
} catch (error) {
|
||||
res = { error: true, message: `Error parsing file: ${error}` };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { block as blockDef, delay as delayDef } from '../models/eventsDefinition.js';
|
||||
import { dbModelv1 } from '../models/dataModel.js';
|
||||
import { validateEvent_v1 } from './parser.js';
|
||||
import { dbModel } from '../models/dataModel.js';
|
||||
import { validateEvent } from './parser.js';
|
||||
import { generateId } from './generate_id.js';
|
||||
import { MAX_EVENTS } from '../settings.js';
|
||||
|
||||
@@ -9,16 +9,16 @@ import { MAX_EVENTS } from '../settings.js';
|
||||
* @param {object} data - data object
|
||||
* @returns {object} - event object data
|
||||
*/
|
||||
export const parseEvents_v1 = (data) => {
|
||||
let newEvents = [];
|
||||
if ('events' in data) {
|
||||
console.log('Found events definition, importing...');
|
||||
const events = [];
|
||||
export const parseRundown = (data) => {
|
||||
let newRundown = [];
|
||||
if ('rundown' in data) {
|
||||
console.log('Found rundown definition, importing...');
|
||||
const rundown = [];
|
||||
try {
|
||||
const ids = [];
|
||||
for (const e of data.events) {
|
||||
for (const e of data.rundown) {
|
||||
// cap number of events
|
||||
if (events.length >= MAX_EVENTS) {
|
||||
if (rundown.length >= MAX_EVENTS) {
|
||||
console.log(`ERROR: Reached limit number of ${MAX_EVENTS} events`);
|
||||
break;
|
||||
}
|
||||
@@ -30,19 +30,19 @@ export const parseEvents_v1 = (data) => {
|
||||
}
|
||||
|
||||
if (e.type === 'event') {
|
||||
const event = validateEvent_v1(e);
|
||||
const event = validateEvent(e);
|
||||
if (event != null) {
|
||||
events.push(event);
|
||||
rundown.push(event);
|
||||
ids.push(event.id);
|
||||
}
|
||||
} else if (e.type === 'delay') {
|
||||
events.push({
|
||||
rundown.push({
|
||||
...delayDef,
|
||||
duration: e.duration,
|
||||
id: e.id || generateId(),
|
||||
});
|
||||
} else if (e.type === 'block') {
|
||||
events.push({ ...blockDef, id: e.id || generateId() });
|
||||
rundown.push({ ...blockDef, id: e.id || generateId() });
|
||||
} else {
|
||||
console.log('ERROR: undefined event type, skipping');
|
||||
}
|
||||
@@ -51,10 +51,10 @@ export const parseEvents_v1 = (data) => {
|
||||
console.log(`Error ${error}`);
|
||||
}
|
||||
// write to db
|
||||
newEvents = events;
|
||||
console.log(`Uploaded file with ${events.length} entries`);
|
||||
newRundown = rundown;
|
||||
console.log(`Uploaded file with ${newRundown.length} entries`);
|
||||
}
|
||||
return newEvents;
|
||||
return newRundown;
|
||||
};
|
||||
/**
|
||||
* Parse event portion of an entry
|
||||
@@ -62,22 +62,22 @@ export const parseEvents_v1 = (data) => {
|
||||
* @param {boolean} enforce - whether to create a definition if one is missing
|
||||
* @returns {object} - event object data
|
||||
*/
|
||||
export const parseEvent_v1 = (data, enforce) => {
|
||||
export const parseEvent = (data, enforce) => {
|
||||
let newEvent = {};
|
||||
if ('event' in data) {
|
||||
console.log('Found event data, importing...');
|
||||
const e = data.event;
|
||||
// filter known properties and write to db
|
||||
newEvent = {
|
||||
...dbModelv1.event,
|
||||
title: e.title || dbModelv1.event.title,
|
||||
url: e.url || dbModelv1.event.url,
|
||||
publicInfo: e.publicInfo || dbModelv1.event.publicInfo,
|
||||
backstageInfo: e.backstageInfo || dbModelv1.event.backstageInfo,
|
||||
endMessage: e.endMessage || dbModelv1.event.endMessage,
|
||||
...dbModel.event,
|
||||
title: e.title || dbModel.event.title,
|
||||
url: e.url || dbModel.event.url,
|
||||
publicInfo: e.publicInfo || dbModel.event.publicInfo,
|
||||
backstageInfo: e.backstageInfo || dbModel.event.backstageInfo,
|
||||
endMessage: e.endMessage || dbModel.event.endMessage,
|
||||
};
|
||||
} else if (enforce) {
|
||||
newEvent = { ...dbModelv1.event };
|
||||
newEvent = { ...dbModel.event };
|
||||
console.log(`Created event object in db`);
|
||||
}
|
||||
return newEvent;
|
||||
@@ -89,7 +89,7 @@ export const parseEvent_v1 = (data, enforce) => {
|
||||
* @param {boolean} enforce - whether to create a definition if one is missing
|
||||
* @returns {object} - event object data
|
||||
*/
|
||||
export const parseSettings_v1 = (data, enforce) => {
|
||||
export const parseSettings = (data, enforce) => {
|
||||
let newSettings = {};
|
||||
if ('settings' in data) {
|
||||
console.log('Found settings definition, importing...');
|
||||
@@ -107,12 +107,12 @@ export const parseSettings_v1 = (data, enforce) => {
|
||||
|
||||
// write to db
|
||||
newSettings = {
|
||||
...dbModelv1.settings,
|
||||
...dbModel.settings,
|
||||
...settings,
|
||||
};
|
||||
}
|
||||
} else if (enforce) {
|
||||
newSettings = dbModelv1.settings;
|
||||
newSettings = dbModel.settings;
|
||||
console.log(`Created settings object in db`);
|
||||
}
|
||||
return newSettings;
|
||||
@@ -124,14 +124,14 @@ export const parseSettings_v1 = (data, enforce) => {
|
||||
* @param {boolean} enforce - whether to create a definition if one is missing
|
||||
* @returns {object} - event object data
|
||||
*/
|
||||
export const parseViews_v1 = (data, enforce) => {
|
||||
export const parseViews = (data, enforce) => {
|
||||
let newViews = {};
|
||||
if ('views' in data) {
|
||||
console.log('Found view definition, importing...');
|
||||
const v = data.views;
|
||||
|
||||
const viewSettings = {
|
||||
overrideStyles: v.overrideStyles ?? dbModelv1.views.overrideStyles,
|
||||
overrideStyles: v.overrideStyles ?? dbModel.views.overrideStyles,
|
||||
};
|
||||
|
||||
// write to db
|
||||
@@ -139,7 +139,7 @@ export const parseViews_v1 = (data, enforce) => {
|
||||
...viewSettings,
|
||||
};
|
||||
} else if (enforce) {
|
||||
newViews = dbModelv1.views;
|
||||
newViews = dbModel.views;
|
||||
console.log(`Created view object in db`);
|
||||
}
|
||||
return newViews;
|
||||
@@ -151,7 +151,7 @@ export const parseViews_v1 = (data, enforce) => {
|
||||
* @param {boolean} enforce - whether to create a definition if one is missing
|
||||
* @returns {object} - event object data
|
||||
*/
|
||||
export const parseOsc_v1 = (data, enforce) => {
|
||||
export const parseOsc = (data, enforce) => {
|
||||
let newOsc = {};
|
||||
if ('osc' in data) {
|
||||
console.log('Found OSC definition, importing...');
|
||||
@@ -164,11 +164,11 @@ export const parseOsc_v1 = (data, enforce) => {
|
||||
if (typeof s.enabled !== 'undefined') osc.enabled = s.enabled;
|
||||
// write to db
|
||||
newOsc = {
|
||||
...dbModelv1.osc,
|
||||
...dbModel.osc,
|
||||
...osc,
|
||||
};
|
||||
} else if (enforce) {
|
||||
newOsc = { ...dbModelv1.osc };
|
||||
newOsc = { ...dbModel.osc };
|
||||
console.log(`Created OSC object in db`);
|
||||
}
|
||||
return newOsc;
|
||||
@@ -180,7 +180,7 @@ export const parseOsc_v1 = (data, enforce) => {
|
||||
* @param {boolean} enforce - whether to create a definition if one is missing
|
||||
* @returns {object} - event object data
|
||||
*/
|
||||
export const parseHttp_v1 = (data, enforce) => {
|
||||
export const parseHttp = (data, enforce) => {
|
||||
const newHttp = {};
|
||||
if ('http' in data) {
|
||||
console.log('Found HTTP definition, importing...');
|
||||
@@ -192,11 +192,11 @@ export const parseHttp_v1 = (data, enforce) => {
|
||||
|
||||
// write to db
|
||||
newHttp.http = {
|
||||
...dbModelv1.http,
|
||||
...dbModel.http,
|
||||
...http,
|
||||
};
|
||||
} else if (enforce) {
|
||||
newHttp.http = { ...dbModelv1.http };
|
||||
newHttp.http = { ...dbModel.http };
|
||||
console.log(`Created http object in db`);
|
||||
}
|
||||
return newHttp;
|
||||
@@ -207,7 +207,7 @@ export const parseHttp_v1 = (data, enforce) => {
|
||||
* @param {object} data - data object
|
||||
* @returns {object} - event object data
|
||||
*/
|
||||
export const parseAliases_v1 = (data) => {
|
||||
export const parseAliases = (data) => {
|
||||
const newAliases = [];
|
||||
if ('aliases' in data) {
|
||||
console.log('Found Aliases definition, importing...');
|
||||
@@ -242,8 +242,8 @@ export const parseAliases_v1 = (data) => {
|
||||
* @param {object} data - data object
|
||||
* @returns {object} - event object data
|
||||
*/
|
||||
export const parseUserFields_v1 = (data) => {
|
||||
const newUserFields = { ...dbModelv1.userFields };
|
||||
export const parseUserFields = (data) => {
|
||||
const newUserFields = { ...dbModel.userFields };
|
||||
|
||||
if ('userFields' in data) {
|
||||
console.log('Found User Fields definition, importing...');
|
||||
Reference in New Issue
Block a user