mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-08 08:53:51 +00:00
Refactor: ms for api calls (#1593)
* use ms for api calls * change it in UI * update comment * rename variables * refactor: addtime api logic
This commit is contained in:
committed by
arc-alex
parent
5c47a834b5
commit
8e994fb0df
@@ -1,5 +1,5 @@
|
||||
import { MessageState, OffsetMode, OntimeEvent, SimpleDirection, SimplePlayback } from 'ontime-types';
|
||||
import { MILLIS_PER_HOUR, MILLIS_PER_SECOND } from 'ontime-utils';
|
||||
import { MILLIS_PER_HOUR } from 'ontime-utils';
|
||||
|
||||
import { DeepPartial } from 'ts-essentials';
|
||||
|
||||
@@ -187,27 +187,24 @@ const actionHandlers: Record<string, ActionHandler> = {
|
||||
throw new Error('No matching method provided');
|
||||
},
|
||||
addtime: (payload) => {
|
||||
let time = 0;
|
||||
if (payload && typeof payload === 'object') {
|
||||
if ('add' in payload) {
|
||||
time = numberOrError(payload.add);
|
||||
} else if ('remove' in payload) {
|
||||
time = numberOrError(payload.remove) * -1;
|
||||
const time = (() => {
|
||||
if (payload && typeof payload === 'object') {
|
||||
if ('add' in payload) return numberOrError(payload.add);
|
||||
if ('remove' in payload) return numberOrError(payload.remove) * -1;
|
||||
}
|
||||
} else {
|
||||
time = numberOrError(payload);
|
||||
}
|
||||
return numberOrError(payload);
|
||||
})();
|
||||
|
||||
assert.isNumber(time);
|
||||
if (time === 0) {
|
||||
return { payload: 'success' };
|
||||
}
|
||||
|
||||
const timeToAdd = time * MILLIS_PER_SECOND; // frontend is seconds based
|
||||
if (Math.abs(timeToAdd) > MILLIS_PER_HOUR) {
|
||||
if (Math.abs(time) > MILLIS_PER_HOUR) {
|
||||
throw new Error(`Payload too large: ${time}`);
|
||||
}
|
||||
|
||||
runtimeService.addTime(timeToAdd);
|
||||
runtimeService.addTime(time);
|
||||
return { payload: 'success' };
|
||||
},
|
||||
/* Extra timers */
|
||||
@@ -233,13 +230,11 @@ const actionHandlers: Record<string, ActionHandler> = {
|
||||
} else if (command && typeof command === 'object') {
|
||||
const reply = { payload: {} };
|
||||
if ('duration' in command) {
|
||||
// convert duration in seconds to ms
|
||||
const timeInMs = numberOrError(command.duration) * 1000;
|
||||
const timeInMs = numberOrError(command.duration);
|
||||
reply.payload = auxTimerService.setTime(timeInMs);
|
||||
}
|
||||
if ('addtime' in command) {
|
||||
// convert addTime in seconds to ms
|
||||
const timeInMs = numberOrError(command.addtime) * 1000;
|
||||
const timeInMs = numberOrError(command.addtime);
|
||||
reply.payload = auxTimerService.addTime(timeInMs);
|
||||
}
|
||||
if ('direction' in command) {
|
||||
|
||||
Reference in New Issue
Block a user