owltide/utils/functions.ts
Hornwitser ce9f758f84 Implement editing of slots in ClientSchedule
Implement tracking of time slots along with editing and restoration of
singularly edited time slots.  This provides a simpler interface to work
with when rendering tables of time slots that can be edited than
directly manipulating events and shifts containing an array of slots.
2025-06-14 19:12:31 +02:00

22 lines
677 B
TypeScript

import type { LocationQueryValue } from 'vue-router';
import type { Id } from '~/shared/types/common';
export function queryToString(item?: null | LocationQueryValue | LocationQueryValue[]) {
if (item === null)
return "";
if (item instanceof Array)
return queryToString(item[0])
return item;
}
export function queryToNumber(item?: null | LocationQueryValue | LocationQueryValue[]) {
if (item === null || item === undefined)
return undefined;
if (item instanceof Array)
return queryToNumber(item[0])
return Number.parseInt(item, 10);
}
export function idMap<T extends { id: Id }>(entities: T[]) {
return new Map(entities.map(entity => [entity.id, entity]));
}