import { Column , Entity , ManyToOne , OneToMany , PrimaryGeneratedColumn , RelationId } from "typeorm" ; import { Question } from "./question" ; import { Exclude , Expose } from "class-transformer" ; import { ClosedAnswer } from "./closed-answer" ; import { OpenTextAnswer } from "./open-text-answer" ; import { OpenNumberAnswer } from "./open-number-answer" ; import { DynamicAnswer } from "./dynamic-answer" ; import { Variable } from "./variable" ; @ Exclude ( ) @ Entity ( { name : "answer" , } ) export class Answer { @ Expose ( ) @ PrimaryGeneratedColumn ( ) id ! : number ; @ Expose ( ) @ ManyToOne ( ( type ) => Question , ( question ) => question . answers , { nullable : false , } ) question ! : Question ; @ RelationId ( ( answer ) => answer . question ) questionId ! : number ; @ Column ( { nullable : true , } ) closedAnswerText ? : string ; @ Column ( { nullable : true , } ) correct ? : boolean ; @ Column ( { type : "float" , nullable : true , } ) openAnswerNumber ? : number ; @ Column ( { type : "float" , nullable : true , } ) precision ? : number ; @ Column ( { nullable : true , } ) openAnswerText ? : string ; @ Column ( { nullable : true , } ) dynamicAnswerExpression ? : string ; @ OneToMany ( ( type ) => Variable , ( variable ) => variable . answer ) dynamicAnswerVariables ? : Variable [ ] ; public isClosedAnswer ( ) { return ( this . closedAnswerText !== null && this . closedAnswerText !== undefined && this . correct !== null && this . correct !== undefined ) ; } public isOpenTextAnswer ( ) { return this . openAnswerText !== null && this . openAnswerText !== undefined ; } public isOpenNumberAnswer ( ) { return ( this . openAnswerNumber !== null && this . openAnswerNumber !== undefined && this . precision !== null && this . precision !== undefined ) ; } public isDynamicAnswer ( ) { return this . dynamicAnswerExpression !== null && this . dynamicAnswerExpression !== undefined ; } }