From d74463c011a38043369378e2e47885f6aba236e8 Mon Sep 17 00:00:00 2001 From: ridhishjain Date: Thu, 17 Dec 2020 15:41:13 +0530 Subject: [PATCH] Update server/models/contests/getModeratorContests.js Co-authored-by: NIKHIL BN <45630095+NBNARADHYA@users.noreply.github.com> --- server/models/contests/getAllParticipantsDetails.js | 6 +++--- server/models/contests/getContest.js | 4 ++-- server/models/contests/getContests.js | 4 ++-- server/models/contests/getModeratorContests.js | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) 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 ?`