Skip to content

Commit

Permalink
feat(Police Force Area): Add PFA model
Browse files Browse the repository at this point in the history
  • Loading branch information
cblanc committed Jan 4, 2023
1 parent 6f24dcf commit b3183b4
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app/lib/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Ward,
ScottishConstituency,
Outcode,
PoliceForceArea,
} from "../models/index";

// List of support tables generated from data/ directory
Expand All @@ -26,6 +27,7 @@ export const SUPPORT_TABLES = [
Parish,
Ward,
ScottishConstituency,
PoliceForceArea,
];

/**
Expand Down
1 change: 1 addition & 0 deletions src/app/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from "./terminated_postcode";
export * from "./ced";
export * from "./lsoa";
export * from "./msoa";
export * from "./police_force_area";
5 changes: 5 additions & 0 deletions src/app/models/police_force_area.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { generateAttributeMethods } from "./attribute_base";

const relation = "police_force_areas";

export const PoliceForceArea = generateAttributeMethods({ relation });
5 changes: 5 additions & 0 deletions src/app/models/postcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface PostcodeInterface {
lsoa: string | null;
msoa: string | null;
lau2: string | null;
pfa: string | null;
};
}

Expand Down Expand Up @@ -105,6 +106,7 @@ export interface PostcodeTuple {
ced: string;
ccg: string;
nuts: string;
pfa_id: string;
}

const relation: Relation = {
Expand Down Expand Up @@ -137,6 +139,7 @@ const relation: Relation = {
ced_id: "VARCHAR(32)",
constituency_id: "VARCHAR(32)",
date_of_introduction: "VARCHAR(6)",
pfa_id: "VARCHAR(32)",
},
indexes: [
{
Expand Down Expand Up @@ -802,6 +805,7 @@ const toJson = function (
lsoa: p.lsoa_id,
msoa: p.msoa_id,
lau2: p.nuts_id,
pfa: p.pfa_id,
},
// Insert distance if present
//@ts-ignore
Expand Down Expand Up @@ -868,6 +872,7 @@ const seedPostcodes = async (filepath: string) => {
{ column: "ced_id", method: (row) => row.extract("ced") },
{ column: "ccg_id", method: (row) => row.extract("ccg") },
{ column: "date_of_introduction", method: row => row.extract("dointr") },
{ column: "pfa_id", method: row => row.extract("pfa") },
]);

await methods.csvSeed({
Expand Down
2 changes: 2 additions & 0 deletions src/bin/clear_test_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ScottishPostcode,
Nuts,
Ward,
PoliceForceArea,
Outcode,
Place,
TerminatedPostcode,
Expand All @@ -31,6 +32,7 @@ const clear = async () => {
await ScottishConstituency.destroyRelation();
await Ccg.destroyRelation();
await Ward.destroyRelation();
await PoliceForceArea.destroyRelation();
await Outcode.destroyRelation();
await Ced.destroyRelation();
await Lsoa.destroyRelation();
Expand Down
3 changes: 3 additions & 0 deletions src/bin/create_test_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ScottishPostcode,
Nuts,
Ward,
PoliceForceArea,
Outcode,
Place,
TerminatedPostcode,
Expand Down Expand Up @@ -48,6 +49,7 @@ const clear = async (): Promise<unknown> => {
await ScottishConstituency.destroyRelation();
await Ccg.destroyRelation();
await Ward.destroyRelation();
await PoliceForceArea.destroyRelation();
await Outcode.destroyRelation();
await Ced.destroyRelation();
};
Expand All @@ -70,6 +72,7 @@ const seed = async (): Promise<unknown> => {
await ScottishConstituency.setupTable();
await Ccg.setupTable();
await Ward.setupTable();
await PoliceForceArea.setupTable();
await Outcode.setupTable();
console.log("Created outcodes relation");
await Ced.setupTable();
Expand Down
2 changes: 2 additions & 0 deletions test/attribute_base.models.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Ward,
Msoa,
Lsoa,
PoliceForceArea,
} from "../src/app/models/index";

const { rigCoreSpecs } = AttributeBaseSuite;
Expand All @@ -26,3 +27,4 @@ rigCoreSpecs(Parish);
rigCoreSpecs(Ward);
rigCoreSpecs(Msoa);
rigCoreSpecs(Lsoa);
rigCoreSpecs(PoliceForceArea);
3 changes: 3 additions & 0 deletions test/helper/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Ced,
Lsoa,
Msoa,
PoliceForceArea,
} from "../../src/app/models/index";
import { QueryResult } from "pg";

Expand Down Expand Up @@ -49,6 +50,7 @@ const clearTestDb = async (): Promise<any[] | null> => {
Msoa.destroyRelation(),
Outcode.destroyRelation(),
Ced.destroyRelation(),
PoliceForceArea.destroyRelation(),
]);
};

Expand Down Expand Up @@ -76,6 +78,7 @@ const seedPostcodeDb = async (): Promise<any[] | null> => {
Msoa.setupTable(),
Outcode.setupTable(),
Ced.setupTable(),
PoliceForceArea.setupTable(),
]);
};

Expand Down
3 changes: 3 additions & 0 deletions test/postcode.regression.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe("Postcode data regression testing", function () {
nuts: "Aberdeen City and Aberdeenshire",
nuts_code: "TLM50",
nuts_id: result.nuts_id,
pfa_id: "S23000009",
},
result
);
Expand Down Expand Up @@ -103,6 +104,7 @@ describe("Postcode data regression testing", function () {
nuts: "Lewisham and Southwark",
nuts_code: "TLI44",
nuts_id: result.nuts_id,
pfa_id: "E23000001",
},
result
);
Expand Down Expand Up @@ -153,6 +155,7 @@ describe("Postcode data regression testing", function () {
nuts: null,
nuts_code: null,
nuts_id: result.nuts_id,
pfa_id: "L99999999",
},
result
);
Expand Down

0 comments on commit b3183b4

Please sign in to comment.