mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 19:10:12 +08:00
feat: check if a quest is unlocked before creating session
This commit is contained in:
1 parent
c2dac8d385
commit
92181d960f
4 files changed
+32
-8
No files matched your search
@@ -99,3 +99,18 @@ export async function finishSession(session) {
|
||||
}
|
||||
await userProfile.save()
|
||||
}
|
||||
|
||||
export async function isQuestUnlocked(user, questId) {
|
||||
const userProfile = await UserProfile.findOne({ user: user._id })
|
||||
if (!userProfile) {
|
||||
throw new Error(`UserProfile ${user._id} not found`)
|
||||
}
|
||||
const quest = await Quest.findById(questId)
|
||||
if (!quest) {
|
||||
throw new Error(`Quest ${questId} not found`)
|
||||
}
|
||||
return quest.requirements.every((requiredQuestId) => {
|
||||
const progress = userProfile.progress.get(requiredQuestId)
|
||||
return progress && progress.completed
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user