mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-08 08:53:51 +00:00
fix: validateLinkStart (#1430)
* fix validateLinkStart * update comment * use fallback * cast to MaybeString * update comment Co-authored-by: Carlos Valente <34649812+cpvalente@users.noreply.github.com> --------- Co-authored-by: Carlos Valente <34649812+cpvalente@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
891c43ba77
commit
743d7fa782
@@ -376,7 +376,7 @@ export function createPatch(originalEvent: OntimeEvent, patchEvent: Partial<Onti
|
||||
timeEnd,
|
||||
duration,
|
||||
timeStrategy,
|
||||
linkStart: validateLinkStart(patchEvent.linkStart),
|
||||
linkStart: validateLinkStart(patchEvent.linkStart, originalEvent.linkStart),
|
||||
endAction: validateEndAction(patchEvent.endAction, originalEvent.endAction),
|
||||
timerType: validateTimerType(patchEvent.timerType, originalEvent.timerType),
|
||||
countToEnd: typeof patchEvent.countToEnd === 'boolean' ? patchEvent.countToEnd : originalEvent.countToEnd,
|
||||
|
||||
@@ -2,12 +2,16 @@ import type { MaybeString } from 'ontime-types';
|
||||
import { EndAction, TimerType, TimeStrategy } from 'ontime-types';
|
||||
|
||||
/**
|
||||
* Check if a given value is a valid type of string, returns null otherwise
|
||||
* Check if a given value is a valid type linkStart, returns the fallback otherwise
|
||||
* linkStart can be a string (id of an event to link) or null (unlinked)
|
||||
* @param {MaybeString} maybeLinkStart
|
||||
* @returns {MaybeString}
|
||||
*/
|
||||
export function validateLinkStart(maybeLinkStart: unknown): MaybeString {
|
||||
return typeof maybeLinkStart === 'string' ? maybeLinkStart : null;
|
||||
export function validateLinkStart(maybeLinkStart: unknown, fallback: MaybeString = null): MaybeString {
|
||||
if (typeof maybeLinkStart === 'string' || maybeLinkStart === null) {
|
||||
return maybeLinkStart as MaybeString;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user