59 lines
1.5 KiB
TypeScript
59 lines
1.5 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 { Attachment, AttachmentSchema } from '../../attachment/entity/attachment.entity';
|
|
import { Option, OptionSchema } from '../../option/entity/option.entity';
|
|
import { Answer, AnswerSchema } from '../../answer/entity/answer.entity';
|
|
import { Question, QuestionSchema } from '../../question/entity/question.entity';
|
|
import { Participant, ParticipantSchema } from '../../participant/entity/participant.entity';
|
|
import { FormPage, FormPageSchema } from '../../formPage/entity/formPage.entity';
|
|
|
|
@Schema({ _id: false, id: false }) // Disable _id and virtual id
|
|
export class Form extends BaseEntity {
|
|
@Prop({
|
|
type: String,
|
|
required: true,
|
|
})
|
|
title: string;
|
|
|
|
@Prop({
|
|
type: String,
|
|
required: true,
|
|
})
|
|
description: string;
|
|
|
|
@Prop({
|
|
type: [AttachmentSchema],
|
|
default: [],
|
|
})
|
|
attachments: Attachment[];
|
|
|
|
@Prop({
|
|
type: [FormPageSchema],
|
|
default: [],
|
|
})
|
|
pages: FormPage[];
|
|
|
|
@Prop({
|
|
type: [ParticipantSchema],
|
|
default: [],
|
|
})
|
|
participants: Participant[];
|
|
}
|
|
|
|
export type FormDocument = Form & Document;
|
|
export const FormSchema = SchemaFactory.createForClass(Form);
|
|
FormSchema.plugin(mongoosePaginate);
|
|
|
|
// Transform the output to remove the internal '_id'
|
|
FormSchema.set('toJSON', {
|
|
transform: (doc: FormDocument, ret: Form & { _id?: any }) => {
|
|
delete ret._id;
|
|
return ret;
|
|
},
|
|
});
|
|
|
|
|
|
|