From 7ad945cda75cf9dfceddd3b3b94716ddb36dd5dc Mon Sep 17 00:00:00 2001 From: ColinBuyck <53269332+ColinBuyck@users.noreply.github.com> Date: Tue, 24 Oct 2023 11:37:06 -0700 Subject: [PATCH] 338/incorporate new juris (#387) --- .../1695143897902-add-jurisdictions.ts | 55 +++++++++++++++++++ backend/core/src/seeder/seed.ts | 2 + backend/core/src/seeder/seeder.module.ts | 2 + .../ami-charts/default-ami-chart-doorway.ts | 19 +++++++ .../core/src/seeder/seeds/jurisdictions.ts | 11 ++-- .../src/shared/types/doorway-jurisdictions.ts | 9 +++ 6 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 backend/core/src/seeder/seeds/ami-charts/default-ami-chart-doorway.ts create mode 100644 backend/core/src/shared/types/doorway-jurisdictions.ts diff --git a/backend/core/src/migration/1695143897902-add-jurisdictions.ts b/backend/core/src/migration/1695143897902-add-jurisdictions.ts index 8e81940941a..5182576bc11 100644 --- a/backend/core/src/migration/1695143897902-add-jurisdictions.ts +++ b/backend/core/src/migration/1695143897902-add-jurisdictions.ts @@ -11,6 +11,7 @@ export class addJurisdictions1695143897902 implements MigrationInterface { WHERE name='Bay Area'` ) )[0] + //add new jurisdictions const countyArr = ["Contra Costa", "Marin", "Napa", "Santa Clara", "Solano", "Sonoma"] countyArr.forEach(async (county) => { const newJuris = { ...baseJurisdiction, name: county } @@ -25,6 +26,60 @@ export class addJurisdictions1695143897902 implements MigrationInterface { jurisValues ) }) + + //link existing listings to corresponding jurisdiction + const existingListings = await queryRunner.query( + `SELECT listings.id,county + FROM listings + LEFT JOIN address on listings.building_address_id = address.id` + ) + const existingJurisdictions = await queryRunner.query( + `SELECT id,name + FROM jurisdictions` + ) + + existingListings.forEach(async (listing) => { + const matchingJuris = existingJurisdictions.find((juris) => juris.name === listing.county).id + await queryRunner.query( + `UPDATE listings + SET jurisdiction_id='${matchingJuris}' + WHERE id='${listing.id}'` + ) + }) + + //link existing ami charts to new jurisdictions + const amiJurisMap = { + "Marin - HUD": "Marin", + "Napa - HUD": "Napa", + "Contra Costa - HUD": "Contra Costa", + "Santa Clara - HUD": "Santa Clara", + "Solano - HUD": "Solano", + "Sonoma - HUD": "Sonoma", + "Sonoma - Sonoma County State and Local": "Sonoma", + "Contra Costa - CA TCAC": "Contra Costa", + "Marin - CA TCAC": "Marin", + "Napa - CA TCAC": "Napa", + "Santa Clara - CA TCAC": "Santa Clara", + "Solano - CA TCAC": "Solano", + "Sonoma - CA TCAC": "Sonoma", + } + const amiCharts = await queryRunner.query( + `SELECT id,name + FROM ami_chart` + ) + amiCharts.forEach(async (ami) => { + const matchingJuris = existingJurisdictions.find( + (juris) => juris.name === amiJurisMap[ami.name] + )?.id + if (matchingJuris) { + await queryRunner.query( + `UPDATE ami_chart + SET jurisdiction_id='${matchingJuris}' + WHERE id='${ami.id}'` + ) + } + }) } + public async down(queryRunner: QueryRunner): Promise {} } diff --git a/backend/core/src/seeder/seed.ts b/backend/core/src/seeder/seed.ts index 1846174e556..a1ef79e4e6a 100644 --- a/backend/core/src/seeder/seed.ts +++ b/backend/core/src/seeder/seed.ts @@ -40,6 +40,7 @@ import { AmiDefaultMissingAMI } from "./seeds/ami-charts/missing-household-ami-l import { SeederModule } from "./seeder.module" import { AmiDefaultTriton } from "./seeds/ami-charts/triton-ami-chart" import { AmiDefaultSanMateo } from "./seeds/ami-charts/default-ami-chart-san-mateo" +import { AmiDefaultDoorway } from "./seeds/ami-charts/default-ami-chart-doorway" import { makeNewApplication } from "./seeds/applications" import { UserRoles } from "../auth/entities/user-roles.entity" import { Jurisdiction } from "../jurisdictions/entities/jurisdiction.entity" @@ -88,6 +89,7 @@ const amiSeeds: any[] = [ AmiDefaultTriton, AmiDefaultSanJose, AmiDefaultSanMateo, + AmiDefaultDoorway, ] export function getSeedListingsCount() { diff --git a/backend/core/src/seeder/seeder.module.ts b/backend/core/src/seeder/seeder.module.ts index 05e7be369e0..0a0985ee101 100644 --- a/backend/core/src/seeder/seeder.module.ts +++ b/backend/core/src/seeder/seeder.module.ts @@ -47,6 +47,7 @@ import { AmiDefaultMissingAMI } from "../seeder/seeds/ami-charts/missing-househo import { AmiDefaultTriton } from "../seeder/seeds/ami-charts/triton-ami-chart" import { AmiDefaultSanJose } from "../seeder/seeds/ami-charts/default-ami-chart-san-jose" import { AmiDefaultSanMateo } from "../seeder/seeds/ami-charts/default-ami-chart-san-mateo" +import { AmiDefaultDoorway } from "./seeds/ami-charts/default-ami-chart-doorway" import { Asset } from "../assets/entities/asset.entity" @Module({}) @@ -113,6 +114,7 @@ export class SeederModule { AmiDefaultTriton, AmiDefaultSanJose, AmiDefaultSanMateo, + AmiDefaultDoorway, ], } } diff --git a/backend/core/src/seeder/seeds/ami-charts/default-ami-chart-doorway.ts b/backend/core/src/seeder/seeds/ami-charts/default-ami-chart-doorway.ts new file mode 100644 index 00000000000..4f68a473546 --- /dev/null +++ b/backend/core/src/seeder/seeds/ami-charts/default-ami-chart-doorway.ts @@ -0,0 +1,19 @@ +import { DoorwayJurisdictions } from "../../../../src/shared/types/doorway-jurisdictions" +import { AmiChartDefaultSeed, getDefaultAmiChart } from "./default-ami-chart" + +export class AmiDefaultDoorway extends AmiChartDefaultSeed { + async seed() { + const promiseArr = Object.values(DoorwayJurisdictions).map(async (name) => { + const doorwayJurisdiction = await this.jurisdictionRepository.findOneOrFail({ + where: { name: name }, + }) + return await this.amiChartRepository.save({ + ...getDefaultAmiChart(), + name: `${name} - HUD`, + jurisdiction: doorwayJurisdiction, + }) + }) + + return await Promise.all(promiseArr) + } +} diff --git a/backend/core/src/seeder/seeds/jurisdictions.ts b/backend/core/src/seeder/seeds/jurisdictions.ts index a6b9360e604..7edf6485c65 100644 --- a/backend/core/src/seeder/seeds/jurisdictions.ts +++ b/backend/core/src/seeder/seeds/jurisdictions.ts @@ -3,6 +3,7 @@ import { JurisdictionCreateDto } from "../../jurisdictions/dto/jurisdiction-crea import { Language } from "../../shared/types/language-enum" import { JurisdictionsService } from "../../jurisdictions/services/jurisdictions.service" import { UserRoleEnum } from "../../../src/auth/enum/user-role-enum" +import { DoorwayJurisdictions } from "../../../src/shared/types/doorway-jurisdictions" export const basicJurisInfo: JurisdictionCreateDto = { name: "", @@ -18,10 +19,12 @@ export const basicJurisInfo: JurisdictionCreateDto = { enableUtilitiesIncluded: true, listingApprovalPermissions: [UserRoleEnum.admin], } -const jurisNames = ["Bay Area", "Contra Costa", "Marin", "Napa", "Santa Clara", "Solano", "Sonoma"] -const activeJurisdictions: JurisdictionCreateDto[] = jurisNames.map((name) => { - return { ...basicJurisInfo, name: name } -}) + +const activeJurisdictions: JurisdictionCreateDto[] = Object.values(DoorwayJurisdictions).map( + (name) => { + return { ...basicJurisInfo, name: name } + } +) export async function createJurisdictions(app: INestApplicationContext) { const jurisdictionService = await app.resolve(JurisdictionsService) diff --git a/backend/core/src/shared/types/doorway-jurisdictions.ts b/backend/core/src/shared/types/doorway-jurisdictions.ts new file mode 100644 index 00000000000..7eea5648af5 --- /dev/null +++ b/backend/core/src/shared/types/doorway-jurisdictions.ts @@ -0,0 +1,9 @@ +export enum DoorwayJurisdictions { + bayArea = "Bay Area", + contraCosta = "Contra Costa", + marin = "Marin", + napa = "Napa", + santaClara = "Santa Clara", + solano = "Solano", + sonoma = "Sonoma", +}