mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 11:30:13 +08:00
feat: load responses and tasks from existing session
This commit is contained in:
1 parent
2fcca0c4b9
commit
b4b8f8baee
9 files changed
+52
-28
No files matched your search
@@ -1,9 +1,11 @@
|
||||
import { TRPCError } from '@trpc/server'
|
||||
import { Session } from '@linux-odyssey/models'
|
||||
import { GameSession, VoidFileExistenceChecker } from '@linux-odyssey/game'
|
||||
import { z } from 'zod'
|
||||
import { isQuestUnlocked } from '../models/sessionManager.js'
|
||||
import config from '../config.js'
|
||||
import { protectedProcedure, router } from '../trpc.js'
|
||||
import { questManager } from '../models/quest.js'
|
||||
|
||||
export const sessionRouter = router({
|
||||
getActiveSession: protectedProcedure
|
||||
@@ -27,6 +29,15 @@ export const sessionRouter = router({
|
||||
if (!session) {
|
||||
return null
|
||||
}
|
||||
const quest = await questManager.get(questId)
|
||||
if (!quest) {
|
||||
return null
|
||||
}
|
||||
const gameSession = new GameSession(
|
||||
session,
|
||||
quest,
|
||||
new VoidFileExistenceChecker()
|
||||
)
|
||||
return {
|
||||
_id: session._id.toString(),
|
||||
user: session.user,
|
||||
@@ -35,6 +46,8 @@ export const sessionRouter = router({
|
||||
createdAt: session.createdAt,
|
||||
lastActivityAt: session.lastActivityAt,
|
||||
completedEvents: session.completedEvents,
|
||||
responses: gameSession.getResponses(),
|
||||
tasks: gameSession.getTasks(),
|
||||
}
|
||||
}
|
||||
throw new TRPCError({
|
||||
|
||||
Reference in new issue
Block a user