-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(frontend): split services into their respective domains (#304)
- Loading branch information
1 parent
69714de
commit a849698
Showing
20 changed files
with
777 additions
and
750 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
export type ApplicantGender = Readonly<{ | ||
id: string; | ||
nameEn: string | null; | ||
nameFr: string | null; | ||
}>; | ||
|
||
export type LocalizedApplicantGender = Readonly<{ | ||
id: string; | ||
name: string | null; | ||
}>; | ||
|
||
export type ApplicantPrimaryDocumentChoice = Readonly<{ | ||
id: string; | ||
nameEn: string | null; | ||
nameFr: string | null; | ||
}>; | ||
|
||
export type LocalizedApplicantPrimaryDocumentChoice = Readonly<{ | ||
id: string; | ||
name: string | null; | ||
}>; | ||
|
||
export type ApplicantSecondaryDocumentChoice = Readonly<{ | ||
id: string; | ||
nameEn: string | null; | ||
nameFr: string | null; | ||
}>; | ||
|
||
export type LocalizedApplicantSecondaryDocumentChoice = Readonly<{ | ||
id: string; | ||
name: string | null; | ||
}>; | ||
|
||
export type ApplicantHadSinOption = Readonly<{ | ||
id: string; | ||
nameEn: string | null; | ||
nameFr: string | null; | ||
}>; | ||
|
||
export type LocalizedApplicantHadSinOption = Readonly<{ | ||
id: string; | ||
name: string | null; | ||
}>; | ||
|
||
export type ApplicationSubmissionScenario = Readonly<{ | ||
id: string; | ||
nameEn: string | null; | ||
nameFr: string | null; | ||
}>; | ||
|
||
export type LocalizedApplicationSubmissionScenario = Readonly<{ | ||
id: string; | ||
name: string | null; | ||
}>; | ||
|
||
export type TypeOfApplicationToSubmit = Readonly<{ | ||
id: string; | ||
nameEn: string | null; | ||
nameFr: string | null; | ||
}>; | ||
|
||
export type LocalizedTypeOfApplicationToSubmit = Readonly<{ | ||
id: string; | ||
name: string | null; | ||
}>; | ||
|
||
export type LanguageOfCorrespondence = Readonly<{ | ||
id: string; | ||
nameEn: string | null; | ||
nameFr: string | null; | ||
}>; | ||
|
||
export type LocalizedPreferredLanguage = Readonly<{ | ||
id: string; | ||
name: string | null; | ||
}>; |
62 changes: 62 additions & 0 deletions
62
frontend/app/.server/domain/person-case/services/applicant-gender-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import type { ApplicantGender, LocalizedApplicantGender } from '~/.server/domain/person-case/models'; | ||
import { getOptionSet } from '~/.server/domain/person-case/services/data-service'; | ||
import { AppError } from '~/errors/app-error'; | ||
import { ErrorCodes } from '~/errors/error-codes'; | ||
|
||
/** | ||
* Retrieves a list of applicant genders. | ||
* | ||
* @returns An array of applicant gender objects. | ||
*/ | ||
export function getApplicantGenders(): readonly ApplicantGender[] { | ||
const optionSet = getOptionSet('esdc_applicantgender'); | ||
return optionSet.options.map((option) => ({ | ||
id: option.value.toString(), | ||
nameEn: option.labelEn, | ||
nameFr: option.labelFr, | ||
})); | ||
} | ||
|
||
/** | ||
* Retrieves a single applicant gender by its ID. | ||
* | ||
* @param id The ID of the applicant gender to retrieve. | ||
* @returns The applicant gender object if found. | ||
* @throws {AppError} If the applicant gender is not found. | ||
*/ | ||
export function getApplicantGenderById(id: string): ApplicantGender { | ||
const gender = getApplicantGenders().find((g) => g.id === id); | ||
if (!gender) { | ||
throw new AppError(`Applicant gender with ID '${id}' not found.`, ErrorCodes.NO_GENDER_FOUND); | ||
} | ||
return gender; | ||
} | ||
|
||
/** | ||
* Retrieves a list of applicant genders localized to the specified language. | ||
* | ||
* @param language The language to localize the gender names to. | ||
* @returns An array of localized applicant gender objects. | ||
*/ | ||
export function getLocalizedApplicantGenders(language: Language): LocalizedApplicantGender[] { | ||
return getApplicantGenders().map((option) => ({ | ||
id: option.id, | ||
name: language === 'fr' ? option.nameFr : option.nameEn, | ||
})); | ||
} | ||
|
||
/** | ||
* Retrieves a single localized applicant gender by its ID. | ||
* | ||
* @param id The ID of the applicant gender to retrieve. | ||
* @param language The language to localize the gender name to. | ||
* @returns The localized applicant gender object if found. | ||
* @throws {AppError} If the applicant gender is not found. | ||
*/ | ||
export function getLocalizedApplicantGenderById(id: string, language: Language): LocalizedApplicantGender { | ||
const gender = getLocalizedApplicantGenders(language).find((g) => g.id === id); | ||
if (!gender) { | ||
throw new AppError(`Localized applicant gender with ID '${id}' not found.`, ErrorCodes.NO_GENDER_FOUND); | ||
} | ||
return gender; | ||
} |
74 changes: 74 additions & 0 deletions
74
frontend/app/.server/domain/person-case/services/applicant-primary-document-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import type { | ||
ApplicantPrimaryDocumentChoice, | ||
LocalizedApplicantPrimaryDocumentChoice, | ||
} from '~/.server/domain/person-case/models'; | ||
import { getOptionSet } from '~/.server/domain/person-case/services/data-service'; | ||
import { AppError } from '~/errors/app-error'; | ||
import { ErrorCodes } from '~/errors/error-codes'; | ||
|
||
/** | ||
* Retrieves a list of applicant primary document choices. | ||
* | ||
* @returns An array of applicant primary document choice objects. | ||
*/ | ||
export function getApplicantPrimaryDocumentChoices(): readonly ApplicantPrimaryDocumentChoice[] { | ||
const optionSet = getOptionSet('esdc_applicantprimarydocumentchoices'); | ||
return optionSet.options.map((option) => ({ | ||
id: option.value.toString(), | ||
nameEn: option.labelEn, | ||
nameFr: option.labelFr, | ||
})); | ||
} | ||
|
||
/** | ||
* Retrieves a single applicant primary document choice by its ID. | ||
* | ||
* @param id The ID of the applicant primary document choice to retrieve. | ||
* @returns The applicant primary document choice object if found. | ||
* @throws {AppError} If the choice is not found. | ||
*/ | ||
export function getApplicantPrimaryDocumentChoiceById(id: string): ApplicantPrimaryDocumentChoice { | ||
const choice = getApplicantPrimaryDocumentChoices().find((c) => c.id === id); | ||
if (!choice) { | ||
throw new AppError( | ||
`Applicant primary document choice with ID '${id}' not found.`, | ||
ErrorCodes.NO_APPLICANT_PRIMARY_DOCUMENT_CHOICE_FOUND, | ||
); | ||
} | ||
return choice; | ||
} | ||
|
||
/** | ||
* Retrieves a list of applicant primary document choices localized to the specified language. | ||
* | ||
* @param language The language to localize the choice names to. | ||
* @returns An array of localized applicant primary document choice objects. | ||
*/ | ||
export function getLocalizedApplicantPrimaryDocumentChoices(language: Language): LocalizedApplicantPrimaryDocumentChoice[] { | ||
return getApplicantPrimaryDocumentChoices().map((option) => ({ | ||
id: option.id, | ||
name: language === 'fr' ? option.nameFr : option.nameEn, | ||
})); | ||
} | ||
|
||
/** | ||
* Retrieves a single localized applicant primary document choice by its ID. | ||
* | ||
* @param id The ID of the applicant primary document choice to retrieve. | ||
* @param language The language to localize the choice name to. | ||
* @returns The localized applicant primary document choice object if found. | ||
* @throws {AppError} If the choice is not found. | ||
*/ | ||
export function getLocalizedApplicantPrimaryDocumentChoiceById( | ||
id: string, | ||
language: Language, | ||
): LocalizedApplicantPrimaryDocumentChoice { | ||
const choice = getLocalizedApplicantPrimaryDocumentChoices(language).find((c) => c.id === id); | ||
if (!choice) { | ||
throw new AppError( | ||
`Localized applicant primary document choice with ID '${id}' not found.`, | ||
ErrorCodes.NO_APPLICANT_PRIMARY_DOCUMENT_CHOICE_FOUND, | ||
); | ||
} | ||
return choice; | ||
} |
74 changes: 74 additions & 0 deletions
74
frontend/app/.server/domain/person-case/services/applicant-secondary-document-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import type { | ||
ApplicantSecondaryDocumentChoice, | ||
LocalizedApplicantSecondaryDocumentChoice, | ||
} from '~/.server/domain/person-case/models'; | ||
import { getOptionSet } from '~/.server/domain/person-case/services/data-service'; | ||
import { AppError } from '~/errors/app-error'; | ||
import { ErrorCodes } from '~/errors/error-codes'; | ||
|
||
/** | ||
* Retrieves a list of applicant secondary document choices. | ||
* | ||
* @returns An array of applicant secondary document choice objects. | ||
*/ | ||
export function getApplicantSecondaryDocumentChoices(): readonly ApplicantSecondaryDocumentChoice[] { | ||
const optionSet = getOptionSet('esdc_applicantsecondarydocumentchoices'); | ||
return optionSet.options.map((option) => ({ | ||
id: option.value.toString(), | ||
nameEn: option.labelEn, | ||
nameFr: option.labelFr, | ||
})); | ||
} | ||
|
||
/** | ||
* Retrieves a single applicant secondary document choice by its ID. | ||
* | ||
* @param id The ID of the applicant secondary document choice to retrieve. | ||
* @returns The applicant secondary document choice object if found. | ||
* @throws {AppError} If the choice is not found. | ||
*/ | ||
export function getApplicantSecondaryDocumentChoiceById(id: string): ApplicantSecondaryDocumentChoice { | ||
const choice = getApplicantSecondaryDocumentChoices().find((c) => c.id === id); | ||
if (!choice) { | ||
throw new AppError( | ||
`Applicant secondary document choice with ID '${id}' not found.`, | ||
ErrorCodes.NO_APPLICANT_SECONDARY_DOCUMENT_CHOICE_FOUND, | ||
); | ||
} | ||
return choice; | ||
} | ||
|
||
/** | ||
* Retrieves a list of applicant secondary document choices localized to the specified language. | ||
* | ||
* @param language The language to localize the choice names to. | ||
* @returns An array of localized applicant secondary document choice objects. | ||
*/ | ||
export function getLocalizedApplicantSecondaryDocumentChoices(language: Language): LocalizedApplicantSecondaryDocumentChoice[] { | ||
return getApplicantSecondaryDocumentChoices().map((option) => ({ | ||
id: option.id, | ||
name: language === 'fr' ? option.nameFr : option.nameEn, | ||
})); | ||
} | ||
|
||
/** | ||
* Retrieves a single localized applicant secondary document choice by its ID. | ||
* | ||
* @param id The ID of the applicant secondary document choice to retrieve. | ||
* @param language The language to localize the choice name to. | ||
* @returns The localized applicant secondary document choice object if found. | ||
* @throws {AppError} If the choice is not found. | ||
*/ | ||
export function getLocalizedApplicantSecondaryDocumentChoiceById( | ||
id: string, | ||
language: Language, | ||
): LocalizedApplicantSecondaryDocumentChoice { | ||
const choice = getLocalizedApplicantSecondaryDocumentChoices(language).find((c) => c.id === id); | ||
if (!choice) { | ||
throw new AppError( | ||
`Localized applicant secondary document choice with ID '${id}' not found.`, | ||
ErrorCodes.NO_APPLICANT_SECONDARY_DOCUMENT_CHOICE_FOUND, | ||
); | ||
} | ||
return choice; | ||
} |
65 changes: 65 additions & 0 deletions
65
frontend/app/.server/domain/person-case/services/applicant-sin-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import type { ApplicantHadSinOption, LocalizedApplicantHadSinOption } from '~/.server/domain/person-case/models'; | ||
import { getOptionSet } from '~/.server/domain/person-case/services/data-service'; | ||
import { AppError } from '~/errors/app-error'; | ||
import { ErrorCodes } from '~/errors/error-codes'; | ||
|
||
/** | ||
* Retrieves a list of applicant had SIN options. | ||
* | ||
* @returns An array of applicant had SIN option objects. | ||
*/ | ||
export function getApplicantHadSinOptions(): readonly ApplicantHadSinOption[] { | ||
const optionSet = getOptionSet('esdc_didtheapplicanteverhadasinnumber'); | ||
return optionSet.options.map((option) => ({ | ||
id: option.value.toString(), | ||
nameEn: option.labelEn, | ||
nameFr: option.labelFr, | ||
})); | ||
} | ||
|
||
/** | ||
* Retrieves a single applicant had SIN option by its ID. | ||
* | ||
* @param id The ID of the applicant had SIN option to retrieve. | ||
* @returns The applicant had SIN option object if found. | ||
* @throws {AppError} If the option is not found. | ||
*/ | ||
export function getApplicantHadSinOptionById(id: string): ApplicantHadSinOption { | ||
const option = getApplicantHadSinOptions().find((o) => o.id === id); | ||
if (!option) { | ||
throw new AppError(`Applicant had SIN option with ID '${id}' not found.`, ErrorCodes.NO_APPLICANT_HAD_SIN_OPTION_FOUND); | ||
} | ||
return option; | ||
} | ||
|
||
/** | ||
* Retrieves a list of applicant had SIN options localized to the specified language. | ||
* | ||
* @param language The language to localize the option names to. | ||
* @returns An array of localized applicant had SIN option objects. | ||
*/ | ||
export function getLocalizedApplicantHadSinOptions(language: Language): LocalizedApplicantHadSinOption[] { | ||
return getApplicantHadSinOptions().map((option) => ({ | ||
id: option.id, | ||
name: language === 'fr' ? option.nameFr : option.nameEn, | ||
})); | ||
} | ||
|
||
/** | ||
* Retrieves a single localized applicant had SIN option by its ID. | ||
* | ||
* @param id The ID of the applicant had SIN option to retrieve. | ||
* @param language The language to localize the option name to. | ||
* @returns The localized applicant had SIN option object if found. | ||
* @throws {AppError} If the option is not found. | ||
*/ | ||
export function getLocalizedApplicantHadSinOptionById(id: string, language: Language): LocalizedApplicantHadSinOption { | ||
const option = getLocalizedApplicantHadSinOptions(language).find((o) => o.id === id); | ||
if (!option) { | ||
throw new AppError( | ||
`Localized applicant had SIN option with ID '${id}' not found.`, | ||
ErrorCodes.NO_APPLICANT_HAD_SIN_OPTION_FOUND, | ||
); | ||
} | ||
return option; | ||
} |
Oops, something went wrong.