feat: add medical test entities
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { Question } from './question.entity';
|
||||
|
||||
@Entity()
|
||||
export class Choice {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@ManyToOne(() => Question, (question) => question.choices, {
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
question: Question;
|
||||
|
||||
@Column({
|
||||
type: 'varchar',
|
||||
length: 255,
|
||||
nullable: false,
|
||||
})
|
||||
text: string;
|
||||
|
||||
@Column({ type: 'int', nullable: false })
|
||||
value: number;
|
||||
|
||||
@Column({ type: 'int', nullable: false })
|
||||
order: number;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { Test } from '@/modules/tests/entities/test.entity';
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { QuestionType } from '../enums/question-type.enum';
|
||||
import type { QuestionMetadata } from '../types/question-metadata.type';
|
||||
import { Choice } from './choice.entity';
|
||||
|
||||
@Entity()
|
||||
export class Question {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@ManyToOne(() => Test, (test) => test.questions, {
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
test: Test;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: QuestionType,
|
||||
default: QuestionType.MULTI_CHOICE,
|
||||
})
|
||||
type: QuestionType;
|
||||
|
||||
@Column({ type: 'text' })
|
||||
content: string;
|
||||
|
||||
@Column({ type: 'int', nullable: false })
|
||||
order: number;
|
||||
|
||||
@Column({ type: 'boolean', default: true })
|
||||
required: boolean;
|
||||
|
||||
@Column({ type: 'jsonb', nullable: true })
|
||||
metadata: QuestionMetadata;
|
||||
|
||||
@OneToMany(() => Choice, (choice) => choice.question)
|
||||
choices?: Array<Choice>;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export enum QuestionType {
|
||||
MULTI_CHOICE = 'multi-choice',
|
||||
NUMERIC = 'numeric',
|
||||
TEXT = 'text',
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export interface MultiChoiceMetadata {
|
||||
allowOther?: boolean;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export interface NumericMetadata {
|
||||
min: number;
|
||||
max: number;
|
||||
step?: number;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Question } from './entities/question.entity';
|
||||
import { Choice } from './entities/choice.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Question, Choice])],
|
||||
})
|
||||
export class QuestionsModule {}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { MultiChoiceMetadata } from '../interfaces/multi-choice-metadata.interface';
|
||||
import { NumericMetadata } from '../interfaces/numeric-metadata.interface';
|
||||
|
||||
export type QuestionMetadata = NumericMetadata | MultiChoiceMetadata;
|
||||
Reference in New Issue
Block a user