From efd6b150887c25fe8f073039a0e94624e901e063 Mon Sep 17 00:00:00 2001 From: zhl Date: Thu, 13 May 2021 19:16:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B6=85=E6=97=B6=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E7=9A=84=E5=A4=84=E7=90=86=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/controllers/puzzle.controller.ts | 21 ++++++++++----------- src/models/GameUser.ts | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/api/controllers/puzzle.controller.ts b/src/api/controllers/puzzle.controller.ts index 2d7bf75..c24529d 100644 --- a/src/api/controllers/puzzle.controller.ts +++ b/src/api/controllers/puzzle.controller.ts @@ -93,10 +93,16 @@ class PuzzleController extends BaseController { if (!history) { throw new ZError(13, 'not found match info') } + let record = await Puzzle.findById(id) + if (!record) { + throw new ZError(12, 'question not found') + } + let result = record.a1 == answer ? 1 : 0 + if (type == 1) { + result = 0 + } if (history.status == 9 || history.hasExpired()) { - history.status = 9 - await history.save() - throw new ZError(17, 'match end') + result = 0 } if (!history.members.has(accountid)) { throw new ZError(14, 'not in current match') @@ -108,14 +114,7 @@ class PuzzleController extends BaseController { if (statMap.answer.has(id)) { throw new ZError(15, 'current question already answered') } - let record = await Puzzle.findById(id) - if (!record) { - throw new ZError(12, 'question not found') - } - let result = record.a1 == answer ? 1 : 0 - if (type == 1) { - result = 0 - } + statMap.answer.set(id, result) if (result == 1) { statMap.rightCount++ diff --git a/src/models/GameUser.ts b/src/models/GameUser.ts index 964528d..5eb18bb 100644 --- a/src/models/GameUser.ts +++ b/src/models/GameUser.ts @@ -8,7 +8,7 @@ import { import { BaseModule } from './Base' @dbconn() -@index({ accoundId: 1}, { unique: true }) +@index({ accountId: 1}, { unique: true }) @modelOptions({ schemaOptions: { collection: 'game_user', timestamps: true } }) class GameUserClass extends BaseModule { @prop()