feat: add abilty to attach song to songbook

This commit is contained in:
robin committed 2026-07-28 15:53:51 +02:00
1 parent 001a0d6ef8
commit e3115df0bd
3 files changed
+46 -14

No files matched your search

+19 -9
View File
@@ -122,16 +122,26 @@ export async function addSongToSongbook(title:string, songbookId:number, number:
export async function attachSongToSongbook(songId: number, songbookId: number, number: string) {
try {
const runTransaction = db.transaction(() => {
db.prepare(`
INSERT OR REPLACE INTO songbook_songs (songbook_id, song_id, song_number)
VALUES (?, ?, ?)
`).run(songbookId, songId, number);
})
runTransaction();
return { success: true }
const songExists = db.prepare("SELECT id FROM songs WHERE id = ?").get(songId);
if (!songExists) {
console.error(`Song mit ID ${songId} existiert nicht in DB.`);
return { success: false, error: "Song nicht gefunden." };
}
const bookExists = db.prepare("SELECT id FROM songbooks WHERE id = ?").get(songbookId);
if (!bookExists) {
console.error(`Songbook mit ID ${songbookId} existiert nicht in DB.`);
return { success: false, error: "Liederbuch nicht gefunden." };
}
db.prepare(`
INSERT OR REPLACE INTO songbook_songs (songbook_id, song_id, song_number)
VALUES (?, ?, ?)
`).run(songbookId, songId, number);
return { success: true };
} catch (error) {
console.error("Error in addSongToSongbook:", error);
console.error("Error in attachSongToSongbook:", error);
return { success: false };
}
}