feat: update quest and user schema

* add requirements in quest
* add progress in user
This commit is contained in:
Lin, Hung-Shin committed 2023-11-14 10:44:52 +08:00
1 parent 710eb8fc2e
commit fac91e0f10
6 files changed
+67 -7

No files matched your search

+30 -6
View File
@@ -54,7 +54,10 @@ const stageSchema = new Schema({
required: true,
default: false,
},
condition: conditionSchema,
condition: {
type: conditionSchema,
required: true,
},
responses: {
type: [responseSchema],
required: true,
@@ -68,11 +71,32 @@ const stageSchema = new Schema({
const Quest = model(
'Quest',
new Schema({
_id: String,
title: String,
order: Number,
instruction: String,
stages: [stageSchema],
_id: {
type: String,
unique: true,
required: true,
},
title: {
type: String,
required: true,
},
requirements: {
type: [
{
type: String,
ref: 'Quest',
},
],
required: true,
},
instruction: {
type: String,
required: true,
},
stages: {
type: [stageSchema],
required: true,
},
})
)
+20
View File
@@ -1,5 +1,24 @@
import { model, Schema } from 'mongoose'
const progressSchema = new Schema({
quest: {
type: String,
ref: 'Quest',
},
sessions: [
{
type: Schema.ObjectId,
ref: 'Session',
},
],
completionStatus: {
type: String,
enum: ['incomplete', 'completed'],
},
startedAt: Date,
finishedAt: Date,
})
const User = model(
'User',
new Schema(
@@ -23,6 +42,7 @@ const User = model(
id: String,
displayName: String,
},
progress: [progressSchema],
},
{
timestamps: true,
+6
View File
@@ -0,0 +1,6 @@
title: Discover the World!
instruction: |
試著探索這個世界吧!
requirements:
- spell
+6
View File
@@ -0,0 +1,6 @@
title: Read the File
instruction: |
閱讀檔案
requirements:
- spell
+4
View File
@@ -4,6 +4,10 @@ instruction: |
「輸入 echo Hello World!」
requirements:
- helloworld
- noexists
conditions:
pwd_home: &pwd_home
pwd:
+1 -1
View File
@@ -31,7 +31,7 @@ export default async function loadAndUpdateQuests() {
return Quest.findByIdAndUpdate(
id,
{
id,
_id: id,
...quest,
},
{