Skip to content

Commit

Permalink
Added Bulk create and Raven.
Browse files Browse the repository at this point in the history
  • Loading branch information
sd5869 committed Feb 20, 2018
1 parent b0a8a25 commit 809cb93
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions services/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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) {
Expand Down Expand Up @@ -90,9 +91,15 @@ const addToContest = function (b_code,userId) {
return Contest.findAll({
where: {batch_code:b_code},
}).then(result => {
return result.forEach((contest)=>{
CStudent.create({created_by:userId,user_id:userId,contest_id:contest.id}, {returning: true});
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);
});
};

Expand Down

0 comments on commit 809cb93

Please sign in to comment.