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 83a26f1 commit fa04706
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 4 additions & 0 deletions server/models/contests/getModeratorContests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ function getModeratorContests({ username, query }) {
const cursor = Number(query.cursor)
let sqlQuery = `SELECT * FROM contests c JOIN contests_moderators cm ON c.id=cm.contest_id WHERE cm.moderator=? `
let arr = [username]
if (cursor) {
sqlQuery += `AND c.id>? `
arr.push(cursor)
}
if (limit && limit > 0) {
sqlQuery += ` LIMIT ?`
arr.push(limit)
Expand Down
8 changes: 3 additions & 5 deletions server/models/contests/participate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ function participate({ params, username }) {
}
connection.beginTransaction((error) => {
if (error) {
return connection.rollback(() => {
connection.release()
return reject(error)
})
connection.release()
return reject(error)
}
connection.query(
`INSERT INTO contests_participants (contest_id, participant) SELECT ?, ?
WHERE EXISTS(SELECT 1 FROM user_groups WHERE username=? AND group_id = ANY (SELECT group_id FROM contests_groups WHERE contest_id=?))`,
WHERE EXISTS(SELECT 1 FROM user_groups ug INNER JOIN contests_groups cg ON ug.group_id = cg.group_id WHERE ug.username=? AND cg.contest_id=?)`,
[contestId, username, username, contestId],
(error, res) => {
if (error || res === undefined) {
Expand Down

0 comments on commit fa04706

Please sign in to comment.