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

45 lines
1.1 KiB
TypeScript

import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';
import { BaseEntity } from 'src/_core/entity/_base.entity';
import * as mongoosePaginate from 'mongoose-paginate-v2';
import { v4 as uuidv4 } from 'uuid';
@Schema({ _id: false, id: false }) // Disable _id and virtual id
export class Answer extends BaseEntity {
@Prop({
type: String,
default: () => uuidv4(),
required: true,
immutable: true,
})
participantId: string;
@Prop({
type: String,
default: () => uuidv4(),
required: true,
immutable: true,
})
questionId: string; // form can be identified based on question
@Prop({
type: String,
required: true,
})
value: string; //value can be mapped to option based on question type
}
export type AnswerDocument = Answer & Document;
export const AnswerSchema = SchemaFactory.createForClass(Answer);
AnswerSchema.plugin(mongoosePaginate);
// Transform the output to remove the internal '_id'
AnswerSchema.set('toJSON', {
transform: (doc: AnswerDocument, ret: Answer & { _id?: any }) => {
delete ret._id;
return ret;
},
});