Skip to content

Commit

Permalink
338/incorporate new juris (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinBuyck committed Oct 25, 2023
1 parent 838f4a9 commit 7ad945c
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 4 deletions.
55 changes: 55 additions & 0 deletions backend/core/src/migration/1695143897902-add-jurisdictions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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<void> {}
}
2 changes: 2 additions & 0 deletions backend/core/src/seeder/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -88,6 +89,7 @@ const amiSeeds: any[] = [
AmiDefaultTriton,
AmiDefaultSanJose,
AmiDefaultSanMateo,
AmiDefaultDoorway,
]

export function getSeedListingsCount() {
Expand Down
2 changes: 2 additions & 0 deletions backend/core/src/seeder/seeder.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({})
Expand Down Expand Up @@ -113,6 +114,7 @@ export class SeederModule {
AmiDefaultTriton,
AmiDefaultSanJose,
AmiDefaultSanMateo,
AmiDefaultDoorway,
],
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
11 changes: 7 additions & 4 deletions backend/core/src/seeder/seeds/jurisdictions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand All @@ -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>(JurisdictionsService)
Expand Down
9 changes: 9 additions & 0 deletions backend/core/src/shared/types/doorway-jurisdictions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export enum DoorwayJurisdictions {
bayArea = "Bay Area",
contraCosta = "Contra Costa",
marin = "Marin",
napa = "Napa",
santaClara = "Santa Clara",
solano = "Solano",
sonoma = "Sonoma",
}

0 comments on commit 7ad945c

Please sign in to comment.