2022-04-23 21:29:35 +02:00
|
|
|
import { CustomError, errorCodes } from "../interfaces";
|
2022-04-13 21:38:59 +02:00
|
|
|
import { scheduleNames, supportedSchedule } from "../types/scheduledEventTypes";
|
|
|
|
|
|
|
|
export function findInScheduleTypes(inputString: string): supportedSchedule {
|
|
|
|
const maybeScheduleName: unknown = JSON.parse(`"${inputString.toLowerCase()}"`);
|
|
|
|
const scheduleName = scheduleNames.find((validName: supportedSchedule) => validName === maybeScheduleName);
|
|
|
|
if (scheduleName) {
|
|
|
|
// `sheepName` comes from the list of `sheepNames` so the compiler is happy.
|
|
|
|
return scheduleName;
|
|
|
|
}
|
2022-04-23 21:29:35 +02:00
|
|
|
throw new CustomError('That is not a schedule name.', errorCodes.schedule_not_supported);
|
2022-04-13 21:38:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|