feat: add isFinished method to GameSession and update commandController to handle session completion

This commit is contained in:
Justin Lin committed 2025-04-23 17:10:51 +08:00
1 parent cfbc386c16
commit 52e9a13645
2 files changed
+7 -2

No files matched your search

+4
View File
@@ -44,6 +44,10 @@ export class GameSession {
return stageId
}
isFinished() {
return this.getActiveStages().length === 0
}
getResponses(): IResponse[] {
return this.quest.getResponses(this.completed)
}
@@ -60,10 +60,11 @@ export const newCommand = asyncHandler(async (req: Request, res: Response) => {
await c.save()
session.completedEvents = gameSession.completedEvents
await session.save()
if ((session.status as string) === 'finished') {
if (gameSession.isFinished()) {
await finishSession(session)
} else {
await session.save()
}
pushToSession(session.id, 'update', {
responses: gameSession.getResponses(),