mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 19:10:12 +08:00
feat: finishSession and allow user command after finished
This commit is contained in:
1 parent
45f12acbd9
commit
f49fb0e4da
3 files changed
+30
-5
No files matched your search
@@ -49,11 +49,6 @@ export default class SessionHandler {
|
||||
|
||||
this.session.hints.push(...stage.hints)
|
||||
|
||||
if (stage.id === 'END') {
|
||||
this.session.status = 'finished'
|
||||
this.session.finishedAt = new Date()
|
||||
}
|
||||
|
||||
this.addNewTasks()
|
||||
|
||||
return {
|
||||
|
||||
@@ -79,3 +79,23 @@ export async function getOrCreateActiveSession(user, questId) {
|
||||
}
|
||||
return createNewSession(user, questId)
|
||||
}
|
||||
|
||||
export async function finishSession(session) {
|
||||
session.status = 'finished'
|
||||
await session.save()
|
||||
|
||||
const userProfile = await UserProfile.findOne({ user: session.user })
|
||||
if (!userProfile) {
|
||||
throw new Error(`UserProfile ${session.user} not found`)
|
||||
}
|
||||
|
||||
const progress = userProfile.progress.get(session.quest)
|
||||
if (!progress) {
|
||||
throw new Error(`Progress ${session.quest} not found`)
|
||||
}
|
||||
if (!progress.completed) {
|
||||
progress.finishedAt = new Date()
|
||||
progress.completed = true
|
||||
}
|
||||
await userProfile.save()
|
||||
}
|
||||
Reference in new issue
Block a user