bugfix: 修改因为练习阶段题目变动造成的无法进入下一阶段的问题 #4

Merged
zhaojunzhe merged 1 commits from feat-replace-cdn into master 3 years ago
  1. 17
      modules/practice.js

17
modules/practice.js

@ -38,12 +38,17 @@ app.get('/practice', async (req, res) => {
await result.forEachAsync(async resultItem => {
const c_id = resultItem.id;
let utopInfo = await utopQuery.where('c_id=:c_id',{c_id}).andWhere('u_id=:u_id',{u_id:userId}).andWhere("is_finished=1").getMany();
resultItem.ac_num = utopInfo.length || 0;
if (resultItem.ac_num === resultItem.problem_num) {
if (resultItem.order < result.length ) {
currentPId = resultItem.order + 1
await userQuery.update(User).set({current_p_id: currentPId}).where("id = :id", { id:userId }).execute();
}
let ctopQuery = CToP.createQueryBuilder();
const classifyProblems = await ctopQuery.where("c_id = :id", { id:resultItem.id }).getMany();
const classifyProblemsArr = classifyProblems.map(item => item.p_id);
const utopInfoArr = utopInfo.map(item => item.p_id);
const restArr = classifyProblemsArr.filter(item => !utopInfoArr.includes(item));
// 当前阶段里已经练习的题目的数量
const currentPassProblemNum = classifyProblemsArr.filter(item => utopInfoArr.includes(item));
resultItem.ac_num = currentPassProblemNum.length || 0;
if (restArr.length === 0) {
currentPId = resultItem.order + 1
await userQuery.update(User).set({current_p_id: currentPId}).where("id = :id", { id:userId }).execute();
} else {
unFinishedIdArray.push(resultItem.order);
}

Loading…
Cancel
Save