From 1dcbb24cdb2502fcd443d09243c862ac9ec06530 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Thu, 12 Aug 2021 19:56:03 +0200 Subject: [PATCH] Define `participant` DB model --- src/db/index.ts | 4 +++- src/db/models/participant.ts | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/db/index.ts b/src/db/index.ts index a75af9a8..391d0cbd 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -1,6 +1,6 @@ import Knex = require('knex'); -import attachmentVersion from './models/attachmentVersion'; import attachment from './models/attachment'; +import attachmentVersion from './models/attachmentVersion'; import authGrant from './models/authGrant'; import authGrantee from './models/authGrantee'; import authGrantLog from './models/authGrantLog'; @@ -10,6 +10,7 @@ import form from './models/form'; import governingEntity from './models/governingEntity'; import operation from './models/operation'; import operationCluster from './models/operationCluster'; +import participant from './models/participant'; import reportingWindow from './models/reportingWindow'; import reportingWindowAssignment from './models/reportingWindowAssignment'; @@ -25,6 +26,7 @@ export default (conn: Knex) => ({ governingEntity: governingEntity(conn), operation: operation(conn), operationCluster: operationCluster(conn), + participant: participant(conn), reportingWindow: reportingWindow(conn), reportingWindowAssignment: reportingWindowAssignment(conn), }); diff --git a/src/db/models/participant.ts b/src/db/models/participant.ts index 38a5414c..afb7609f 100644 --- a/src/db/models/participant.ts +++ b/src/db/models/participant.ts @@ -2,6 +2,7 @@ import * as t from 'io-ts'; import { brandedType } from '../../util/io-ts'; import { Brand } from '../../util/types'; +import { defineIDModel } from '../util/id-model'; export type ParticipantId = Brand< number, @@ -10,3 +11,22 @@ export type ParticipantId = Brand< >; export const PARTICIPANT_ID = brandedType(t.number); + +export default defineIDModel({ + tableName: 'participant', + fields: { + generated: { + id: { kind: 'branded-integer', brand: PARTICIPANT_ID }, + }, + optional: { + hidId: { kind: 'checked', type: t.string }, + hidSub: { kind: 'checked', type: t.string }, + email: { kind: 'checked', type: t.string }, + name_given: { kind: 'checked', type: t.string }, + name_family: { kind: 'checked', type: t.string }, + }, + required: {}, + }, + idField: 'id', + softDeletionEnabled: false, +});