修改挑战题目的获取逻辑
This commit is contained in:
parent
d9c533f146
commit
be0cb09b7b
@ -31,17 +31,27 @@ class ExamController extends BaseController {
|
||||
throw new ZError(11, '暂时没有可参加的挑战')
|
||||
}
|
||||
let params = {}
|
||||
if (record.qtypes && record.qtypes.length > 0) {
|
||||
params = {$or: [{tag: {$in: record.qtypes}}, {sub_tag: {$in: record.qtypes}}]}
|
||||
}
|
||||
let questions = await Puzzle.randomQuestions(params, record.qcount)
|
||||
let results: any[] = []
|
||||
let history = new PuzzleSession({ shop, level: 0})
|
||||
if (record.source === 0) {
|
||||
if (record.qtypes && record.qtypes.length > 0) {
|
||||
params = {$or: [{tag: {$in: record.qtypes}}, {sub_tag: {$in: record.qtypes}}]}
|
||||
}
|
||||
let questions = await Puzzle.randomQuestions(params, record.qcount)
|
||||
results = transformRecord(questions)
|
||||
for (let _r of questions) {
|
||||
history.questions.set(_r.id, _r.a1)
|
||||
}
|
||||
} else {
|
||||
results = record.transQuestion()
|
||||
for (let _r of record.questions) {
|
||||
history.questions.set(_r._id + '', _r.a1)
|
||||
}
|
||||
}
|
||||
let stat = new PuzzleStatusClass()
|
||||
stat.timeLast = now
|
||||
history.members.set(accountid, stat)
|
||||
for (let record of questions) {
|
||||
history.questions.set(record.id, record.a1)
|
||||
}
|
||||
|
||||
history.expire = Date.now() + (record.qcount * record.timeone || 90) * 1000
|
||||
history.type = 2
|
||||
history.total = record.qcount
|
||||
@ -49,7 +59,6 @@ class ExamController extends BaseController {
|
||||
history.difficultyMode = 0
|
||||
history.qtypes = record.qtypes
|
||||
await history.save()
|
||||
const results = transformRecord(questions)
|
||||
return {
|
||||
session: history.id,
|
||||
records: results,
|
||||
|
@ -7,8 +7,9 @@ import {
|
||||
import { BaseModule } from '../Base'
|
||||
import { noJson } from '../../decorators/nojson'
|
||||
import { Severity } from '@typegoose/typegoose/lib/internal/constants'
|
||||
import { Base } from '@typegoose/typegoose/lib/defaultClasses'
|
||||
|
||||
export class ShopPuzzleClass {
|
||||
export class ShopPuzzleClass extends Base{
|
||||
@prop()
|
||||
public question: string
|
||||
@prop()
|
||||
@ -158,6 +159,26 @@ export class ShopExamClass extends BaseModule {
|
||||
let sort = {_id: -1}
|
||||
return { opt, sort }
|
||||
}
|
||||
|
||||
public transQuestion() {
|
||||
return this.questions.map(o => {
|
||||
let answers = []
|
||||
for (let i = 1; i <= 4; i++) {
|
||||
if (o[`a${ i }`]) {
|
||||
answers.push(o[`a${ i }`])
|
||||
}
|
||||
}
|
||||
answers.randomSort()
|
||||
return {
|
||||
id: o._id,
|
||||
title: o.question,
|
||||
answers,
|
||||
type: 1,
|
||||
category: '自定义',
|
||||
quality: 1
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const ShopExam = getModelForClass(ShopExamClass, { existingConnection: ShopExamClass.db })
|
||||
|
Loading…
x
Reference in New Issue
Block a user