|
| 1 | +import type { |
| 2 | + ApplicantStatusInCanadaChoice, |
| 3 | + LocalizedApplicantStatusInCanadaChoice, |
| 4 | +} from '~/.server/domain/person-case/models'; |
| 5 | +import esdcApplicantStatusInCanadaChoicesData from '~/.server/resources/esdc_applicantstatusincanada.json'; |
| 6 | +import { AppError } from '~/errors/app-error'; |
| 7 | +import { ErrorCodes } from '~/errors/error-codes'; |
| 8 | + |
| 9 | +/** |
| 10 | + * Retrieves a list of applicant status in Canada choices. |
| 11 | + * |
| 12 | + * @returns An array of applicant status in Canada choice objects. |
| 13 | + */ |
| 14 | +export function getApplicantStatusInCanadaChoices(): readonly ApplicantStatusInCanadaChoice[] { |
| 15 | + return esdcApplicantStatusInCanadaChoicesData.options.map((option) => ({ |
| 16 | + id: option.value.toString(), |
| 17 | + nameEn: option.labelEn, |
| 18 | + nameFr: option.labelFr, |
| 19 | + })); |
| 20 | +} |
| 21 | + |
| 22 | +/** |
| 23 | + * Retrieves a single applicant status in Canada choice by its ID. |
| 24 | + * |
| 25 | + * @param id The ID of the applicant status in Canada choice to retrieve. |
| 26 | + * @returns Theapplicant status in Canada choice object if found. |
| 27 | + * @throws {AppError} If the choice is not found. |
| 28 | + */ |
| 29 | +export function getApplicantStatusInCanadaChoicesById(id: string): ApplicantStatusInCanadaChoice { |
| 30 | + const scenario = getApplicantStatusInCanadaChoices().find((s) => s.id === id); |
| 31 | + if (!scenario) { |
| 32 | + throw new AppError( |
| 33 | + `Application status in Canada with ID '${id}' not found.`, |
| 34 | + ErrorCodes.NO_APPLICANT_STATUS_IN_CANADA_CHOICE_FOUND, |
| 35 | + ); |
| 36 | + } |
| 37 | + return scenario; |
| 38 | +} |
| 39 | + |
| 40 | +/** |
| 41 | + * Retrieves a list of applicant status in Canada choices localized to the specified language. |
| 42 | + * |
| 43 | + * @param language The language to localize the scenario names to. |
| 44 | + * @returns An array of localized applicant status in Canada choice objects. |
| 45 | + */ |
| 46 | +export function getLocalizedApplicantStatusInCanadaChoices(language: Language): LocalizedApplicantStatusInCanadaChoice[] { |
| 47 | + return getApplicantStatusInCanadaChoices().map((option) => ({ |
| 48 | + id: option.id, |
| 49 | + name: language === 'fr' ? option.nameFr : option.nameEn, |
| 50 | + })); |
| 51 | +} |
| 52 | + |
| 53 | +/** |
| 54 | + * Retrieves a single localized applicant status in Canada choice by its ID. |
| 55 | + * |
| 56 | + * @param id The ID of the applicant status in Canada choice to retrieve. |
| 57 | + * @param language The language to localize the choice name to. |
| 58 | + * @returns The localized applicant status in Canada choice object if found. |
| 59 | + * @throws {AppError} If the choice is not found. |
| 60 | + */ |
| 61 | +export function getLocalizedApplicantStatusInCanadaChoiceById( |
| 62 | + id: string, |
| 63 | + language: Language, |
| 64 | +): LocalizedApplicantStatusInCanadaChoice { |
| 65 | + const scenario = getLocalizedApplicantStatusInCanadaChoices(language).find((s) => s.id === id); |
| 66 | + if (!scenario) { |
| 67 | + throw new AppError( |
| 68 | + `Localized applicant status in Canada choice with ID '${id}' not found.`, |
| 69 | + ErrorCodes.NO_APPLICANT_STATUS_IN_CANADA_CHOICE_FOUND, |
| 70 | + ); |
| 71 | + } |
| 72 | + return scenario; |
| 73 | +} |
0 commit comments