From a6be180f331f9dbe9becd3c5210bcf709e9ac1e6 Mon Sep 17 00:00:00 2001 From: Morgan Ludtke <42942267+ludtkemorgan@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:07:48 -0500 Subject: [PATCH] fix: script runner for new reserved community type (#4380) * fix: script runner for new reserved community type * fix: update comment --- .../controllers/script-runner.controller.ts | 19 ++++++++++ .../dtos/script-runner/community-type.dto.ts | 23 +++++++++++ api/src/services/script-runner.service.ts | 38 +++++++++++++++++++ shared-helpers/src/locales/es.json | 2 + shared-helpers/src/locales/general.json | 2 + shared-helpers/src/locales/tl.json | 2 + shared-helpers/src/locales/vi.json | 2 + shared-helpers/src/locales/zh.json | 2 + 8 files changed, 90 insertions(+) create mode 100644 api/src/dtos/script-runner/community-type.dto.ts diff --git a/api/src/controllers/script-runner.controller.ts b/api/src/controllers/script-runner.controller.ts index f4c46b5a60..c77cf48671 100644 --- a/api/src/controllers/script-runner.controller.ts +++ b/api/src/controllers/script-runner.controller.ts @@ -17,6 +17,7 @@ import { AdminOrJurisdictionalAdminGuard } from '../guards/admin-or-jurisdiction import { DataTransferDTO } from '../dtos/script-runner/data-transfer.dto'; import { BulkApplicationResendDTO } from '../dtos/script-runner/bulk-application-resend.dto'; import { AmiChartImportDTO } from '../dtos/script-runner/ami-chart-import.dto'; +import { CommunityTypeDTO } from '../dtos/script-runner/community-type.dto'; @Controller('scriptRunner') @ApiTags('scriptRunner') @@ -120,4 +121,22 @@ export class ScirptRunnerController { ): Promise { return await this.scriptRunnerService.optOutExistingLotteries(req); } + + @Put('createNewReservedCommunityType') + @ApiOperation({ + summary: 'A script that creates a new reserved community type', + operationId: 'createNewReservedCommunityType', + }) + @ApiOkResponse({ type: SuccessDTO }) + async createNewReservedCommunityType( + @Body() body: CommunityTypeDTO, + @Request() req: ExpressRequest, + ): Promise { + return await this.scriptRunnerService.createNewReservedCommunityType( + req, + body.id, + body.name, + body.description, + ); + } } diff --git a/api/src/dtos/script-runner/community-type.dto.ts b/api/src/dtos/script-runner/community-type.dto.ts new file mode 100644 index 0000000000..d808dde2aa --- /dev/null +++ b/api/src/dtos/script-runner/community-type.dto.ts @@ -0,0 +1,23 @@ +import { IsDefined, IsString, IsUUID } from 'class-validator'; +import { Expose } from 'class-transformer'; +import { ValidationsGroupsEnum } from '../../enums/shared/validation-groups-enum'; +import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; + +export class CommunityTypeDTO { + @Expose() + @IsString({ groups: [ValidationsGroupsEnum.default] }) + @IsUUID(4, { groups: [ValidationsGroupsEnum.default] }) + @IsDefined({ groups: [ValidationsGroupsEnum.default] }) + @ApiProperty() + id: string; + + @Expose() + @IsString({ groups: [ValidationsGroupsEnum.default] }) + @ApiProperty() + name: string; + + @Expose() + @IsString({ groups: [ValidationsGroupsEnum.default] }) + @ApiPropertyOptional() + description?: string; +} diff --git a/api/src/services/script-runner.service.ts b/api/src/services/script-runner.service.ts index d60efc3813..7da13d66d9 100644 --- a/api/src/services/script-runner.service.ts +++ b/api/src/services/script-runner.service.ts @@ -17,6 +17,7 @@ import { Application } from '../dtos/applications/application.dto'; import { AmiChartImportDTO } from '../dtos/script-runner/ami-chart-import.dto'; import { AmiChartCreate } from '../dtos/ami-charts/ami-chart-create.dto'; import { AmiChartService } from './ami-chart.service'; +import { IdDTO } from '../dtos/shared/id.dto'; /** this is the service for running scripts @@ -416,6 +417,43 @@ export class ScriptRunnerService { return { success: true }; } + /** + * + * @param req incoming request object + * @param jurisdictionIdDTO id containing the jurisdiction id we are creating the new community type for + * @param name name of the community type + * @param name description of the community type + * @returns successDTO + * @description creates a new reserved community type. Reserved community types also need translations added + */ + async createNewReservedCommunityType( + req: ExpressRequest, + jurisdictionId: string, + name: string, + description?: string, + ): Promise { + // script runner standard start up + const requestingUser = mapTo(User, req['user']); + await this.markScriptAsRunStart(`${name} Type`, requestingUser); + + // create new reserved community type using the passed in params + await this.prisma.reservedCommunityTypes.create({ + data: { + name: name, + description: description, + jurisdictions: { + connect: { + id: jurisdictionId, + }, + }, + }, + }); + + // script runner standard spin down + await this.markScriptAsComplete(`${name} Type`, requestingUser); + return { success: true }; + } + /** this is simply an example */ diff --git a/shared-helpers/src/locales/es.json b/shared-helpers/src/locales/es.json index d1608ff012..0796c6ce9d 100644 --- a/shared-helpers/src/locales/es.json +++ b/shared-helpers/src/locales/es.json @@ -668,6 +668,7 @@ "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.reservedCommunityTypes.developmentalDisability": "La discapacidad del desarrollo", "listings.reservedCommunityTypes.housingVoucher": "Vale HCV/Sección 8", "listings.reservedCommunityTypes.senior": "Personas mayores", @@ -675,6 +676,7 @@ "listings.reservedCommunityTypes.senior62": "Personas mayores de 62 años", "listings.reservedCommunityTypes.specialNeeds": "Necesidades especiales", "listings.reservedCommunityTypes.veteran": "Veterano", + "listings.reservedCommunityTypes.schoolEmployee": "Empleado de la escuela", "listings.reservedFor": "Reservada para %{type}", "listings.reservedTypePlural.developmentalDisability": "Discapacidades del desarrollo", "listings.reservedTypePlural.family": "familias", diff --git a/shared-helpers/src/locales/general.json b/shared-helpers/src/locales/general.json index 28bc77d8ed..af7f418289 100644 --- a/shared-helpers/src/locales/general.json +++ b/shared-helpers/src/locales/general.json @@ -659,6 +659,7 @@ "listings.reservedCommunityTypeDescriptions.senior62": "Seniors 62+", "listings.reservedCommunityTypeDescriptions.specialNeeds": "Special Needs", "listings.reservedCommunityTypeDescriptions.veteran": "Veteran", + "listings.reservedCommunityTypeDescriptions.schoolEmployee": "School Employee", "listings.reservedCommunityTypes.developmentalDisability": "Developmental Disability", "listings.reservedCommunityTypes.housingVoucher": "HCV/Section 8 Voucher", "listings.reservedCommunityTypes.senior": "Seniors", @@ -666,6 +667,7 @@ "listings.reservedCommunityTypes.senior62": "Seniors 62+", "listings.reservedCommunityTypes.specialNeeds": "Special Needs", "listings.reservedCommunityTypes.veteran": "Veteran", + "listings.reservedCommunityTypes.schoolEmployee": "School Employee", "listings.reservedFor": "Reserved for %{type}", "listings.reservedTypePlural.developmentalDisability": "Developmental Disabilities", "listings.reservedTypePlural.family": "families", diff --git a/shared-helpers/src/locales/tl.json b/shared-helpers/src/locales/tl.json index 3bb1e663ab..adf3ec330a 100644 --- a/shared-helpers/src/locales/tl.json +++ b/shared-helpers/src/locales/tl.json @@ -668,6 +668,7 @@ "listings.reservedCommunityTypeDescriptions.senior62": "Mga nakatatanda 62+", "listings.reservedCommunityTypeDescriptions.specialNeeds": "Espesyal na pangangailangan", "listings.reservedCommunityTypeDescriptions.veteran": "Beterano", + "listings.reservedCommunityTypeDescriptions.schoolEmployee": "Empleyado ng Paaralan", "listings.reservedCommunityTypes.developmentalDisability": "Kapansanan sa Pag-unlad", "listings.reservedCommunityTypes.housingVoucher": "Voucher ng HCV/Seksyon 8", "listings.reservedCommunityTypes.senior": "Mga nakatatanda", @@ -675,6 +676,7 @@ "listings.reservedCommunityTypes.senior62": "Mga nakatatanda 62+", "listings.reservedCommunityTypes.specialNeeds": "Espesyal na pangangailangan", "listings.reservedCommunityTypes.veteran": "Beterano", + "listings.reservedCommunityTypes.schoolEmployee": "Empleyado ng Paaralan", "listings.reservedFor": "Nakalaan para sa %{type}", "listings.reservedTypePlural.developmentalDisability": "Mga Kapansanan sa Pag-unlad", "listings.reservedTypePlural.family": "mga pamilya", diff --git a/shared-helpers/src/locales/vi.json b/shared-helpers/src/locales/vi.json index b506b69fb0..fadd4e09c9 100644 --- a/shared-helpers/src/locales/vi.json +++ b/shared-helpers/src/locales/vi.json @@ -668,6 +668,7 @@ "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.reservedCommunityTypes.developmentalDisability": "Khuyết tật phát triển", "listings.reservedCommunityTypes.housingVoucher": "Phiếu HCV/Phần 8", "listings.reservedCommunityTypes.senior": "Người lớn tuổi", @@ -675,6 +676,7 @@ "listings.reservedCommunityTypes.senior62": "Người cao tuổi 62+", "listings.reservedCommunityTypes.specialNeeds": "Nhu cầu đặc biệt", "listings.reservedCommunityTypes.veteran": "Cựu chiến binh", + "listings.reservedCommunityTypes.schoolEmployee": "Nhân viên trường học", "listings.reservedFor": "Được dành riêng cho %{type}", "listings.reservedTypePlural.developmentalDisability": "Chậm phát triển", "listings.reservedTypePlural.family": "các gia đình", diff --git a/shared-helpers/src/locales/zh.json b/shared-helpers/src/locales/zh.json index 0847f168be..ea64d04fb7 100644 --- a/shared-helpers/src/locales/zh.json +++ b/shared-helpers/src/locales/zh.json @@ -668,6 +668,7 @@ "listings.reservedCommunityTypeDescriptions.senior62": "62 岁以上的老年人", "listings.reservedCommunityTypeDescriptions.specialNeeds": "特殊需求", "listings.reservedCommunityTypeDescriptions.veteran": "老将", + "listings.reservedCommunityTypeDescriptions.schoolEmployee": "学校员工", "listings.reservedCommunityTypes.developmentalDisability": "发育障碍", "listings.reservedCommunityTypes.housingVoucher": "HCV/第 8 节优惠券", "listings.reservedCommunityTypes.senior": "老年人", @@ -675,6 +676,7 @@ "listings.reservedCommunityTypes.senior62": "62 岁以上的老年人", "listings.reservedCommunityTypes.specialNeeds": "特殊需求", "listings.reservedCommunityTypes.veteran": "老将", + "listings.reservedCommunityTypes.schoolEmployee": "学校员工", "listings.reservedFor": "保留給 %{type}", "listings.reservedTypePlural.developmentalDisability": "发育障碍", "listings.reservedTypePlural.family": "家庭",