Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validateLinkStart #1430

Merged
merged 5 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/server/src/utils/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions packages/utils/src/validate-events/validateEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ 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 of string, returns the fallback otherwise
* @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;
}

/**
Expand Down
Loading