Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ terraform/.terraform.lock.hcl
**/.terraform.lock.hcl
**/terraform/
**/index.mjs
src/tests/claim/pdf-generation/test-outputs/**
src/tests/claim/pdf-generation/test-outputs/**
backend/src/modules/fema-risk-index-data/tmp/**
13 changes: 13 additions & 0 deletions backend/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@supabase/ssr": "^0.5.2",
"@supabase/supabase-js": "^2.47.10",
"@tanstack/react-table": "^8.21.3",
"adm-zip": "^0.5.16",
"aws-lambda": "^1.0.7",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.2",
Expand All @@ -38,6 +39,7 @@
"hono": "^4.5.10",
"jsonwebtoken": "^9.0.2",
"node-cron": "^4.2.1",
"papaparse": "^5.5.3",
"pdf-parse": "^2.4.5",
"pg": "^8.16.3",
"pg-mem": "^3.0.5",
Expand All @@ -57,10 +59,12 @@
"devDependencies": {
"@hono/vite-build": "^1.1.0",
"@hono/vite-dev-server": "^0.17.0",
"@types/adm-zip": "^0.5.7",
"@types/aws-lambda": "^8.10.156",
"@types/bun": "^1.2.21",
"@types/jsonwebtoken": "^9.0.10",
"@types/node": "^20.19.12",
"@types/papaparse": "^5.5.0",
"@typescript-eslint/eslint-plugin": "^8.42.0",
"@typescript-eslint/parser": "^8.42.0",
"eslint": "^9.35.0",
Expand Down
42 changes: 42 additions & 0 deletions backend/src/entities/CountyFemaRiskData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Entity, Column, CreateDateColumn, UpdateDateColumn, PrimaryColumn } from "typeorm";

@Entity("county_fema_risk_data")
export class CountyFemaRisk {
//Column title STCOFIPS
@PrimaryColumn({ length: 5, unique: true })
countyFipsCode!: string;

//Column title RISK_RATNG
@Column({ length: 20 })
riskRating!: string;

//EAL_RATING
@Column({ length: 20 })
ealRating!: string;

//Column title SOVI_RATNG
@Column({ length: 20 })
socialVuln!: string;

//Column title RESL_RATNG
@Column({ length: 20 })
communityResilience!: string;

//Column title CFLD_RISKR
@Column({ length: 20 })
coastalFlooding!: string;

//Column title DRGT_RISKR
@Column({ length: 20 })
drought!: string;

//Column title WFIR_RISKR
@Column({ length: 20 })
wildFire!: string;

@CreateDateColumn()
createdAt!: Date;

@UpdateDateColumn()
updatedAt!: Date;
}
6 changes: 6 additions & 0 deletions backend/src/entities/LocationAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export class LocationAddress {
@Column()
fipsCountyCode!: number;

@Column({ type: "float", default: 0 })
lat!: number;

@Column({ type: "float", default: 0 })
long!: number;

@OneToMany(() => DisasterNotification, (notification: { locationAddress: any }) => notification.locationAddress)
disasterNotifications?: DisasterNotification[];

Expand Down
15 changes: 15 additions & 0 deletions backend/src/migrations/1763616684714-add-fema-risk-index-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class AddFemaRiskIndexData1763616684714 implements MigrationInterface {
name = "AddFemaRiskIndexData1763616684714";

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`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"))`
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "county_fema_risk_data"`);
}
}
16 changes: 16 additions & 0 deletions backend/src/migrations/1763709019323-add-location-lat-long.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class AddLocationLatLong1763709019323 implements MigrationInterface {
name = 'AddLocationLatLong1763709019323'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "location_address" ADD "lat" double precision NOT NULL DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE "location_address" ADD "long" double precision NOT NULL DEFAULT '0'`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "location_address" DROP COLUMN "long"`);
await queryRunner.query(`ALTER TABLE "location_address" DROP COLUMN "lat"`);
}

}
4 changes: 4 additions & 0 deletions backend/src/modules/clients/fips-location-matching/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { logMessageToFile } from "../../../utilities/logger";
export interface LocationFips {
fipsStateCode: string;
fipsCountyCode: string;
lat: number;
long: number;
}

export interface CensusGeocodeResponse {
Expand Down Expand Up @@ -83,6 +85,8 @@ export class FEMALocationMatcher implements IFEMALocationMatcher {
return {
fipsStateCode: geo.STATE,
fipsCountyCode: geo.COUNTY,
lat: parseFloat(geo.CENTLAT),
long: parseFloat(geo.CENTLON),
};
} else {
logMessageToFile("No census blocks data found in match");
Expand Down
29 changes: 29 additions & 0 deletions backend/src/modules/fema-risk-index-data/controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Context, TypedResponse } from "hono";
import { withControllerErrorHandling } from "../../utilities/error";
import { IFemaRiskIndexService } from "./service";
import { FemaRiskIndexDataResult } from "./types";

export interface IFemaRiskIndex {
updateFemaRiskIndexData(ctx: Context): Promise<TypedResponse<number, 200> | Response>;
getFemaRiskIndexData(ctx: Context): Promise<TypedResponse<FemaRiskIndexDataResult, 200> | Response>;
}

export class FemaRiskIndexController implements IFemaRiskIndex {
private femaRiskIndexService: IFemaRiskIndexService;

constructor(service: IFemaRiskIndexService) {
this.femaRiskIndexService = service;
}

updateFemaRiskIndexData = withControllerErrorHandling(async (ctx: Context): Promise<TypedResponse<number, 200>> => {
await this.femaRiskIndexService.updateFemaRiskIndexData();
return ctx.json(1, 200);
});

getFemaRiskIndexData = withControllerErrorHandling(
async (ctx: Context): Promise<TypedResponse<FemaRiskIndexDataResult, 200>> => {
const result = await this.femaRiskIndexService.getFemaRiskIndexData();
return ctx.json(result, 200);
}
);
}
18 changes: 18 additions & 0 deletions backend/src/modules/fema-risk-index-data/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { DataSource } from "typeorm";
import { Hono } from "hono";
import { FemaRiskIndexController } from "./controller";
import { FemaRiskIndexService } from "./service";
import { FemaRiskTransaction } from "./transaction";

export const femaRiskIndexProcessing = (db: DataSource): Hono => {
const femaRiskIndex = new Hono();

const transaction = new FemaRiskTransaction(db);
const service = new FemaRiskIndexService(transaction);
const controller = new FemaRiskIndexController(service);

femaRiskIndex.post("/", (ctx) => controller.updateFemaRiskIndexData(ctx));
femaRiskIndex.get("/", (ctx) => controller.getFemaRiskIndexData(ctx));

return femaRiskIndex;
};
Loading
Loading