Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in unstable (pull request coding-blocks#45)
Browse files Browse the repository at this point in the history
Deploy coding-blocks#43

Approved-by: Varun Hasija <varun.hasija@codingblocks.com>
Varun Hasija committed Feb 20, 2018
2 parents ffe9c08 + 3a27989 commit 474db07
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions routes/users.js
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@ router.get('/:user_id', function (req, res, next) {
router.patch('/:id', UserPolicy.PATCHPolicy, (req,res)=>{
const user = jsonapi.deserialize('user',req.body);
UserService.updateUser(user).then(result=>{
UserService.addToContest(user.b_code,res.locals.user.id)
res.sendStatus(204);
}).catch(function (err) {
jsonapi.error(res, 500, err);
20 changes: 20 additions & 0 deletions services/user.js
Original file line number Diff line number Diff line change
@@ -5,6 +5,9 @@ const User = require('../models/user');
const UserRole = require('../models/user_role');
const Problem = require('../models/problem');
const Submission = require('../models/submission');
const CStudent = require('../models/student_contest');
const Contest = require('../models/contest');
const Raven = require ('raven');

const getUser = function (userId, isMe, isChatModule) {
if (isMe) {
@@ -84,6 +87,23 @@ const updateUser = function (user) {
});
};

const addToContest = function (b_code,userId) {
return Contest.findAll({
where: {batch_code:b_code},
}).then(result => {
let cstudents = []
result.forEach((contest)=>{
cstudents.push({created_by:userId,user_id:userId,contest_id:contest.id});
});
return cstudents;
}).then(cstudents => {
return CStudent.bulkCreate(cstudents, {returning: true});
}).catch(err=>{
Raven.captureException(err);
});
};

exports.addToContest = addToContest;
exports.getUser = getUser;
exports.getUsers = getUsers;
exports.updateUser = updateUser;

0 comments on commit 474db07

Please sign in to comment.