diff --git a/controllers/assignments.js b/controllers/assignments.js index 402178e..8631922 100644 --- a/controllers/assignments.js +++ b/controllers/assignments.js @@ -90,7 +90,22 @@ function get(req, res) { model: Problem, as: 'problems', attributes: ['id', 'title_es', 'title_en', 'level', 'category_id', 'time_limit'], - through: { attributes: ['id'] } + through: { attributes: ['id'] }, + include: [ + { + model: Submissions, + as: 'submissions', + attributes: ['user_id', 'assignment_problem_id', 'contest_problem_id'], + where: { + user_id: req.user.sub, + verdict: 'Accepted', + assignment_problem_id: { + $ne: null + } + }, + required: false + } + ] } ], attributes: ['id', 'tittle', 'init_date', 'description', 'end_date', 'syllabus_id'] diff --git a/controllers/contests.js b/controllers/contests.js index 121122a..a33b4a6 100644 --- a/controllers/contests.js +++ b/controllers/contests.js @@ -2,6 +2,7 @@ const Contest = require('../models').contests const ContestProblems = require('../models').contests_problems +const Submissions = require('../models').submissions const Problem = require('../models').problems const User = require('../models').users const ContestStudent = require('../models').contests_students @@ -151,7 +152,22 @@ function getProblems(req, res) { model: Problem, as: 'problems', attributes: ['id', 'title_es', 'title_en', 'level'], - through: { attributes: ['id'] } + through: { attributes: ['id'] }, + include: [ + { + model: Submissions, + as: 'submissions', + attributes: ['id','user_id', 'assignment_problem_id', 'contest_problem_id'], + where: { + user_id: req.user.sub, + verdict: 'Accepted', + contest_problem_id: { + $ne: null + } + }, + required: false + } + ] } ] }).then( (contest) => {