Skip to content

Commit

Permalink
Update server/models/contests/getModeratorContests.js
Browse files Browse the repository at this point in the history
Co-authored-by: NIKHIL BN <[email protected]>
  • Loading branch information
ridhishjain and NBNARADHYA committed Dec 17, 2020
1 parent 779d252 commit d74463c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions server/models/contests/getAllParticipantsDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ function getAllParticipantsDetails({ username, params }) {
return new Promise((resolve, reject) => {
const { contest_id: contestId } = params
pool.query(
`SELECT username, full_name, admission_number, email, mobile, department, course, admission_year, profile_img FROM users
INNER JOIN contests_participants ON users.username=contests_participants.participant
WHERE EXISTS(SELECT 1 FROM contests_moderators WHERE contest_id=? AND moderator=?) AND contest_id=?`,
`SELECT username, full_name, admission_number, email, mobile, department, course, admission_year, profile_img FROM users u
INNER JOIN contests_participants cp ON u.username = cp.participant
WHERE EXISTS(SELECT 1 FROM contests_moderators WHERE contest_id=? AND moderator=?) AND cp.contest_id=?`,
[contestId, username, contestId],
(error, results) => {
if (error || results === undefined) {
Expand Down
4 changes: 2 additions & 2 deletions server/models/contests/getContest.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ function getContest({ username, params }) {
const { contest_id: contestId } = params
pool.query(
`SELECT * FROM contests WHERE id=?
AND (public=1 OR EXISTS(SELECT 1 FROM user_groups WHERE username=?
AND group_id = ANY (SELECT group_id FROM contests_groups WHERE contest_id=?)))`,
AND (public=1 OR EXISTS(SELECT 1 FROM contests_groups cg INNER JOIN user_groups ug ON cg.group_id = ug.group_id
WHERE ug.username=? AND cg.contest_id=?))`,
[contestId, username, contestId],
(error, results) => {
if (error || results === undefined) {
Expand Down
4 changes: 2 additions & 2 deletions server/models/contests/getContests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function getContests({ username, query }) {
return new Promise((resolve, reject) => {
pool.query(
`SELECT * FROM contests
WHERE (public=1 OR EXISTS(SELECT 1 FROM user_groups WHERE username=?
AND group_id = ANY (SELECT group_id FROM contests_groups WHERE contest_id=id)))
WHERE (public=1 OR EXISTS(SELECT 1 FROM contests_groups cg INNER JOIN user_groups ug
ON cg.group_id = ug.group_id WHERE ug.username=?))
ORDER BY end_time`,
[username],
(error, results) => {
Expand Down
2 changes: 1 addition & 1 deletion server/models/contests/getModeratorContests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { pool } = require('../../models/database')
function getModeratorContests({ username, query }) {
return new Promise((resolve, reject) => {
const limit = Number(query.limit)
let sqlQuery = `SELECT * FROM contests WHERE id IN (SELECT contest_id FROM contests_moderators WHERE moderator=?)`
let sqlQuery = `SELECT * FROM contests c JOIN contests_moderators cm ON c.id=cm.contest_id WHERE cm.moderator=? `
let arr = [username]
if (limit && limit > 0) {
sqlQuery += ` LIMIT ?`
Expand Down

0 comments on commit d74463c

Please sign in to comment.