Feat/change event api (#553)

* feat: change attribute for given event 

---------

Co-authored-by: Ary <arylmoraesn@gmail.com>
Co-authored-by: arc-alex <ac@omnivox.dk>
This commit is contained in:
Alex Christoffer Rasmussen
2023-10-31 19:24:22 +01:00
committed by GitHub
parent 78d5d442cf
commit a01046b479
8 changed files with 173 additions and 9 deletions
@@ -1,9 +1,26 @@
import { LogOrigin, OntimeEvent } from 'ontime-types';
import { messageService } from '../services/message-service/MessageService.js';
import { PlaybackService } from '../services/PlaybackService.js';
import { eventStore } from '../stores/EventStore.js';
import { parse, updateEvent } from './integrationController.config.js';
import { isKeyOfType } from 'ontime-types/src/utils/guards.js';
import { event } from '../models/eventsDefinition.js';
export function dispatchFromAdapter(type: string, payload: unknown, source?: 'osc' | 'ws') {
switch (type.toLowerCase()) {
export function dispatchFromAdapter(
type: string,
args: {
payload: unknown;
params?: Array<string>;
},
source?: 'osc' | 'ws',
) {
const payload = args.payload;
const typeComponents = type.toLowerCase().split('/');
const mainType = typeComponents[0];
const params = args.params || [];
switch (mainType) {
case 'test-ontime': {
return { topic: 'hello' };
}
@@ -222,6 +239,23 @@ export function dispatchFromAdapter(type: string, payload: unknown, source?: 'os
return { topic: 'timer', payload: timer };
}
// ontime/change/{eventID}/{propertyName}
case 'change': {
if (params.length < 2) {
throw new Error(`To few parameters`);
}
if (payload === undefined) {
throw new Error(`Undefined payload`);
}
const eventID = params[0];
const propertyName = params[1] as keyof OntimeEvent;
if (!isKeyOfType(propertyName, event)) {
throw new Error(`Cannot update unknown event property ${propertyName}`);
}
const parsedPayload = parse(propertyName, payload);
return updateEvent(eventID, propertyName, parsedPayload);
}
default: {
throw new Error(`Unhandled message ${type}`);
}