From eb608f520e6febf09e029492fbfaa3dbb764a8b1 Mon Sep 17 00:00:00 2001 From: Eric McGarry <46828798+mcgarrye@users.noreply.github.com> Date: Tue, 29 Oct 2024 14:06:24 -0400 Subject: [PATCH 1/2] feat: correction script for sparks homes application preferences (#795) * feat: preference correction script * feat: add test * feat: comment improvements --- .../controllers/script-runner.controller.ts | 15 ++++ api/src/services/script-runner.service.ts | 71 +++++++++++++++ .../services/script-runner.service.spec.ts | 65 ++++++++++++++ shared-helpers/src/types/backend-swagger.ts | 89 ++++++++++++++----- 4 files changed, 218 insertions(+), 22 deletions(-) diff --git a/api/src/controllers/script-runner.controller.ts b/api/src/controllers/script-runner.controller.ts index 03e3292cd8..9f706268b6 100644 --- a/api/src/controllers/script-runner.controller.ts +++ b/api/src/controllers/script-runner.controller.ts @@ -152,4 +152,19 @@ export class ScirptRunnerController { ): Promise { return await this.scriptRunnerService.updateCodeExpirationTranslations(req); } + + @Put('correctApplicationPreferenceDataForSparksHomes') + @ApiOperation({ + summary: + 'A script that updates the preference keys for applications on Spark Homes', + operationId: 'correctApplicationPreferenceDataForSparksHomes', + }) + @ApiOkResponse({ type: SuccessDTO }) + async correctApplicationPreferenceDataForSparksHomes( + @Request() req: ExpressRequest, + ): Promise { + return await this.scriptRunnerService.correctApplicationPreferenceDataForSparksHomes( + req, + ); + } } diff --git a/api/src/services/script-runner.service.ts b/api/src/services/script-runner.service.ts index 18ad754539..6ef338fae4 100644 --- a/api/src/services/script-runner.service.ts +++ b/api/src/services/script-runner.service.ts @@ -502,6 +502,77 @@ export class ScriptRunnerService { return { success: true }; } + /** + * @param req incoming request object + * @returns successDTO + * @description updates the preference keys for applications on Spark Homes + */ + async correctApplicationPreferenceDataForSparksHomes( + req: ExpressRequest, + ): Promise { + // script runner standard start up + const requestingUser = mapTo(User, req['user']); + await this.markScriptAsRunStart( + 'Correct application preference data for Sparks Homes', + requestingUser, + ); + + const applications = await this.prisma.applications.findMany({ + select: { + id: true, + preferences: true, + }, + where: { listingId: 'a055ce66-a074-4f3a-b67b-6776bec9926e' }, + }); + + const options = [ + { + original: 'Live in %{county} County Preference', + new: 'Live in the City of Hayward', + }, + { + original: 'Work in %{county} County Preference', + new: 'Work in the City of Hayward', + }, + ]; + + console.log(`Updating ${applications.length} applications`); + for (const applicaiton of applications) { + const blob = applicaiton.preferences; + + const preference = blob[0]; + + preference.options = preference.options.map((option) => { + if (option.key === options[0].original) { + return { + ...option, + key: options[0].new, + }; + } else if (option.key === options[1].original) { + return { + ...option, + key: options[1].new, + }; + } + }); + + await this.prisma.applications.update({ + data: { + preferences: [preference] as unknown as Prisma.JsonArray, + }, + where: { + id: applicaiton.id, + }, + }); + } + + await this.markScriptAsComplete( + 'Correct application preference data for Sparks Homes', + requestingUser, + ); + return { success: true }; + } + /** this is simply an example */ diff --git a/api/test/unit/services/script-runner.service.spec.ts b/api/test/unit/services/script-runner.service.spec.ts index f25578bd00..fe68b8f634 100644 --- a/api/test/unit/services/script-runner.service.spec.ts +++ b/api/test/unit/services/script-runner.service.spec.ts @@ -474,6 +474,71 @@ describe('Testing script runner service', () => { }); }); + it('should correct application preference data for sparks home', async () => { + const id = randomUUID(); + prisma.scriptRuns.findUnique = jest.fn().mockResolvedValue(null); + prisma.scriptRuns.create = jest.fn().mockResolvedValue(null); + prisma.scriptRuns.update = jest.fn().mockResolvedValue(null); + prisma.applications.findMany = jest.fn().mockResolvedValue([ + { + id: id, + preferences: [ + { + options: [ + { key: 'Live in %{county} County Preference' }, + { key: 'Work in %{county} County Preference' }, + ], + }, + ], + }, + ]); + prisma.applications.update = jest.fn().mockResolvedValue(null); + + const scriptName = 'Correct application preference data for Sparks Homes'; + const res = await service.correctApplicationPreferenceDataForSparksHomes({ + user: { + id, + userRoles: { isAdmin: true }, + } as unknown as User, + } as unknown as ExpressRequest); + expect(res.success).toEqual(true); + expect(prisma.scriptRuns.findUnique).toHaveBeenCalledWith({ + where: { + scriptName, + }, + }); + expect(prisma.scriptRuns.create).toHaveBeenCalledWith({ + data: { + scriptName, + triggeringUser: id, + }, + }); + expect(prisma.scriptRuns.update).toHaveBeenCalledWith({ + data: { + didScriptRun: true, + triggeringUser: id, + }, + where: { + scriptName, + }, + }); + expect(prisma.applications.update).toHaveBeenCalledWith({ + data: { + preferences: [ + { + options: [ + { key: 'Live in the City of Hayward' }, + { key: 'Work in the City of Hayward' }, + ], + }, + ], + }, + where: { + id, + }, + }); + }); + it('should transfer data', async () => { prisma.listings.updateMany = jest.fn().mockResolvedValue({ count: 1 }); diff --git a/shared-helpers/src/types/backend-swagger.ts b/shared-helpers/src/types/backend-swagger.ts index 7d45c39052..626948e0d7 100644 --- a/shared-helpers/src/types/backend-swagger.ts +++ b/shared-helpers/src/types/backend-swagger.ts @@ -2167,28 +2167,6 @@ export class ScriptRunnerService { axios(configs, resolve, reject) }) } - /** - * A script that creates a new reserved community type - */ - createNewReservedCommunityType( - params: { - /** requestBody */ - body?: IdDTO - } = {} as any, - options: IRequestOptions = {} - ): Promise { - return new Promise((resolve, reject) => { - let url = basePath + "/scriptRunner/createNewReservedCommunityType" - - const configs: IRequestConfig = getConfigs("put", "application/json", url, options) - - let data = params.body - - configs.data = data - - axios(configs, resolve, reject) - }) - } /** * A script that takes in a standardized string and outputs the input for the ami chart create endpoint */ @@ -2256,6 +2234,62 @@ export class ScriptRunnerService { configs.data = data + axios(configs, resolve, reject) + }) + } + /** + * A script that creates a new reserved community type + */ + createNewReservedCommunityType( + params: { + /** requestBody */ + body?: CommunityTypeDTO + } = {} as any, + options: IRequestOptions = {} + ): Promise { + return new Promise((resolve, reject) => { + let url = basePath + "/scriptRunner/createNewReservedCommunityType" + + const configs: IRequestConfig = getConfigs("put", "application/json", url, options) + + let data = params.body + + configs.data = data + + axios(configs, resolve, reject) + }) + } + /** + * A script that updates single use code translations to show extended expiration time + */ + updateCodeExpirationTranslations(options: IRequestOptions = {}): Promise { + return new Promise((resolve, reject) => { + let url = basePath + "/scriptRunner/updateCodeExpirationTranslations" + + const configs: IRequestConfig = getConfigs("put", "application/json", url, options) + + let data = null + + configs.data = data + + axios(configs, resolve, reject) + }) + } + /** + * A script that updates the preference keys for applications on Spark Homes + */ + correctApplicationPreferenceDataForSparksHomes( + options: IRequestOptions = {} + ): Promise { + return new Promise((resolve, reject) => { + let url = basePath + "/scriptRunner/correctApplicationPreferenceDataForSparksHomes" + + const configs: IRequestConfig = getConfigs("put", "application/json", url, options) + + let data = null + + configs.data = data + axios(configs, resolve, reject) }) } @@ -5857,6 +5891,17 @@ export interface AmiChartImportDTO { jurisdictionId: string } +export interface CommunityTypeDTO { + /** */ + id: string + + /** */ + name: string + + /** */ + description?: string +} + export interface ApplicationCsvQueryParams { /** */ id: string From d0e639fee173471a15e12be8d3a221ddf7c8c52d Mon Sep 17 00:00:00 2001 From: Eric McGarry <46828798+mcgarrye@users.noreply.github.com> Date: Wed, 30 Oct 2024 11:16:59 -0400 Subject: [PATCH 2/2] feat: add farmworkerHousing and update other translations (#4415) (#793) --- api/src/dtos/script-runner/community-type.dto.ts | 15 ++++++++++++--- shared-helpers/src/locales/es.json | 8 +++++--- shared-helpers/src/locales/general.json | 8 +++++--- shared-helpers/src/locales/tl.json | 8 +++++--- shared-helpers/src/locales/vi.json | 6 ++++-- shared-helpers/src/locales/zh.json | 12 +++++++----- shared-helpers/src/types/backend-swagger.ts | 1 + 7 files changed, 39 insertions(+), 19 deletions(-) diff --git a/api/src/dtos/script-runner/community-type.dto.ts b/api/src/dtos/script-runner/community-type.dto.ts index d808dde2aa..e9f7c0f7d2 100644 --- a/api/src/dtos/script-runner/community-type.dto.ts +++ b/api/src/dtos/script-runner/community-type.dto.ts @@ -8,16 +8,25 @@ export class CommunityTypeDTO { @IsString({ groups: [ValidationsGroupsEnum.default] }) @IsUUID(4, { groups: [ValidationsGroupsEnum.default] }) @IsDefined({ groups: [ValidationsGroupsEnum.default] }) - @ApiProperty() + @ApiProperty({ + type: String, + example: 'jurisdiction id', + }) id: string; @Expose() @IsString({ groups: [ValidationsGroupsEnum.default] }) - @ApiProperty() + @ApiProperty({ + type: String, + example: 'newReservedCommunityName', + }) name: string; @Expose() @IsString({ groups: [ValidationsGroupsEnum.default] }) - @ApiPropertyOptional() + @ApiPropertyOptional({ + type: String, + example: 'Description of reserved community type', + }) description?: string; } diff --git a/shared-helpers/src/locales/es.json b/shared-helpers/src/locales/es.json index 8abb408054..08016febcb 100644 --- a/shared-helpers/src/locales/es.json +++ b/shared-helpers/src/locales/es.json @@ -665,14 +665,16 @@ "listings.reservedCommunityTitleDefault": "Edificio Reservado", "listings.reservedCommunityType": "Tipo de comunidad reservada", "listings.reservedCommunityTypeDescriptions.developmentalDisability": "Personas con discapacidades del desarrollo", - "listings.reservedCommunityTypeDescriptions.housingVoucher": "el titular del vale de HCV / Sección 8", + "listings.reservedCommunityTypeDescriptions.farmworkerHousing": "Trabajadores agrícolas y sus familias", + "listings.reservedCommunityTypeDescriptions.housingVoucher": "Titulares de vales HCV / Sección 8", "listings.reservedCommunityTypeDescriptions.senior": "Personas mayores", "listings.reservedCommunityTypeDescriptions.senior55": "Personas mayores de 55 años", "listings.reservedCommunityTypeDescriptions.senior62": "Personas mayores de 62 años", "listings.reservedCommunityTypeDescriptions.specialNeeds": "Necesidades especiales", - "listings.reservedCommunityTypeDescriptions.veteran": "Veterano", - "listings.reservedCommunityTypeDescriptions.schoolEmployee": "Empleado de la escuela", + "listings.reservedCommunityTypeDescriptions.veteran": "Veteranos", + "listings.reservedCommunityTypeDescriptions.schoolEmployee": "Empleados de la escuela", "listings.reservedCommunityTypes.developmentalDisability": "La discapacidad del desarrollo", + "listings.reservedCommunityTypes.farmworkerHousing": "Vivienda para trabajadores agrícolas", "listings.reservedCommunityTypes.housingVoucher": "Vale HCV/Sección 8", "listings.reservedCommunityTypes.senior": "Personas mayores", "listings.reservedCommunityTypes.senior55": "Personas mayores de 55 años", diff --git a/shared-helpers/src/locales/general.json b/shared-helpers/src/locales/general.json index b6a2258274..62dcdf210b 100644 --- a/shared-helpers/src/locales/general.json +++ b/shared-helpers/src/locales/general.json @@ -656,14 +656,16 @@ "listings.reservedCommunityTitleDefault": "Reserved Building", "listings.reservedCommunityType": "Reserved Community Type", "listings.reservedCommunityTypeDescriptions.developmentalDisability": "People with Developmental Disabilities", - "listings.reservedCommunityTypeDescriptions.housingVoucher": "HCV/Section 8 Voucher Holder", + "listings.reservedCommunityTypeDescriptions.farmworkerHousing": "Farmworkers and Their Families", + "listings.reservedCommunityTypeDescriptions.housingVoucher": "HCV/Section 8 Voucher Holders", "listings.reservedCommunityTypeDescriptions.senior": "Seniors", "listings.reservedCommunityTypeDescriptions.senior55": "Seniors 55+", "listings.reservedCommunityTypeDescriptions.senior62": "Seniors 62+", "listings.reservedCommunityTypeDescriptions.specialNeeds": "Special Needs", - "listings.reservedCommunityTypeDescriptions.veteran": "Veteran", - "listings.reservedCommunityTypeDescriptions.schoolEmployee": "School Employee", + "listings.reservedCommunityTypeDescriptions.veteran": "Veterans", + "listings.reservedCommunityTypeDescriptions.schoolEmployee": "School Employees", "listings.reservedCommunityTypes.developmentalDisability": "Developmental Disability", + "listings.reservedCommunityTypes.farmworkerHousing": "Farmworker Housing", "listings.reservedCommunityTypes.housingVoucher": "HCV/Section 8 Voucher", "listings.reservedCommunityTypes.senior": "Seniors", "listings.reservedCommunityTypes.senior55": "Seniors 55+", diff --git a/shared-helpers/src/locales/tl.json b/shared-helpers/src/locales/tl.json index 74d0edb73a..262496d06c 100644 --- a/shared-helpers/src/locales/tl.json +++ b/shared-helpers/src/locales/tl.json @@ -664,14 +664,16 @@ "listings.reservedCommunityTitleDefault": "Nakareserbang Gusali", "listings.reservedCommunityType": "Nakareserbang Uri ng Komunidad", "listings.reservedCommunityTypeDescriptions.developmentalDisability": "Mga taong may Kapansanan sa Pag-unlad", - "listings.reservedCommunityTypeDescriptions.housingVoucher": "May-hawak ng Voucher ng HCV/Seksyon 8", + "listings.reservedCommunityTypeDescriptions.farmworkerHousing": "Mga Manggagawa sa Bukid at Kanilang Pamilya", + "listings.reservedCommunityTypeDescriptions.housingVoucher": "Mga May hawak ng Voucher ng HCV/Seksyon 8", "listings.reservedCommunityTypeDescriptions.senior": "Mga nakatatanda", "listings.reservedCommunityTypeDescriptions.senior55": "Mga nakatatanda 55+", "listings.reservedCommunityTypeDescriptions.senior62": "Mga nakatatanda 62+", "listings.reservedCommunityTypeDescriptions.specialNeeds": "Espesyal na pangangailangan", - "listings.reservedCommunityTypeDescriptions.veteran": "Beterano", - "listings.reservedCommunityTypeDescriptions.schoolEmployee": "Empleyado ng Paaralan", + "listings.reservedCommunityTypeDescriptions.veteran": "Mga beterano", + "listings.reservedCommunityTypeDescriptions.schoolEmployee": "Mga empleyado ng paaralan", "listings.reservedCommunityTypes.developmentalDisability": "Kapansanan sa Pag-unlad", + "listings.reservedCommunityTypes.farmworkerHousing": "Pabahay ng Magsasaka", "listings.reservedCommunityTypes.housingVoucher": "Voucher ng HCV/Seksyon 8", "listings.reservedCommunityTypes.senior": "Mga nakatatanda", "listings.reservedCommunityTypes.senior55": "Mga nakatatanda 55+", diff --git a/shared-helpers/src/locales/vi.json b/shared-helpers/src/locales/vi.json index 571b18d921..e99d6f9363 100644 --- a/shared-helpers/src/locales/vi.json +++ b/shared-helpers/src/locales/vi.json @@ -665,14 +665,16 @@ "listings.reservedCommunityTitleDefault": "Tòa nhà dành riêng", "listings.reservedCommunityType": "Loại cộng đồng dành riêng", "listings.reservedCommunityTypeDescriptions.developmentalDisability": "Người khuyết tật phát triển", - "listings.reservedCommunityTypeDescriptions.housingVoucher": "Người giữ phiếu HCV/Phần 8", + "listings.reservedCommunityTypeDescriptions.farmworkerHousing": "Công nhân nông trại và gia đình của họ", + "listings.reservedCommunityTypeDescriptions.housingVoucher": "Người sở hữu Phiếu giảm giá HCV/Mục 8", "listings.reservedCommunityTypeDescriptions.senior": "Người lớn tuổi", "listings.reservedCommunityTypeDescriptions.senior55": "Người cao tuổi 55+", "listings.reservedCommunityTypeDescriptions.senior62": "Người cao tuổi 62+", "listings.reservedCommunityTypeDescriptions.specialNeeds": "Nhu cầu đặc biệt", "listings.reservedCommunityTypeDescriptions.veteran": "Cựu chiến binh", - "listings.reservedCommunityTypeDescriptions.schoolEmployee": "Nhân viên trường học", + "listings.reservedCommunityTypeDescriptions.schoolEmployee": "Nhân viên nhà trường", "listings.reservedCommunityTypes.developmentalDisability": "Khuyết tật phát triển", + "listings.reservedCommunityTypes.farmworkerHousing": "Nhà ở cho công nhân nông trại", "listings.reservedCommunityTypes.housingVoucher": "Phiếu HCV/Phần 8", "listings.reservedCommunityTypes.senior": "Người lớn tuổi", "listings.reservedCommunityTypes.senior55": "Người cao tuổi 55+", diff --git a/shared-helpers/src/locales/zh.json b/shared-helpers/src/locales/zh.json index ee744ea8cf..e178174dfd 100644 --- a/shared-helpers/src/locales/zh.json +++ b/shared-helpers/src/locales/zh.json @@ -665,21 +665,23 @@ "listings.reservedCommunityTitleDefault": "预留楼", "listings.reservedCommunityType": "保留社区类型", "listings.reservedCommunityTypeDescriptions.developmentalDisability": "发育障碍人士", - "listings.reservedCommunityTypeDescriptions.housingVoucher": "HCV/第 8 节凭证持有者", + "listings.reservedCommunityTypeDescriptions.farmworkerHousing": "農場工人及其家人", + "listings.reservedCommunityTypeDescriptions.housingVoucher": "HCV/第 8 節優惠券持有者", "listings.reservedCommunityTypeDescriptions.senior": "老年人", "listings.reservedCommunityTypeDescriptions.senior55": "55 岁以上的老年人", "listings.reservedCommunityTypeDescriptions.senior62": "62 岁以上的老年人", "listings.reservedCommunityTypeDescriptions.specialNeeds": "特殊需求", - "listings.reservedCommunityTypeDescriptions.veteran": "老将", - "listings.reservedCommunityTypeDescriptions.schoolEmployee": "学校员工", + "listings.reservedCommunityTypeDescriptions.veteran": "退伍軍人", + "listings.reservedCommunityTypeDescriptions.schoolEmployee": "學校員工", "listings.reservedCommunityTypes.developmentalDisability": "发育障碍", + "listings.reservedCommunityTypes.farmworkerHousing": "移工住房", "listings.reservedCommunityTypes.housingVoucher": "HCV/第 8 节优惠券", "listings.reservedCommunityTypes.senior": "老年人", "listings.reservedCommunityTypes.senior55": "55 岁以上的老年人", "listings.reservedCommunityTypes.senior62": "62 岁以上的老年人", "listings.reservedCommunityTypes.specialNeeds": "特殊需求", - "listings.reservedCommunityTypes.veteran": "老将", - "listings.reservedCommunityTypes.schoolEmployee": "学校员工", + "listings.reservedCommunityTypes.veteran": "老將", + "listings.reservedCommunityTypes.schoolEmployee": "學校員工", "listings.reservedFor": "保留給 %{type}", "listings.reservedTypePlural.developmentalDisability": "发育障碍", "listings.reservedTypePlural.family": "家庭", diff --git a/shared-helpers/src/types/backend-swagger.ts b/shared-helpers/src/types/backend-swagger.ts index 626948e0d7..537b5cb5e3 100644 --- a/shared-helpers/src/types/backend-swagger.ts +++ b/shared-helpers/src/types/backend-swagger.ts @@ -2275,6 +2275,7 @@ export class ScriptRunnerService { axios(configs, resolve, reject) }) } + /** * A script that updates the preference keys for applications on Spark Homes */