diff --git a/modules/practice.js b/modules/practice.js index 43a6250..a07b8a7 100644 --- a/modules/practice.js +++ b/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,