Skip to content

Commit a86e5d5

Browse files
committed
🗃️ Define location model
1 parent 79f7e94 commit a86e5d5

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/db/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import expiredData from './models/expiredData';
1414
import form from './models/form';
1515
import governingEntity from './models/governingEntity';
1616
import governingEntityVersion from './models/governingEntityVersion';
17+
import location from './models/location';
1718
import operation from './models/operation';
1819
import operationCluster from './models/operationCluster';
1920
import participant from './models/participant';
@@ -44,6 +45,7 @@ export default (conn: Knex) => ({
4445
form: form(conn),
4546
governingEntity: governingEntity(conn),
4647
governingEntityVersion: governingEntityVersion(conn),
48+
location: location(conn),
4749
operation: operation(conn),
4850
operationCluster: operationCluster(conn),
4951
participant: participant(conn),

src/db/models/location.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,44 @@ import * as t from 'io-ts';
22

33
import { brandedType } from '../../util/io-ts';
44
import type { Brand } from '../../util/types';
5+
import { defineIDModel } from '../util/id-model';
56

67
export type LocationId = Brand<number, { readonly s: unique symbol }, 'job.id'>;
78

89
export const LOCATION_ID = brandedType<number, LocationId>(t.number);
10+
11+
const LOCATION_STATUS = {
12+
active: null,
13+
expired: null,
14+
};
15+
16+
export default defineIDModel({
17+
tableName: 'location',
18+
fields: {
19+
generated: {
20+
id: { kind: 'branded-integer', brand: LOCATION_ID },
21+
},
22+
optional: {
23+
externalId: { kind: 'checked', type: t.string },
24+
name: { kind: 'checked', type: t.string },
25+
latitude: { kind: 'checked', type: t.number },
26+
longitude: { kind: 'checked', type: t.number },
27+
iso3: { kind: 'checked', type: t.string },
28+
pcode: { kind: 'checked', type: t.string },
29+
// Even though this column is defined as int8, it is
30+
// fetched as a string by knex, since it is bigint
31+
validOn: { kind: 'checked', type: t.string },
32+
parentId: { kind: 'branded-integer', brand: LOCATION_ID },
33+
},
34+
accidentallyOptional: {
35+
adminLevel: { kind: 'checked', type: t.number },
36+
status: {
37+
kind: 'enum',
38+
values: LOCATION_STATUS,
39+
},
40+
itosSync: { kind: 'checked', type: t.boolean },
41+
},
42+
},
43+
idField: 'id',
44+
softDeletionEnabled: false,
45+
});

0 commit comments

Comments
 (0)