diff --git a/modules/practice.js b/modules/practice.js index 3f8ae34..a87fbd3 100644 --- a/modules/practice.js +++ b/modules/practice.js @@ -204,19 +204,23 @@ app.get('/api/pass/:cid/:pid/:sid',async (req, res) => { let userACArray = await newutopQuery.select("p_id").where('u_id=:u_id',{u_id}).andWhere("is_finished=1").getRawMany(); if (syzoj.config.practice_rating) { const scoreArray = await judgeStateQuery.select("score").addSelect("problem_id").where("user_id=:u_id",{u_id}).andWhere("type=2").andWhere("score>=100").getRawMany(); - let num = 0; - for(let i=0;i item.problem_id === problem_id) - num+=parseInt(item.score); + let newScore = 0; + if (scoreArray && scoreArray.length !== 0) { + let num = 0; + for(let i=0;i item.problem_id === problem_id) + num+=parseInt(item.score); + } + newScore = num - userACArray.length * 100; } - const newScore = num - userACArray.length * 100; const originRating = syzoj.config.default.user.rating; const newRating = originRating + newScore; await userQuery.update(User).set({rating: newRating}).where('id=:u_id',{u_id}).execute(); res.send({newRating: newRating}); } } catch(e) { + console.log(e); res.send({ error_code: e.errno, error_msg: '练习失败,请稍后重试' }); } }); diff --git a/views/submission_practice.ejs b/views/submission_practice.ejs index 6a2ceab..6c83128 100644 --- a/views/submission_practice.ejs +++ b/views/submission_practice.ejs @@ -348,7 +348,7 @@ if (token != null) { console.log("Judge finished"); vueApp.roughData.running = false; vueApp.roughData.result = p.roughResult; - if (p.roughResult.result === 'Accepted') { + if (p.roughResult && p.roughResult.result === 'Accepted') { $.ajax({ url: `/api/pass/${cid}/${pid}/${sid}`, type: 'GET', @@ -384,7 +384,7 @@ if (token != null) { // } // data.running=false; if (data && data.ok) { - if (data.roughResult.result === 'Accepted') { + if (data.roughResult && data.roughResult.result === 'Accepted') { $.ajax({ url: `/api/pass/${cid}/${pid}/${sid}`, type: 'GET',