Some tests and fixes (TODO fixes)
This commit is contained in:
1 parent
a81ea69a8a
commit
3d1448c6aa
4 files changed
+181
-28
No files matched your search
+14
-14
@@ -3,7 +3,7 @@ import { prisma } from "@/lib/db/prisma";
|
||||
export type DbResponse =
|
||||
| { success: true; status: number, entry: {
|
||||
songId: number | undefined;
|
||||
bookId: number | undefined;
|
||||
songBookId: number | undefined;
|
||||
songNumber: number | undefined
|
||||
}, song: {id: number, title: string} | undefined }
|
||||
| { success: false; status: number; error: string };
|
||||
@@ -17,9 +17,9 @@ export type DbResponse =
|
||||
* @param songNumber - Track/Song number in that specific book
|
||||
* @returns {"success": boolean, "status": number, "entry": {"songId": number, "bookId": number, "songNumber": number}}
|
||||
*/
|
||||
export async function addSongToBook(songId: number, bookId: number, songNumber: number): Promise<DbResponse> {
|
||||
export async function addSongToBook(songId: number, songBookId: number, songNumber: number): Promise<DbResponse> {
|
||||
try {
|
||||
const isTaken = await isSongNumberTaken(bookId, songNumber);
|
||||
const isTaken = await isSongNumberTaken(songBookId, songNumber);
|
||||
if (isTaken) {
|
||||
return { success: false, status: 409, error: "Songnumber already taken in this songbook" };
|
||||
}
|
||||
@@ -27,7 +27,7 @@ export async function addSongToBook(songId: number, bookId: number, songNumber:
|
||||
const entry = await prisma.songBookSongs.create({
|
||||
data: {
|
||||
songId,
|
||||
bookId,
|
||||
songBookId,
|
||||
songNumber,
|
||||
},
|
||||
});
|
||||
@@ -54,18 +54,18 @@ export async function addSongToBook(songId: number, bookId: number, songNumber:
|
||||
* @param data - Object of the new data
|
||||
* @returns {"success": true, "status": number, "entry": {"songId": number, "bookId": number, "songNumber": number}} | {"success": false, "error": string}
|
||||
*/
|
||||
export async function updateSongInBook(songId: number, bookId: number, data: {songNumber: number}) {
|
||||
export async function updateSongInBook(songId: number, songBookId: number, data: {songNumber: number}) {
|
||||
try {
|
||||
const isTaken = await isSongNumberTaken(bookId, data.songNumber);
|
||||
const isTaken = await isSongNumberTaken(songBookId, data.songNumber);
|
||||
if (isTaken) {
|
||||
return { success: false, status: 409, error: "New song number is already taken in this songbook" };
|
||||
}
|
||||
|
||||
const entry = await prisma.songBookSongs.update({
|
||||
where: {
|
||||
songId_bookId: {
|
||||
songBookId_songId: {
|
||||
songId,
|
||||
bookId,
|
||||
songBookId,
|
||||
},
|
||||
},
|
||||
data: {
|
||||
@@ -73,7 +73,7 @@ export async function updateSongInBook(songId: number, bookId: number, data: {so
|
||||
},
|
||||
select: {
|
||||
songId: true,
|
||||
bookId: true,
|
||||
songBookId: true,
|
||||
songNumber: true,
|
||||
},
|
||||
});
|
||||
@@ -103,13 +103,13 @@ export async function updateSongInBook(songId: number, bookId: number, data: {so
|
||||
* @param bookId - ID of the songbook
|
||||
* @returns {"success": boolean, "status": number}
|
||||
*/
|
||||
export async function removeSongFromBook(songId: number, bookId: number) {
|
||||
export async function removeSongFromBook(songId: number, songBookId: number) {
|
||||
try {
|
||||
await prisma.songBookSongs.delete({
|
||||
where: {
|
||||
songId_bookId: {
|
||||
songBookId_songId: {
|
||||
songId,
|
||||
bookId,
|
||||
songBookId,
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -168,11 +168,11 @@ export async function getSongByNumber(bookId: number, songNumber: number) {
|
||||
* @param songNumber - The song number to check
|
||||
* @returns true if taken, false if available
|
||||
*/
|
||||
export async function isSongNumberTaken(bookId: number, songNumber: number): Promise<boolean> {
|
||||
export async function isSongNumberTaken(songBookId: number, songNumber: number): Promise<boolean> {
|
||||
try {
|
||||
const existing = await prisma.songBookSongs.findFirst({
|
||||
where: {
|
||||
bookId,
|
||||
songBookId,
|
||||
songNumber,
|
||||
},
|
||||
select: {
|
||||
|
||||
Reference in new issue
Block a user