mirror of
https://github.com/nfonteyne/octane-website.git
synced 2026-09-03 23:24:48 +02:00
update: approve or disaprove suggrestions by sweeping
This commit is contained in:
parent
061df3b1c6
commit
e368a8681b
5 changed files with 566 additions and 54 deletions
|
|
@ -1,17 +1,20 @@
|
|||
const pool = require('../db/pool');
|
||||
|
||||
async function findAll() {
|
||||
const { rows } = await pool.query(`
|
||||
SELECT sg.id, sg.title, sg.artist, sg.youtube_url, sg.spotify_url, sg.description, sg.status, sg.promoted_song_id,
|
||||
sg.created_at, sg.suggested_by, u.name AS suggested_by_name,
|
||||
COUNT(*) FILTER (WHERE v.vote = 'approve')::int AS approve_count,
|
||||
COUNT(*) FILTER (WHERE v.vote = 'reject')::int AS reject_count
|
||||
FROM suggestions sg
|
||||
JOIN users u ON u.id = sg.suggested_by
|
||||
LEFT JOIN suggestion_votes v ON v.suggestion_id = sg.id
|
||||
GROUP BY sg.id, u.name
|
||||
ORDER BY sg.created_at DESC
|
||||
`);
|
||||
async function findAll(userId) {
|
||||
const { rows } = await pool.query(
|
||||
`SELECT sg.id, sg.title, sg.artist, sg.youtube_url, sg.spotify_url, sg.description, sg.status, sg.promoted_song_id,
|
||||
sg.created_at, sg.suggested_by, u.name AS suggested_by_name,
|
||||
COUNT(*) FILTER (WHERE v.vote = 'approve')::int AS approve_count,
|
||||
COUNT(*) FILTER (WHERE v.vote = 'reject')::int AS reject_count,
|
||||
mv.vote AS my_vote, mv.comment AS my_vote_comment
|
||||
FROM suggestions sg
|
||||
JOIN users u ON u.id = sg.suggested_by
|
||||
LEFT JOIN suggestion_votes v ON v.suggestion_id = sg.id
|
||||
LEFT JOIN suggestion_votes mv ON mv.suggestion_id = sg.id AND mv.user_id = $1
|
||||
GROUP BY sg.id, u.name, mv.vote, mv.comment
|
||||
ORDER BY sg.created_at DESC`,
|
||||
[userId]
|
||||
);
|
||||
return rows;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ const router = express.Router();
|
|||
router.get(
|
||||
'/',
|
||||
asyncHandler(async (req, res) => {
|
||||
res.json(await suggestionsRepo.findAll());
|
||||
res.json(await suggestionsRepo.findAll(req.user.id));
|
||||
})
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue