From e2ced33098e1e23c0d895ff27536c7333ae267b5 Mon Sep 17 00:00:00 2001 From: zhl Date: Tue, 27 Apr 2021 14:53:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AD=94=E9=A2=98=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/api.md | 4 ++-- src/api/controllers/puzzle.controller.ts | 8 +++++--- src/models/match/PuzzleSession.ts | 11 +++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 src/models/match/PuzzleSession.ts diff --git a/doc/api.md b/doc/api.md index bf23934..6c0efba 100644 --- a/doc/api.md +++ b/doc/api.md @@ -48,7 +48,7 @@ } ``` -### 1. 获取关卡题目列表 +### 2. 上报题目答案 1. Method: POST 2. URI: /api/:accountid/puzzle/answer @@ -65,6 +65,7 @@ | id | 题目id | | level | 关卡id | | answer | 回答的选项 | +| type | 回答类型, 0: 正常, 1: 超时 | 3. Response: JSON @@ -74,4 +75,3 @@ } ``` - diff --git a/src/api/controllers/puzzle.controller.ts b/src/api/controllers/puzzle.controller.ts index f34707d..8e33818 100644 --- a/src/api/controllers/puzzle.controller.ts +++ b/src/api/controllers/puzzle.controller.ts @@ -33,8 +33,8 @@ class PuzzleController extends BaseController { @role('anon') @router('post /api/:accountid/puzzle/answer') async report(req, res) { - let { id, answer } = req.params - if (!id || !answer) { + let { id, answer, type } = req.params + if (!id) { throw new ZError(11, 'param mismatch') } let record = await Puzzle.findById(id) @@ -42,7 +42,9 @@ class PuzzleController extends BaseController { throw new ZError(12, 'question not found') } let result = record.a1 == answer ? 1 : 0 - + if (type == 1) { + result = 0 + } return {result} } } diff --git a/src/models/match/PuzzleSession.ts b/src/models/match/PuzzleSession.ts new file mode 100644 index 0000000..dae200d --- /dev/null +++ b/src/models/match/PuzzleSession.ts @@ -0,0 +1,11 @@ +import { dbconn } from '../../decorators/dbconn' +import { getModelForClass, modelOptions } from '@typegoose/typegoose' +import { BaseModule } from '../Base' + +@dbconn('second') +@modelOptions({ schemaOptions: { collection: 'question_category' } }) +class PuzzleSessionClass extends BaseModule { + +} + +export const PuzzleSession = getModelForClass(PuzzleSessionClass, { existingConnection: PuzzleSessionClass.db })