Form-Service/src/question/entity/question.entity.ts

49 lines
1.3 KiB
TypeScript

import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
import { BaseEntity } from 'src/_core/entity/_base.entity';
import { Attachment } from '../../attachment/entity/attachment.entity';
import { Option } from '../../option/entity/option.entity';
import { Answer } from '../../answer/entity/answer.entity';
import { FormSection } from '../../formSection/entity/formSection.entity';
@Entity({ name: 'questions' })
export class Question extends BaseEntity {
@Column()
text: string;
@Column({
type: 'enum',
enum: ['multiple-choice', 'single-choice', 'text'],
default: 'text',
})
type: 'multiple-choice' | 'single-choice' | 'text';
@Column({
type: 'boolean',
default: false,
})
isRequired: boolean;
@Column({
type: 'boolean',
default: false,
})
isConfidential: boolean;
@Column({
type: 'varchar',
nullable: true,
})
validationRules?: string;
@OneToMany(() => Option, (option) => option.question, { cascade: true })
options: Option[];
@OneToMany(() => Attachment, (attachment) => attachment.question, { cascade: true })
attachments: Attachment[];
@OneToMany(() => Answer, answer => answer.question, { cascade: true })
answers: Answer[]; // Answers to this question
@ManyToOne(() => FormSection, formSection => formSection.questions)
formSection: FormSection;
}