mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-14 20:03:52 +00:00
fix: automation form validation
This commit is contained in:
committed by
Carlos Valente
parent
166160dda9
commit
701f24cece
@@ -124,8 +124,14 @@ export const validateTestPayload = [
|
||||
body('action').if(body('type').equals('ontime')).isString().trim(),
|
||||
body('text').if(body('type').equals('ontime')).optional().isString().trim(),
|
||||
body('time').if(body('type').equals('ontime')).optional().isString().trim(),
|
||||
body('visible').if(body('type').equals('ontime')).optional().isString().trim(),
|
||||
body('secondarySource').if(body('type').equals('ontime')).optional().isString().trim(),
|
||||
body('visible').if(body('type').equals('ontime')).optional().isBoolean(),
|
||||
// secondary source can be a enum case or null to clear it
|
||||
body('secondarySource')
|
||||
.if(body('type').equals('ontime'))
|
||||
.optional({ nullable: true })
|
||||
.if((value) => value !== null)
|
||||
.isString()
|
||||
.trim(),
|
||||
|
||||
requestValidationFunction,
|
||||
];
|
||||
@@ -222,8 +228,16 @@ function parseOntimeAction(maybeOntimeAction: object): OntimeAction {
|
||||
|
||||
if (maybeOntimeAction.action === 'message-secondary') {
|
||||
assert.hasKeys(maybeOntimeAction, ['secondarySource']);
|
||||
assert.isString(maybeOntimeAction.secondarySource);
|
||||
// null is used to clear the secondary source
|
||||
if (maybeOntimeAction.secondarySource === null) {
|
||||
return {
|
||||
type: 'ontime',
|
||||
action: 'message-secondary',
|
||||
secondarySource: null,
|
||||
};
|
||||
}
|
||||
|
||||
assert.isString(maybeOntimeAction.secondarySource);
|
||||
return {
|
||||
type: 'ontime',
|
||||
action: 'message-secondary',
|
||||
|
||||
@@ -3,6 +3,7 @@ import { DeepPartial } from 'ts-essentials';
|
||||
|
||||
import { throttle } from '../../utils/throttle.js';
|
||||
import type { StoreGetter, PublishFn } from '../../stores/EventStore.js';
|
||||
import { withoutUndefinedValues } from '../../../../../packages/utils/src/common/objectUtils.js';
|
||||
|
||||
/**
|
||||
* Create a throttled version of the set function
|
||||
@@ -42,7 +43,10 @@ export function patch(patch: DeepPartial<MessageState>): MessageState {
|
||||
// make a copy of the state in store
|
||||
const newState = { ...getState() };
|
||||
|
||||
if ('timer' in patch) newState.timer = { ...newState.timer, ...patch.timer };
|
||||
if (patch.timer !== undefined) {
|
||||
const sanitisedTimer = withoutUndefinedValues(patch.timer);
|
||||
newState.timer = { ...newState.timer, ...sanitisedTimer };
|
||||
}
|
||||
if ('secondary' in patch && patch.secondary !== undefined) newState.secondary = patch.secondary;
|
||||
|
||||
throttledSet('message', newState);
|
||||
|
||||
Reference in New Issue
Block a user