修改挑战相关接口

This commit is contained in:
zhl 2021-05-17 13:38:03 +08:00
parent 07d1de0859
commit c5a27e30a2
2 changed files with 7 additions and 3 deletions

View File

@ -215,6 +215,7 @@
| 字段 | 说明 |
| -------- | -------------------------------------- |
| shop | 店铺id, 比如 607ff59d4a4e16687a3b7079 |
| eid | 测验id, 比如 609e13eeccc78154ac683583 |
3. Response: JSON

View File

@ -18,14 +18,17 @@ class ExamController extends BaseController {
@role('anon')
@router('post /api/:accountid/exam/list')
async list(req, res) {
let { shop, accountid } = req.params
let { shop, accountid, eid } = req.params
if (!shop || !isObjectId(shop)) {
throw new ZError(10, '没有店铺id或者店铺id格式不正确, 测试使用: 607ff59d4a4e16687a3b7079')
}
const now = Date.now()
let record = await ShopExam.findOne({shop, beginTime: {$lte: now}, endTime: {$gte: now}, active: true, deleted: false})
if (!eid) {
throw new ZError(12, '需要指定挑战的id')
}
let record = await ShopExam.findById(eid)
if (!record) {
throw new ZError(11, '暂时没有可参加的测试')
throw new ZError(11, '暂时没有可参加的挑战')
}
let params = {}
if (record.qtypes && record.qtypes.length > 0) {