67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
import { Test } from '@/modules/tests/entities/test.entity';
|
|
import {
|
|
Column,
|
|
CreateDateColumn,
|
|
Entity,
|
|
Index,
|
|
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';
|
|
import { UNIQUE_TEST_ORDER_IDX } from '../constants';
|
|
import { QuestionRangeRule } from './question-range-rule.entity';
|
|
import { QuestionTransition } from './question-transition.entity';
|
|
|
|
@Entity()
|
|
@Index(UNIQUE_TEST_ORDER_IDX, ['test', 'order'], { unique: true })
|
|
export class Question {
|
|
@PrimaryGeneratedColumn()
|
|
id!: number;
|
|
|
|
@ManyToOne(() => Test, (test) => test.questions, {
|
|
onDelete: 'CASCADE',
|
|
})
|
|
test!: Test;
|
|
|
|
@Column({
|
|
type: 'enum',
|
|
enum: QuestionType,
|
|
default: QuestionType.SINGLE_CHOICE,
|
|
})
|
|
type!: QuestionType;
|
|
|
|
@Column({ type: 'text', nullable: false })
|
|
content!: string;
|
|
|
|
@Column({ type: 'int', nullable: false })
|
|
@Index()
|
|
order!: number;
|
|
|
|
@Column({ type: 'int', default: 1 })
|
|
weight!: number;
|
|
|
|
@Column({ type: 'boolean', default: true })
|
|
required!: boolean;
|
|
|
|
@OneToMany(() => QuestionRangeRule, (rangeRule) => rangeRule.question)
|
|
rangeRules?: Array<QuestionRangeRule>;
|
|
|
|
@Column({ type: 'jsonb', nullable: true })
|
|
metadata!: QuestionMetadata;
|
|
|
|
@OneToMany(() => Choice, (choice) => choice.question)
|
|
choices!: Array<Choice>;
|
|
|
|
@OneToMany(() => QuestionTransition, (transition) => transition.fromQuestion)
|
|
outgoingTransitions!: Array<QuestionTransition>;
|
|
|
|
@OneToMany(() => QuestionTransition, (transition) => transition.toQuestion)
|
|
incomingTransitions!: Array<QuestionTransition>;
|
|
|
|
@CreateDateColumn()
|
|
createdAt!: Date;
|
|
}
|