From 52e9a13645c3b716aab48d94e15455c6a1c4edb9 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Wed, 23 Apr 2025 17:10:51 +0800 Subject: [PATCH] feat: add isFinished method to GameSession and update commandController to handle session completion --- packages/game/src/Session.ts | 4 ++++ server/src/api/controllers/commandController.ts | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/game/src/Session.ts b/packages/game/src/Session.ts index d3e6ed8..4b5c088 100644 --- a/packages/game/src/Session.ts +++ b/packages/game/src/Session.ts @@ -44,6 +44,10 @@ export class GameSession { return stageId } + isFinished() { + return this.getActiveStages().length === 0 + } + getResponses(): IResponse[] { return this.quest.getResponses(this.completed) } diff --git a/server/src/api/controllers/commandController.ts b/server/src/api/controllers/commandController.ts index b02feb1..68cd71e 100644 --- a/server/src/api/controllers/commandController.ts +++ b/server/src/api/controllers/commandController.ts @@ -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(),