Skip to content

Commit 32c95c9

Browse files
authored
Merge pull request #20 from sensebox/development
add: h5p slides and ids to questions
2 parents 9d72bb2 + 1942f40 commit 32c95c9

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ MONGO_DBNAME=blockly
44
PORT=8080
55

66
APP_ORIGIN=http://localhost:3000
7+
JWT_SECRET=qsldkjf9348u2rjsdf09234jfsd()$§JFSDF2309sdf
8+
REFRESH_TOKEN_SECRET=2323kjh4r23kjh5g23jh4g23jh4g23jh4g2
9+
710

811
# time in seconds
912
SHARE_EXPIRES_IN=2592000

models/tutorial.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44

55
const mongoose = require("mongoose");
66

7+
const QuestionSchema = new mongoose.Schema(
8+
{
9+
question: String,
10+
answers: [Object],
11+
h5plink: String,
12+
type: String,
13+
multipleChoice: Boolean,
14+
},
15+
{ _id: true }
16+
);
17+
718
const StepSchema = new mongoose.Schema({
819
type: {
920
type: String,
@@ -14,6 +25,7 @@ const StepSchema = new mongoose.Schema({
1425
"finish",
1526
"question",
1627
"blocklyExample",
28+
"h5p",
1729
],
1830
required: true,
1931
},
@@ -32,12 +44,15 @@ const StepSchema = new mongoose.Schema({
3244
default: undefined,
3345
},
3446
questionData: {
35-
type: [Object],
47+
type: [QuestionSchema],
3648
default: undefined,
3749
},
3850
xml: {
3951
type: String,
4052
},
53+
h5psrc: {
54+
type: String,
55+
},
4156
});
4257

4358
const TutorialSchema = new mongoose.Schema(
@@ -97,4 +112,18 @@ const TutorialSchema = new mongoose.Schema(
97112
}
98113
);
99114

115+
TutorialSchema.pre("save", function (next) {
116+
this.steps.forEach((step) => {
117+
if (step.type === "question" && Array.isArray(step.questionData)) {
118+
step.questionData.forEach((q) => {
119+
if (!q.id) {
120+
q.id = q._id?.toString();
121+
}
122+
});
123+
}
124+
});
125+
126+
next();
127+
});
128+
100129
module.exports = mongoose.model("Tutorial", TutorialSchema);

0 commit comments

Comments
 (0)