From 1c8157cd511009fb9916db407efbe3dc75706f78 Mon Sep 17 00:00:00 2001 From: Pl217 Date: Tue, 2 Nov 2021 10:49:22 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20Define=20`usageYear`=20?= =?UTF-8?q?model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/index.ts | 2 ++ src/db/models/usageYear.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/db/index.ts b/src/db/index.ts index 897682a0..3cfbd201 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -29,6 +29,7 @@ import projectVersionAttachment from './models/projectVersionAttachment'; import projectVersionPlan from './models/projectVersionPlan'; import reportingWindow from './models/reportingWindow'; import reportingWindowAssignment from './models/reportingWindowAssignment'; +import usageYear from './models/usageYear'; import workflowStatusOption from './models/workflowStatusOption'; export default (conn: Knex) => ({ @@ -62,5 +63,6 @@ export default (conn: Knex) => ({ projectVersionPlan: projectVersionPlan(conn), reportingWindow: reportingWindow(conn), reportingWindowAssignment: reportingWindowAssignment(conn), + usageYear: usageYear(conn), workflowStatusOption: workflowStatusOption(conn), }); diff --git a/src/db/models/usageYear.ts b/src/db/models/usageYear.ts index 4defd8a8..b775ac0f 100644 --- a/src/db/models/usageYear.ts +++ b/src/db/models/usageYear.ts @@ -2,6 +2,7 @@ import * as t from 'io-ts'; import { brandedType } from '../../util/io-ts'; import type { Brand } from '../../util/types'; +import { defineIDModel } from '../util/id-model'; export type UsageYearId = Brand< number, @@ -10,3 +11,17 @@ export type UsageYearId = Brand< >; export const USAGE_YEAR_ID = brandedType(t.number); + +export default defineIDModel({ + tableName: 'usageYear', + fields: { + generated: { + id: { kind: 'branded-integer', brand: USAGE_YEAR_ID }, + }, + required: { + year: { kind: 'checked', type: t.string }, + }, + }, + idField: 'id', + softDeletionEnabled: false, +});