feat: add UserProfile collection, create on login

* add progress
This commit is contained in:
wancat authored and Lin, Hung-Shin committed 2023-11-14 10:44:52 +08:00
1 parent e981bff3bb
commit 45f12acbd9
5 files changed
+75 -22

No files matched your search

+1
View File
@@ -4,6 +4,7 @@ export { default as User } from './user.js'
export { default as Quest } from './quest.js'
export { default as Session } from './session.js'
export { default as Command } from './command.js'
export { default as UserProfile } from './userProfile.js'
export default async function connectDB(uri) {
const db = await mongoose.connect(uri, {
-20
View File
@@ -1,24 +1,5 @@
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(
@@ -42,7 +23,6 @@ const User = model(
id: String,
displayName: String,
},
progress: [progressSchema],
},
{
timestamps: true,
+51
View File
@@ -0,0 +1,51 @@
import { model, Schema } from 'mongoose'
const progressSchema = new Schema({
quest: {
type: String,
ref: 'Quest',
required: true,
},
sessions: [
{
type: Schema.ObjectId,
ref: 'Session',
required: true,
},
],
completed: {
type: Boolean,
default: false,
required: true,
},
startedAt: {
type: Date,
required: true,
},
finishedAt: Date,
})
const UserProfile = model(
'UserProfile',
new Schema(
{
user: {
type: Schema.ObjectId,
ref: 'User',
unique: true,
required: true,
},
progress: {
type: Map,
of: progressSchema,
default: {},
required: true,
},
},
{
timestamps: true,
}
)
)
export default UserProfile