diff --git a/server/models/contests/getAllParticipantsDetails.js b/server/models/contests/getAllParticipantsDetails.js index a9065ed..f06aa17 100644 --- a/server/models/contests/getAllParticipantsDetails.js +++ b/server/models/contests/getAllParticipantsDetails.js @@ -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) { diff --git a/server/models/contests/getContest.js b/server/models/contests/getContest.js index 3e2448b..2d2e97f 100644 --- a/server/models/contests/getContest.js +++ b/server/models/contests/getContest.js @@ -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) { diff --git a/server/models/contests/getContests.js b/server/models/contests/getContests.js index ba688f7..8b93393 100644 --- a/server/models/contests/getContests.js +++ b/server/models/contests/getContests.js @@ -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) => { diff --git a/server/models/contests/getModeratorContests.js b/server/models/contests/getModeratorContests.js index 0853d83..a61a7b6 100644 --- a/server/models/contests/getModeratorContests.js +++ b/server/models/contests/getModeratorContests.js @@ -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 ?`