question.model.ts 665 Bytes
Newer Older
Jiwon Yoon's avatar
Jiwon Yoon committed
1
import { model, ObjectId, Schema, Types } from "mongoose";
Jiwon Yoon's avatar
Jiwon Yoon committed
2
3

export interface IQuestion {
Jiwon Yoon's avatar
Jiwon Yoon committed
4
  _id?: Types.ObjectId;
Jiwon Yoon's avatar
Jiwon Yoon committed
5
  user?: Types.ObjectId;
Jiwon Yoon's avatar
Jiwon Yoon committed
6
  order: number;
Jiwon Yoon's avatar
Jiwon Yoon committed
7
8
9
10
11
12
13
14
15
  type: string;
  title?: string;
  isRequired: boolean;
  comment?: string;
  content?: any;
}

const schema = new Schema<IQuestion>(
  {
Jiwon Yoon's avatar
Jiwon Yoon committed
16
    user: { type: Schema.Types.ObjectId, ref: "User" },
Jiwon Yoon's avatar
Jiwon Yoon committed
17
18
    order: { type: Number },
    type: { type: String, required: true },
Jiwon Yoon's avatar
Jiwon Yoon committed
19
20
21
22
23
24
25
26
27
    title: { type: String },
    isRequired: { type: Boolean },
    comment: { type: String },
    content: { type: Object },
  },
  {
    toJSON: {
      versionKey: false,
    },
Jiwon Yoon's avatar
Jiwon Yoon committed
28
  }
Jiwon Yoon's avatar
Jiwon Yoon committed
29
30
31
);

export default model<IQuestion>("Question", schema);