mirror of
https://github.com/nfonteyne/octane-website.git
synced 2026-09-03 23:24:48 +02:00
update: fix hidden filter in calendar and add text zone for tutorials in repertory
This commit is contained in:
parent
678b81e790
commit
44dacf4196
5 changed files with 80 additions and 12 deletions
3
src/db/migrations/017_song_tutorial_content.sql
Normal file
3
src/db/migrations/017_song_tutorial_content.sql
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE song_tutorials
|
||||
ALTER COLUMN url DROP NOT NULL,
|
||||
ADD COLUMN content TEXT;
|
||||
|
|
@ -48,7 +48,7 @@ async function remove(id) {
|
|||
async function findTutorials(songId) {
|
||||
const { rows } = await pool.query(
|
||||
`SELECT st.id, st.song_id, st.instrument_id, i.name AS instrument_name,
|
||||
st.url, st.label, st.added_by, st.created_at
|
||||
st.url, st.content, st.label, st.added_by, st.created_at
|
||||
FROM song_tutorials st
|
||||
JOIN instruments i ON i.id = st.instrument_id
|
||||
WHERE st.song_id = $1
|
||||
|
|
@ -58,12 +58,12 @@ async function findTutorials(songId) {
|
|||
return rows;
|
||||
}
|
||||
|
||||
async function addTutorial(songId, { instrumentId, url, label, addedBy }) {
|
||||
async function addTutorial(songId, { instrumentId, url, content, label, addedBy }) {
|
||||
const { rows } = await pool.query(
|
||||
`INSERT INTO song_tutorials (song_id, instrument_id, url, label, added_by)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING id, song_id, instrument_id, url, label, added_by, created_at`,
|
||||
[songId, instrumentId, url, label || null, addedBy]
|
||||
`INSERT INTO song_tutorials (song_id, instrument_id, url, content, label, added_by)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
RETURNING id, song_id, instrument_id, url, content, label, added_by, created_at`,
|
||||
[songId, instrumentId, url || null, content || null, label || null, addedBy]
|
||||
);
|
||||
return rows[0];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,15 +91,21 @@ router.delete(
|
|||
router.post(
|
||||
'/:id/tutorials',
|
||||
asyncHandler(async (req, res) => {
|
||||
const { instrumentId, url, label } = req.body || {};
|
||||
if (!instrumentId || !url || !url.trim()) {
|
||||
return res.status(400).json({ error: 'instrument_and_url_required' });
|
||||
const { instrumentId, url, content, label } = req.body || {};
|
||||
const trimmedUrl = url && url.trim() ? url.trim() : null;
|
||||
const trimmedContent = content && content.trim() ? content.trim() : null;
|
||||
if (!instrumentId) {
|
||||
return res.status(400).json({ error: 'instrument_required' });
|
||||
}
|
||||
if (!trimmedUrl && !trimmedContent) {
|
||||
return res.status(400).json({ error: 'url_or_content_required' });
|
||||
}
|
||||
const song = await songsRepo.findById(req.params.id);
|
||||
if (!song) return res.status(404).json({ error: 'not_found' });
|
||||
const tutorial = await songsRepo.addTutorial(req.params.id, {
|
||||
instrumentId,
|
||||
url: url.trim(),
|
||||
url: trimmedUrl,
|
||||
content: trimmedContent,
|
||||
label,
|
||||
addedBy: req.user.id,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue