Skip to content

Commit a34d7e0

Browse files
add service for esdc_applicantstatusincanada
1 parent b2cb791 commit a34d7e0

File tree

4 files changed

+87
-1
lines changed

4 files changed

+87
-1
lines changed

frontend/app/.server/domain/person-case/models.ts

+11
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,14 @@ export type LocalizedPreferredLanguage = Readonly<{
7474
id: string;
7575
name: string;
7676
}>;
77+
78+
export type ApplicantStatusInCanadaChoice = Readonly<{
79+
id: string;
80+
nameEn: string;
81+
nameFr: string;
82+
}>;
83+
84+
export type LocalizedApplicantStatusInCanadaChoice = Readonly<{
85+
id: string;
86+
name: string;
87+
}>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
}

frontend/app/.server/domain/person-case/services/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * as applicationSubmissionScenario from './application-submission-scenari
66
export * as applicationTypeService from './application-type-service';
77
export * as languageCorrespondenceService from './language-correspondence-service';
88
export * as sinApplicationService from './sin-application-service';
9+
export * as applicantStatusInCanadaService from './applicant-status-in-canada-service';

frontend/app/errors/error-codes.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ export const ErrorCodes = {
4747
NO_PROVINCE_FOUND: 'SVC-0008',
4848
NO_TYPE_OF_APPLICATION_TO_SUBMIT_FOUND: 'SVC-0009',
4949
NO_LANGUAGE_OF_CORRESPONDENCE_FOUND: 'SVC-0010',
50-
SUBMIT_SIN_APPLICATION_FAILED: 'SVC-0011',
50+
NO_APPLICANT_STATUS_IN_CANADA_CHOICE_FOUND: 'SVC-00011',
51+
SUBMIT_SIN_APPLICATION_FAILED: 'SVC-0012',
5152
} as const;

0 commit comments

Comments
 (0)