-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcoursepage.mgmodel.ts
More file actions
108 lines (94 loc) · 2.09 KB
/
coursepage.mgmodel.ts
File metadata and controls
108 lines (94 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import mongoose, { Document, Schema } from "mongoose";
import mongooseLeanId from "mongoose-lean-id";
import { ElementSkeleton, PageType } from "../types/courseTypes";
// const ElementSkeletonSchema: Schema = new Schema({
// x: {
// type: Number,
// required: true,
// },
// y: {
// type: Number,
// required: true,
// },
// w: {
// type: Number,
// required: true,
// },
// h: {
// type: Number,
// required: true,
// },
// content: {
// type: ObjectId,
// required: true,
// ref: "CourseElement",
// },
// });
export interface CoursePageBase extends Document {
id: string;
title: string;
type: PageType;
}
export interface LessonPage extends CoursePageBase {
type: "Lesson";
source: string;
pageIndex: number;
}
export interface ActivityPage extends CoursePageBase {
type: "Activity";
layout: [ElementSkeleton];
}
export type CoursePage = LessonPage | ActivityPage;
const baseOptions = {
discriminatorKey: "type",
};
export const CoursePageSchema: Schema = new Schema(
{
title: {
type: String,
required: true,
},
type: {
type: String,
required: true,
enum: ["Lesson", "MultipleChoiceActivity", "MultiSelectActivity"],
},
},
baseOptions,
);
const LessonPageSchema: Schema = new Schema({
source: {
type: String,
required: true,
},
pageIndex: {
type: Number,
required: true,
},
});
// const ActivityPageSchema: Schema = new Schema({
// layout: {
// type: [ElementSkeletonSchema],
// required: true,
// },
// });
/* eslint-disable no-param-reassign */
CoursePageSchema.set("toObject", {
virtuals: true,
versionKey: false,
transform: (_doc: Document, ret: Record<string, unknown>) => {
// eslint-disable-next-line no-underscore-dangle
delete ret._id;
},
});
CoursePageSchema.plugin(mongooseLeanId);
const CoursePageModel = mongoose.model<CoursePage>(
"CoursePage",
CoursePageSchema,
);
const LessonPageModel = CoursePageModel.discriminator(
"Lesson",
LessonPageSchema,
);
export { LessonPageModel };
export default CoursePageModel;