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(),