Skip to content

Commit

Permalink
Merge branch 'main' into release/update-ami-chart-script
Browse files Browse the repository at this point in the history
  • Loading branch information
mcgarrye authored Nov 4, 2024
2 parents 0e96d4d + d0e639f commit 0bd92f7
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 41 deletions.
15 changes: 15 additions & 0 deletions api/src/controllers/script-runner.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,19 @@ export class ScirptRunnerController {
): Promise<SuccessDTO> {
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<SuccessDTO> {
return await this.scriptRunnerService.correctApplicationPreferenceDataForSparksHomes(
req,
);
}
}
15 changes: 12 additions & 3 deletions api/src/dtos/script-runner/community-type.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
71 changes: 71 additions & 0 deletions api/src/services/script-runner.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,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<SuccessDTO> {
// 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
*/
Expand Down
65 changes: 65 additions & 0 deletions api/test/unit/services/script-runner.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 update existing ami chart', async () => {
const id = randomUUID();
prisma.scriptRuns.findUnique = jest.fn().mockResolvedValue(null);
Expand Down
8 changes: 5 additions & 3 deletions shared-helpers/src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 5 additions & 3 deletions shared-helpers/src/locales/general.json
Original file line number Diff line number Diff line change
Expand Up @@ -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+",
Expand Down
8 changes: 5 additions & 3 deletions shared-helpers/src/locales/tl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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+",
Expand Down
6 changes: 4 additions & 2 deletions shared-helpers/src/locales/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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+",
Expand Down
12 changes: 7 additions & 5 deletions shared-helpers/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "家庭",
Expand Down
Loading

0 comments on commit 0bd92f7

Please sign in to comment.