-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a4005a
commit c7829b6
Showing
6 changed files
with
116 additions
and
87 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { getAdminStats, getBuzzes, getLeaderboard, getPlayerList, getProtests, resolveProtest } from '../../../database/geoword.js'; | ||
import { getUserId } from '../../../database/users.js'; | ||
|
||
import { Router } from 'express'; | ||
import { ObjectId } from 'mongodb'; | ||
|
||
const router = Router(); | ||
|
||
router.get('/compare', async (req, res) => { | ||
const { packetName, division, player1, player2 } = req.query; | ||
const player1Buzzes = await getBuzzes(packetName, division, await getUserId(player1)); | ||
const player2Buzzes = await getBuzzes(packetName, division, await getUserId(player2)); | ||
res.json({ player1Buzzes, player2Buzzes }); | ||
}); | ||
|
||
router.get('/leaderboard', async (req, res) => { | ||
const { packetName, division, includeInactive } = req.query; | ||
const leaderboard = await getLeaderboard(packetName, division, includeInactive === 'true'); | ||
res.json({ leaderboard }); | ||
}); | ||
|
||
router.get('/player-list', async (req, res) => { | ||
const { packetName, division } = req.query; | ||
const players = await getPlayerList(packetName, division); | ||
res.json({ players }); | ||
}); | ||
|
||
router.get('/protests', async (req, res) => { | ||
const { packetName, division } = req.query; | ||
const { protests, packet } = await getProtests(packetName, division); | ||
res.json({ protests, packet }); | ||
}); | ||
|
||
router.post('/resolve-protest', async (req, res) => { | ||
const { buzz_id, decision, reason } = req.body; | ||
const result = await resolveProtest(new ObjectId(buzz_id), decision, reason); | ||
|
||
if (result) { | ||
res.sendStatus(200); | ||
} else { | ||
res.sendStatus(500); | ||
} | ||
}); | ||
|
||
router.get('/stats', async (req, res) => { | ||
const { packetName, division } = req.query; | ||
const stats = await getAdminStats(packetName, division); | ||
res.json({ stats }); | ||
}); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import geowordRouter from './geoword.js'; | ||
import listReportsRouter from './list-reports.js'; | ||
import updateSubcategoryRouter from './update-subcategory.js'; | ||
|
||
import { isAdmin } from '../../../database/users.js'; | ||
import { checkToken } from '../../../server/authentication.js'; | ||
|
||
import { Router } from 'express'; | ||
|
||
const router = Router(); | ||
|
||
router.use(async (req, res, next) => { | ||
const { username, token } = req.session; | ||
if (!checkToken(username, token)) { | ||
delete req.session; | ||
res.redirect('/geoword/login'); | ||
return; | ||
} | ||
|
||
const admin = await isAdmin(username); | ||
if (!admin) { | ||
res.status(403).redirect('/user/my-profile'); | ||
return; | ||
} | ||
|
||
next(); | ||
}); | ||
|
||
router.use('/geoword', geowordRouter); | ||
router.use('/list-reports', listReportsRouter); | ||
router.use('/update-subcategory', updateSubcategoryRouter); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getReports } from '../../../database/questions.js'; | ||
|
||
import { Router } from 'express'; | ||
|
||
const router = Router(); | ||
|
||
router.get('/', async (req, res) => { | ||
const { reason } = req.query; | ||
return res.json(await getReports(reason)); | ||
}); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { updateSubcategory } from '../../../database/questions.js'; | ||
|
||
import { Router } from 'express'; | ||
import { ObjectId } from 'mongodb'; | ||
|
||
const router = Router(); | ||
|
||
router.put('/', async (req, res) => { | ||
const { _id, type, subcategory } = req.body; | ||
const result = await updateSubcategory(new ObjectId(_id), type, subcategory); | ||
|
||
if (result) { | ||
res.sendStatus(200); | ||
} else { | ||
res.sendStatus(500); | ||
} | ||
}); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters