-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperation.ts
52 lines (47 loc) · 1.39 KB
/
operation.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import * as t from 'io-ts';
import { brandedType } from '../../util/io-ts';
import type { Brand } from '../../util/types';
import { defineVersionedModel } from '../util/versioned-model';
import { PLAN_ID } from './plan';
export type OperationId = Brand<
number,
{ readonly s: unique symbol },
'operation.id'
>;
export const OPERATION_ID = brandedType<number, OperationId>(t.number);
export const OPERATION_DATA = t.intersection([
t.type({
name: t.string,
/**
* TODO: Change to ID type
*/
locations: t.array(t.number),
/**
* TODO: Change to ID type
*/
emergencies: t.array(t.number),
}),
t.partial({
/**
* A list of any plans that are associated with this operation.
*
* Eventually, plans will be descendants of operations,
* but until that happens, we use this field to track the association.
*
* (doing this, though less efficient, allows us some flexibility,
* and avoids the need for additional migrations). If this link becomes
* needed for more regular lookups (e.g. auth calculations), then we should
* add a lookup Column / or move the data to a column in plan.
*/
plans: t.array(PLAN_ID),
}),
]);
export default defineVersionedModel({
tableBaseName: 'operation',
idType: OPERATION_ID,
data: OPERATION_DATA,
lookupColumns: {
columns: {},
prepare: () => Promise.resolve({}),
},
});