46 lines
1.3 KiB
TypeScript
46 lines
1.3 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 { FormSection, FormSectionSchema } from '../../formSection/entity/formSection.entity';
|
|
|
|
@Schema({ _id: false, id: false }) // Disable _id and virtual id
|
|
export class FormPage extends BaseEntity {
|
|
@Prop({
|
|
type: String,
|
|
required: true,
|
|
})
|
|
title: string;
|
|
|
|
@Prop({
|
|
type: String,
|
|
required: true,
|
|
})
|
|
description: string;
|
|
|
|
@Prop({
|
|
type: [FormSectionSchema],
|
|
default: [],
|
|
})
|
|
attachments: FormSection[];
|
|
}
|
|
|
|
export type FormPageDocument = FormPage & Document;
|
|
export const FormPageSchema = SchemaFactory.createForClass(FormPage);
|
|
FormPageSchema.plugin(mongoosePaginate);
|
|
|
|
// Transform the output to remove the internal '_id'
|
|
FormPageSchema.set('toJSON', {
|
|
transform: (doc: FormPageDocument, ret: FormPage & { _id?: any }) => {
|
|
delete ret._id;
|
|
return ret;
|
|
},
|
|
});
|
|
|
|
|
|
|