update: visual update, phone responsive, db migration

This commit is contained in:
Nathan FONTEYNE 2026-07-08 11:50:12 +02:00
parent 73ebd6ad49
commit e97aa2c6c3
16 changed files with 894 additions and 244 deletions

View file

@ -2,7 +2,7 @@ const pool = require('../db/pool');
async function findAll() {
const { rows } = await pool.query(`
SELECT s.id, s.title, s.artist, s.notes, s.created_at,
SELECT s.id, s.title, s.artist, s.notes, s.youtube_url, s.spotify_url, s.created_at,
COUNT(st.id)::int AS tutorial_count
FROM songs s
LEFT JOIN song_tutorials st ON st.song_id = s.id
@ -14,28 +14,29 @@ async function findAll() {
async function findById(id) {
const { rows } = await pool.query(
'SELECT id, title, artist, notes, added_by, created_at, updated_at FROM songs WHERE id = $1',
`SELECT id, title, artist, notes, youtube_url, spotify_url, added_by, created_at, updated_at
FROM songs WHERE id = $1`,
[id]
);
return rows[0] || null;
}
async function create({ title, artist, notes, addedBy }) {
async function create({ title, artist, notes, youtubeUrl, spotifyUrl, addedBy }) {
const { rows } = await pool.query(
`INSERT INTO songs (title, artist, notes, added_by)
VALUES ($1, $2, $3, $4)
RETURNING id, title, artist, notes, added_by, created_at, updated_at`,
[title, artist, notes || null, addedBy]
`INSERT INTO songs (title, artist, notes, youtube_url, spotify_url, added_by)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id, title, artist, notes, youtube_url, spotify_url, added_by, created_at, updated_at`,
[title, artist, notes || null, youtubeUrl || null, spotifyUrl || null, addedBy]
);
return rows[0];
}
async function update(id, { title, artist, notes }) {
async function update(id, { title, artist, notes, youtubeUrl, spotifyUrl }) {
const { rows } = await pool.query(
`UPDATE songs SET title = $2, artist = $3, notes = $4, updated_at = now()
`UPDATE songs SET title = $2, artist = $3, notes = $4, youtube_url = $5, spotify_url = $6, updated_at = now()
WHERE id = $1
RETURNING id, title, artist, notes, added_by, created_at, updated_at`,
[id, title, artist, notes || null]
RETURNING id, title, artist, notes, youtube_url, spotify_url, added_by, created_at, updated_at`,
[id, title, artist, notes || null, youtubeUrl || null, spotifyUrl || null]
);
return rows[0] || null;
}

View file

@ -2,7 +2,7 @@ const pool = require('../db/pool');
async function findAll() {
const { rows } = await pool.query(`
SELECT sg.id, sg.title, sg.artist, sg.youtube_url, sg.status, sg.promoted_song_id,
SELECT sg.id, sg.title, sg.artist, sg.youtube_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
@ -17,7 +17,7 @@ async function findAll() {
async function findById(id) {
const { rows } = await pool.query(
`SELECT sg.id, sg.title, sg.artist, sg.youtube_url, sg.status, sg.promoted_song_id,
`SELECT sg.id, sg.title, sg.artist, sg.youtube_url, sg.description, sg.status, sg.promoted_song_id,
sg.created_at, sg.suggested_by, u.name AS suggested_by_name
FROM suggestions sg
JOIN users u ON u.id = sg.suggested_by
@ -39,12 +39,12 @@ async function findVotes(suggestionId) {
return rows;
}
async function create({ title, artist, youtubeUrl, suggestedBy }) {
async function create({ title, artist, youtubeUrl, description, suggestedBy }) {
const { rows } = await pool.query(
`INSERT INTO suggestions (title, artist, youtube_url, suggested_by)
VALUES ($1, $2, $3, $4)
RETURNING id, title, artist, youtube_url, status, promoted_song_id, created_at, suggested_by`,
[title, artist || null, youtubeUrl, suggestedBy]
`INSERT INTO suggestions (title, artist, youtube_url, description, suggested_by)
VALUES ($1, $2, $3, $4, $5)
RETURNING id, title, artist, youtube_url, description, status, promoted_song_id, created_at, suggested_by`,
[title, artist || null, youtubeUrl, description || null, suggestedBy]
);
return rows[0];
}
@ -52,7 +52,7 @@ async function create({ title, artist, youtubeUrl, suggestedBy }) {
async function updateStatus(id, status) {
const { rows } = await pool.query(
`UPDATE suggestions SET status = $2, updated_at = now() WHERE id = $1
RETURNING id, title, artist, youtube_url, status, promoted_song_id, created_at, suggested_by`,
RETURNING id, title, artist, youtube_url, description, status, promoted_song_id, created_at, suggested_by`,
[id, status]
);
return rows[0] || null;
@ -94,10 +94,10 @@ async function promoteToSong(suggestionId, addedBy) {
return null;
}
const { rows: songRows } = await client.query(
`INSERT INTO songs (title, artist, added_by)
VALUES ($1, $2, $3)
RETURNING id, title, artist, notes, added_by, created_at, updated_at`,
[suggestion.title, suggestion.artist || suggestion.title, addedBy]
`INSERT INTO songs (title, artist, notes, youtube_url, added_by)
VALUES ($1, $2, $3, $4, $5)
RETURNING id, title, artist, notes, youtube_url, spotify_url, added_by, created_at, updated_at`,
[suggestion.title, suggestion.artist || suggestion.title, suggestion.description, suggestion.youtube_url, addedBy]
);
const song = songRows[0];
await client.query(