Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Judger rating function is working incorrectly. #8

Open
GooeyNyan opened this issue Nov 8, 2018 · 0 comments
Open

Judger rating function is working incorrectly. #8

GooeyNyan opened this issue Nov 8, 2018 · 0 comments

Comments

@GooeyNyan
Copy link

GooeyNyan commented Nov 8, 2018

Do you want to request a feature or report a bug?

report a bug

What is the current behavior?

Judger side's rating function is not working as expect.

Step to fix it

The addJudgers function was invoked incorrectly.

origin code

// controller/judger.js, from line 122 to 132
judger.post('*/rate/save/:id/', async (ctx, next) => {
    let rate = Number.parseInt(ctx.request.fields.rate);

    if (Number.isInteger(rate) === false || rate < 1 || rate > 10) {
        ctx.body = {status: "error", data: "评分必须是整数并且在1到10之间"};
        return;
    }
    let teamInfo = await ctx.db.Team.findById(ctx.params.id);
    teamInfo.addJudgers(ctx.session.id, {rate: ctx.request.fields.rate});
    ctx.body = {status: "success"};
});

fixed code

// controller/judger.js
judger.post('*/rate/save/:id/', async (ctx, next) => {
    let rate = Number.parseInt(ctx.request.fields.rate);

    if (Number.isInteger(rate) === false || rate < 1 || rate > 10) {
        ctx.body = {status: "error", data: "评分必须是整数并且在1到10之间"};
        return;
    }
    let teamInfo = await ctx.db.Team.findById(ctx.params.id);
    
    // the following line has been changed ⬇️
    teamInfo.addJudgers(ctx.session.id, {through: {rate: rate}});
    
    ctx.body = {status: "success"};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant