Skip to content

Commit

Permalink
Add reportDetail, reportFile to v4 models
Browse files Browse the repository at this point in the history
  • Loading branch information
Delgee committed Feb 15, 2024
1 parent 6bdcc40 commit ff951be
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ import projectVersionHistory from './models/projectVersionHistory';
import projectVersionOrganization from './models/projectVersionOrganization';
import projectVersionPlan from './models/projectVersionPlan';
import projectVersionPlanEntity from './models/projectVersionPlanEntity';
import reportDetail from './models/reportDetail';
import reportFile from './models/reportFile';
import reportingWindow from './models/reportingWindow';
import reportingWindowAssignment from './models/reportingWindowAssignment';
import tag from './models/tag';
Expand Down Expand Up @@ -198,6 +200,8 @@ const initializeTables = (conn: Knex) => ({
projectVersionOrganization: projectVersionOrganization(conn),
projectVersionPlan: projectVersionPlan(conn),
projectVersionPlanEntity: projectVersionPlanEntity(conn),
reportDetail: reportDetail(conn),
reportFile: reportFile(conn),
reportingWindow: reportingWindow(conn),
reportingWindowAssignment: reportingWindowAssignment(conn),
tag: tag(conn),
Expand Down
41 changes: 41 additions & 0 deletions src/db/models/reportDetail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as t from 'io-ts';

import { defineSequelizeModel } from '../util/sequelize-model';
import { Brand } from '../../util/types';
import { brandedType } from '../../util/io-ts';
import { FLOW_ID } from './flow';
import { DATE } from '../util/datatypes';
import { ORGANIZATION_ID } from './organization';

export type ReportDetailId = Brand<
number,
{ readonly s: unique symbol },
'reportDetail.id'
>;

export const REPORT_DETAIL_ID = brandedType<number, ReportDetailId>(t.number);

export default defineSequelizeModel({
tableName: 'reportDetail',
fields: {
generated: {
id: { kind: 'branded-integer', brand: REPORT_DETAIL_ID },
},
required: {
flowID: { kind: 'branded-integer', brand: FLOW_ID },
source: { kind: 'checked', type: t.string },
},
nonNullWithDefault: {
versionID: { kind: 'checked', type: t.number },
verified: { kind: 'checked', type: t.boolean },
},
optional: {
contactInfo: { kind: 'checked', type: t.string },
date: { kind: 'checked', type: DATE },
sourceID: { kind: 'checked', type: t.string },
refCode: { kind: 'checked', type: t.string },
organizationID: { kind: 'checked', type: ORGANIZATION_ID },
},
},
softDeletionEnabled: false,
});
39 changes: 39 additions & 0 deletions src/db/models/reportFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as t from 'io-ts';

import { defineSequelizeModel } from '../util/sequelize-model';
import { Brand } from '../../util/types';
import { brandedType } from '../../util/io-ts';
import { FILE_ASSET_ENTITY_ID } from './fileAssetEntity';
import { REPORT_DETAIL_ID } from './reportDetail';

export type ReportFileId = Brand<
number,
{ readonly s: unique symbol },
'reportFile.id'
>;

export const REPORT_FILE_TYPE = t.keyof({
file: null,
url: null,
});

export const REPORT_FILE_ID = brandedType<number, ReportFileId>(t.number);

export default defineSequelizeModel({
tableName: 'reportFile',
fields: {
generated: {
id: { kind: 'branded-integer', brand: REPORT_FILE_ID },
},
required: {
reportID: { kind: 'branded-integer', brand: REPORT_DETAIL_ID },
title: { kind: 'checked', type: t.string },
type: { kind: 'checked', type: REPORT_FILE_TYPE },
},
optional: {
url: { kind: 'checked', type: t.string },
fileAssetID: { kind: 'checked', type: FILE_ASSET_ENTITY_ID },
},
},
softDeletionEnabled: false,
});

0 comments on commit ff951be

Please sign in to comment.