Skip to content

Commit 07c98df

Browse files
josh-torrejacktoncelliZainabImadulla
authored
Pris 137 (#179)
* Notification be refactor (#157) * refactored backend * schema and backend linting * final tsc checks and migration generated * linting * comments || false * updating featurethon workflows * basic Impl * cleanup * Cleanup types * Fix lint? * fix lint? pt 2 the electric boogaloo * One who thinks all the time, has only thoughts * remove file * Remove file pt 2 the electric boogaloo * Apply requested changes and improve cron structure * fix lint :( * took out featurethon --------- Co-authored-by: Jack <115236356+jacktoncelli@users.noreply.github.com> Co-authored-by: ZainabImadulla <zainab.imadulla@icloud.com>
1 parent 6916a41 commit 07c98df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+125558
-60
lines changed

backend/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ terraform/.terraform.lock.hcl
1414
**/.terraform.lock.hcl
1515
**/terraform/
1616
**/index.mjs
17-
src/tests/claim/pdf-generation/test-outputs/**
17+
src/tests/claim/pdf-generation/test-outputs/**
18+
backend/src/modules/fema-risk-index-data/tmp/**

backend/bun.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@supabase/ssr": "^0.5.2",
2929
"@supabase/supabase-js": "^2.47.10",
3030
"@tanstack/react-table": "^8.21.3",
31+
"adm-zip": "^0.5.16",
3132
"aws-lambda": "^1.0.7",
3233
"class-transformer": "^0.5.1",
3334
"class-validator": "^0.14.2",
@@ -38,6 +39,7 @@
3839
"hono": "^4.5.10",
3940
"jsonwebtoken": "^9.0.2",
4041
"node-cron": "^4.2.1",
42+
"papaparse": "^5.5.3",
4143
"pdf-parse": "^2.4.5",
4244
"pg": "^8.16.3",
4345
"pg-mem": "^3.0.5",
@@ -57,10 +59,12 @@
5759
"devDependencies": {
5860
"@hono/vite-build": "^1.1.0",
5961
"@hono/vite-dev-server": "^0.17.0",
62+
"@types/adm-zip": "^0.5.7",
6063
"@types/aws-lambda": "^8.10.156",
6164
"@types/bun": "^1.2.21",
6265
"@types/jsonwebtoken": "^9.0.10",
6366
"@types/node": "^20.19.12",
67+
"@types/papaparse": "^5.5.0",
6468
"@typescript-eslint/eslint-plugin": "^8.42.0",
6569
"@typescript-eslint/parser": "^8.42.0",
6670
"eslint": "^9.35.0",
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Entity, Column, CreateDateColumn, UpdateDateColumn, PrimaryColumn } from "typeorm";
2+
3+
@Entity("county_fema_risk_data")
4+
export class CountyFemaRisk {
5+
//Column title STCOFIPS
6+
@PrimaryColumn({ length: 5, unique: true })
7+
countyFipsCode!: string;
8+
9+
//Column title RISK_RATNG
10+
@Column({ length: 20 })
11+
riskRating!: string;
12+
13+
//EAL_RATING
14+
@Column({ length: 20 })
15+
ealRating!: string;
16+
17+
//Column title SOVI_RATNG
18+
@Column({ length: 20 })
19+
socialVuln!: string;
20+
21+
//Column title RESL_RATNG
22+
@Column({ length: 20 })
23+
communityResilience!: string;
24+
25+
//Column title CFLD_RISKR
26+
@Column({ length: 20 })
27+
coastalFlooding!: string;
28+
29+
//Column title DRGT_RISKR
30+
@Column({ length: 20 })
31+
drought!: string;
32+
33+
//Column title WFIR_RISKR
34+
@Column({ length: 20 })
35+
wildFire!: string;
36+
37+
@CreateDateColumn()
38+
createdAt!: Date;
39+
40+
@UpdateDateColumn()
41+
updatedAt!: Date;
42+
}

backend/src/entities/LocationAddress.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ export class LocationAddress {
4343
@Column()
4444
fipsCountyCode!: number;
4545

46+
@Column({ type: "float", default: 0 })
47+
lat!: number;
48+
49+
@Column({ type: "float", default: 0 })
50+
long!: number;
51+
4652
@OneToMany(() => DisasterNotification, (notification: { locationAddress: any }) => notification.locationAddress)
4753
disasterNotifications?: DisasterNotification[];
4854

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm";
2+
3+
export class AddFemaRiskIndexData1763616684714 implements MigrationInterface {
4+
name = "AddFemaRiskIndexData1763616684714";
5+
6+
public async up(queryRunner: QueryRunner): Promise<void> {
7+
await queryRunner.query(
8+
`CREATE TABLE "county_fema_risk_data" ("countyFipsCode" character varying(5) NOT NULL, "riskRating" character varying(20) NOT NULL, "ealRating" character varying(20) NOT NULL, "socialVuln" character varying(20) NOT NULL, "communityResilience" character varying(20) NOT NULL, "coastalFlooding" character varying(20) NOT NULL, "drought" character varying(20) NOT NULL, "wildFire" character varying(20) NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "PK_448aaa477ad2d846fa079d6dd9c" PRIMARY KEY ("countyFipsCode"))`
9+
);
10+
}
11+
12+
public async down(queryRunner: QueryRunner): Promise<void> {
13+
await queryRunner.query(`DROP TABLE "county_fema_risk_data"`);
14+
}
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm";
2+
3+
export class AddLocationLatLong1763709019323 implements MigrationInterface {
4+
name = 'AddLocationLatLong1763709019323'
5+
6+
public async up(queryRunner: QueryRunner): Promise<void> {
7+
await queryRunner.query(`ALTER TABLE "location_address" ADD "lat" double precision NOT NULL DEFAULT '0'`);
8+
await queryRunner.query(`ALTER TABLE "location_address" ADD "long" double precision NOT NULL DEFAULT '0'`);
9+
}
10+
11+
public async down(queryRunner: QueryRunner): Promise<void> {
12+
await queryRunner.query(`ALTER TABLE "location_address" DROP COLUMN "long"`);
13+
await queryRunner.query(`ALTER TABLE "location_address" DROP COLUMN "lat"`);
14+
}
15+
16+
}

backend/src/modules/clients/fips-location-matching/service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { logMessageToFile } from "../../../utilities/logger";
55
export interface LocationFips {
66
fipsStateCode: string;
77
fipsCountyCode: string;
8+
lat: number;
9+
long: number;
810
}
911

1012
export interface CensusGeocodeResponse {
@@ -83,6 +85,8 @@ export class FEMALocationMatcher implements IFEMALocationMatcher {
8385
return {
8486
fipsStateCode: geo.STATE,
8587
fipsCountyCode: geo.COUNTY,
88+
lat: parseFloat(geo.CENTLAT),
89+
long: parseFloat(geo.CENTLON),
8690
};
8791
} else {
8892
logMessageToFile("No census blocks data found in match");
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Context, TypedResponse } from "hono";
2+
import { withControllerErrorHandling } from "../../utilities/error";
3+
import { IFemaRiskIndexService } from "./service";
4+
import { FemaRiskIndexDataResult } from "./types";
5+
6+
export interface IFemaRiskIndex {
7+
updateFemaRiskIndexData(ctx: Context): Promise<TypedResponse<number, 200> | Response>;
8+
getFemaRiskIndexData(ctx: Context): Promise<TypedResponse<FemaRiskIndexDataResult, 200> | Response>;
9+
}
10+
11+
export class FemaRiskIndexController implements IFemaRiskIndex {
12+
private femaRiskIndexService: IFemaRiskIndexService;
13+
14+
constructor(service: IFemaRiskIndexService) {
15+
this.femaRiskIndexService = service;
16+
}
17+
18+
updateFemaRiskIndexData = withControllerErrorHandling(async (ctx: Context): Promise<TypedResponse<number, 200>> => {
19+
await this.femaRiskIndexService.updateFemaRiskIndexData();
20+
return ctx.json(1, 200);
21+
});
22+
23+
getFemaRiskIndexData = withControllerErrorHandling(
24+
async (ctx: Context): Promise<TypedResponse<FemaRiskIndexDataResult, 200>> => {
25+
const result = await this.femaRiskIndexService.getFemaRiskIndexData();
26+
return ctx.json(result, 200);
27+
}
28+
);
29+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { DataSource } from "typeorm";
2+
import { Hono } from "hono";
3+
import { FemaRiskIndexController } from "./controller";
4+
import { FemaRiskIndexService } from "./service";
5+
import { FemaRiskTransaction } from "./transaction";
6+
7+
export const femaRiskIndexProcessing = (db: DataSource): Hono => {
8+
const femaRiskIndex = new Hono();
9+
10+
const transaction = new FemaRiskTransaction(db);
11+
const service = new FemaRiskIndexService(transaction);
12+
const controller = new FemaRiskIndexController(service);
13+
14+
femaRiskIndex.post("/", (ctx) => controller.updateFemaRiskIndexData(ctx));
15+
femaRiskIndex.get("/", (ctx) => controller.getFemaRiskIndexData(ctx));
16+
17+
return femaRiskIndex;
18+
};

0 commit comments

Comments
 (0)