Skip to content

Commit

Permalink
Model rsc assessment and category tables; add OneToMany relation betw…
Browse files Browse the repository at this point in the history
…een user and assessment; update question and resource column names.
  • Loading branch information
Matthew-Grayson committed Mar 22, 2024
1 parent b3d4aff commit 8e654b5
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 2 deletions.
4 changes: 4 additions & 0 deletions backend/src/models/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
Organization,
OrganizationTag,
Role,
RscAssessment,
RscCategory,
RscQuestion,
RscResource,
SavedSearch,
Expand Down Expand Up @@ -36,6 +38,8 @@ const connectDb = async (logging?: boolean) => {
Organization,
OrganizationTag,
Role,
RscAssessment,
RscCategory,
RscQuestion,
RscResource,
SavedSearch,
Expand Down
2 changes: 2 additions & 0 deletions backend/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export * from './domain';
export * from './organization';
export * from './organization-tag';
export * from './role';
export * from './rsc_assessment';
export * from './rsc_category';
export * from './rsc_question';
export * from './rsc_resource';
export * from './saved-search';
Expand Down
29 changes: 29 additions & 0 deletions backend/src/models/rsc_assessment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
BaseEntity,
CreateDateColumn,
Entity,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
UpdateDateColumn
} from 'typeorm';
import { User } from './user';
import { RscQuestion } from './rsc_question';

@Entity()
export class RscAssessment extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id: string;

@CreateDateColumn()
createdAt: Date;

@UpdateDateColumn()
updatedAt: Date;

@ManyToOne(() => User, (user) => user.assessments)
user: User;

@OneToMany(() => RscQuestion, (question) => question.assessment)
questions: RscQuestion[];
}
20 changes: 20 additions & 0 deletions backend/src/models/rsc_category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
BaseEntity,
Column,
Entity,
OneToMany,
PrimaryGeneratedColumn
} from 'typeorm';
import { RscQuestion } from './rsc_question';

@Entity()
export class RscCategory extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column()
name: string;

@OneToMany(() => RscQuestion, (question) => question.category)
questions: RscQuestion[];
}
15 changes: 15 additions & 0 deletions backend/src/models/rsc_question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import {
BaseEntity,
Column,
Entity,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn
} from 'typeorm';
import { RscAssessment } from './rsc_assessment';
import { RscCategory } from './rsc_category';
import { RscResource } from './rsc_resource';

@Entity()
Expand All @@ -15,6 +18,18 @@ export class RscQuestion extends BaseEntity {
@Column()
name: string;

@Column()
longForm: string;

@Column()
number: number;

@ManyToOne(() => RscAssessment, (assessment) => assessment.questions)
assessment: RscAssessment;

@ManyToOne(() => RscCategory, (category) => category.questions)
category: RscCategory;

@OneToMany(() => RscResource, (resource) => resource.question)
resources: RscResource[];
}
7 changes: 5 additions & 2 deletions backend/src/models/rsc_resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ export class RscResource extends BaseEntity {
id: string;

@Column()
title: string;
description: string;

@Column()
text: string;
name: string;

@Column()
type: string;

@Column()
url: string;
Expand Down
4 changes: 4 additions & 0 deletions backend/src/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from 'typeorm';
import { Role } from './';
import { ApiKey } from './api-key';
import { RscAssessment } from './rsc_assessment';

export enum UserType {
GLOBAL_VIEW = 'globalView',
Expand Down Expand Up @@ -116,4 +117,7 @@ export class User extends BaseEntity {
nullable: true
})
state: string;

@OneToMany(() => RscAssessment, (assessment) => assessment.user)
assessments: RscAssessment[];
}

0 comments on commit 8e654b5

Please sign in to comment.