修正正常模式无法返回系统题库的bug

This commit is contained in:
zhl 2021-05-26 17:22:17 +08:00
parent 146704e11d
commit 6359a43f90
3 changed files with 11 additions and 4 deletions

View File

@ -48,7 +48,7 @@ class ExamController extends BaseController {
let questions = await Puzzle.randomQuestions(params, record.qcount)
results = transformRecord(questions)
for (let _r of questions) {
history.questions.set(_r.id, _r.a1)
history.questions.set(_r.id, _r.compactRecord(true))
}
} else {
results = record.transQuestion()

View File

@ -113,10 +113,17 @@ export class PuzzleClass extends BaseModule {
public static async randomQuestions(this: ReturnModelType<typeof PuzzleClass>, options: any, count: number) {
let filters = {status: 1, is_hide: 0, deleted: 0, dp: 1}
Object.assign(filters, options)
return Puzzle.aggregate([
let records = await Puzzle.aggregate([
{ $match: filters },
{ $sample: { size: count } }
]).exec()
let results = []
for (let record of records) {
let o = new Puzzle({})
Object.assign(o, record)
results.push(o)
}
return results
}
public compactRecord(withAnswer: boolean) {

View File

@ -6,7 +6,7 @@ import {
updateRound,
updateScore
} from './WsSvr'
import { Puzzle } from '../models/content/Puzzle'
import { Puzzle, PuzzleClass } from '../models/content/Puzzle'
import { Schedule } from '../clock/Schedule'
import { BaseConst } from '../constants/BaseConst'
import { PuzzleSession } from '../models/match/PuzzleSession'
@ -22,7 +22,7 @@ import { GameUser } from '../models/GameUser'
export function transformRecord(records: any[]) {
return records.map(o => {
return o.compactRecord(false)
return (o as PuzzleClass).compactRecord(false)
})
}