* move dailyApiFetcher.ts to app store package * update imports * bookingLocationService * revert * move findFieldValueByIdentifier * wip * fix * fix * fix * fix * fix * fix * fix * move to features package * update imports * update imports * move * fix typechecks * move getCalendarLinks * mv event test
21 lines
709 B
TypeScript
21 lines
709 B
TypeScript
import getFieldIdentifier from "./getFieldIdentifier";
|
|
import type { RoutingFormResponseData } from "./responseData/types";
|
|
|
|
type FindFieldValueByIdentifierResult =
|
|
| { success: true; data: string | string[] | number | null }
|
|
| { success: false; error: string };
|
|
|
|
export function findFieldValueByIdentifier(
|
|
data: RoutingFormResponseData,
|
|
identifier: string
|
|
): FindFieldValueByIdentifierResult {
|
|
const field = data.fields.find((field) => getFieldIdentifier(field) === identifier);
|
|
if (!field) {
|
|
return { success: false, error: `Field with identifier ${identifier} not found` };
|
|
}
|
|
|
|
const fieldValue = data.response[field.id]?.value;
|
|
|
|
return { success: true, data: fieldValue ?? null };
|
|
}
|