Browse Source

feat: 增加练习题成功时加分的异常判断。

pull/6/head
zjz1993 6 years ago
parent
commit
82f5e26836
  1. 15
      modules/practice.js

15
modules/practice.js

@ -23,7 +23,7 @@ app.get('/practice', async (req, res) => {
let userQuery = await User.createQueryBuilder();
const userId = res.locals.user.id;
let currentPId = await getUserInfo(userId);
const test = [];
const unFinishedIdArray = [];
if (!currentPId) {
// 用户第一次进入练习板块
await userQuery.update(User).set({current_p_id: 1}).where("id = :id", { id:userId }).execute();
@ -42,8 +42,8 @@ app.get('/practice', async (req, res) => {
}
});
}
if (test.length !== 0) {
const minOrder = Math.min.apply(null,test);
if (unFinishedIdArray.length !== 0) {
const minOrder = Math.min.apply(null,unFinishedIdArray);
currentPId = minOrder;
await userQuery.update(User).set({current_p_id: minOrder}).where("id = :id", { id:userId }).execute();
}
@ -57,10 +57,11 @@ app.get('/practice', async (req, res) => {
item.isNow = item.order === currentPId;
});
let userACArray = await utopQuery.where('u_id=:u_id',{u_id:userId}).andWhere("is_finished=1").getMany();
const originRating = syzoj.config.default.user.rating;
const newRating = originRating + userACArray.length * syzoj.config.practice_rating;
await userQuery.update(User).set({rating: newRating}).where('id=:u_id',{u_id:userId}).execute();
if (syzoj.config.practice_rating) {
const originRating = syzoj.config.default.user.rating;
const newRating = originRating + userACArray.length * syzoj.config.practice_rating;
await userQuery.update(User).set({rating: newRating}).where('id=:u_id',{u_id:userId}).execute();
}
res.render('practice', {
user:res.locals.user,
result,

Loading…
Cancel
Save