Skip to content

Commit

Permalink
fix: set badges in achievement sectiion
Browse files Browse the repository at this point in the history
  • Loading branch information
akashgp09 committed Jul 22, 2021
1 parent 66a1b87 commit 5841f8f
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions src/server/routes/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,30 +485,17 @@ async function rankUpdate(orm, editorId, bodyRank, rank) {
}


router.post('/:id/achievements/', auth.isAuthenticated, (req, res) => {
router.post('/:id/achievements/', auth.isAuthenticated, async (req, res) => {
const {orm} = req.app.locals;
const {Editor} = orm;
const userId = parseInt(req.params.id, 10);

async function runAsync() {
if (!isCurrentUser(userId, req.user)) {
throw new Error('Not authenticated');
}

const rankOnePromise = rankUpdate(orm, userId, req.body.rank1, 1);
const rankTwoPromise = rankUpdate(orm, userId, req.body.rank2, 2);
const rankThreePromise = rankUpdate(orm, userId, req.body.rank3, 3);

const rankJSON = await Promise.all([
rankOnePromise, rankTwoPromise, rankThreePromise
]);

res.redirect(`/editor/${req.params.id}`);

return rankJSON;
if (!isCurrentUser(userId, req.user)) {
throw new Error('Not authenticated');
}

handler.sendPromiseResult(res, runAsync());
await rankUpdate(orm, userId, req.body.rank1, 1);
await rankUpdate(orm, userId, req.body.rank2, 2);
await rankUpdate(orm, userId, req.body.rank3, 3);
return res.redirect(`/editor/${req.params.id}`);
});


Expand Down

0 comments on commit 5841f8f

Please sign in to comment.