diff options
| author | Factiven <[email protected]> | 2023-08-12 22:54:26 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-08-12 22:54:26 +0700 |
| commit | 3e78826658c7d2a4e9b3c1d73e63dacc1d39c361 (patch) | |
| tree | d580d03670692c6c5d361ec8559e7a2352354f3a /prisma/user.js | |
| parent | Update v3.9.1 - Merged Beta to Main (#44) (diff) | |
| download | moopa-3.9.3.tar.xz moopa-3.9.3.zip | |
Update v3.9.3 - Merged Beta to Main (#51)v3.9.3
* commit
* update db
* Update v3.9.1-beta-v3.1
* Update v3.9.1
* Fix watched progress not showing
* Secure headers
* Fix recently watched image
* Update v3.9.2
> Added custom lists for AniList
> Fixed episode listMode progress
* Update db route
* Fixed AniList
* Fix next button on dub anime
> video is playing sub anime instead dub
* small adjusment for premid
* fix eslint
* small updates
> added ability to remove episode from recently watched
* Update v3.9.3
Diffstat (limited to 'prisma/user.js')
| -rw-r--r-- | prisma/user.js | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/prisma/user.js b/prisma/user.js index 8c436a5..dd61078 100644 --- a/prisma/user.js +++ b/prisma/user.js @@ -1,9 +1,9 @@ -// import { PrismaClient } from "@prisma/client"; +import { Prisma } from "@prisma/client"; // const prisma = new PrismaClient(); import { prisma } from "../lib/prisma"; -export const createUser = async (name, setting) => { +export const createUser = async (name) => { try { const checkUser = await prisma.userProfile.findUnique({ where: { @@ -22,6 +22,15 @@ export const createUser = async (name, setting) => { return null; } } catch (error) { + if (error instanceof Prisma.PrismaClientKnownRequestError) { + if (error.code === "P2002") { + console.log( + "There is a unique constraint violation, a new user cannot be created with this name" + ); + } + } else if (error instanceof Prisma.PrismaClientUnknownRequestError) { + console.log("An unknown Prisma error occurred:", error.message); + } console.error(error); throw new Error("Error creating user"); } @@ -218,19 +227,38 @@ export const updateUserEpisode = async ({ } }; -export const updateTimeWatched = async (id, timeWatched) => { +export const deleteEpisode = async (name, id) => { try { - const user = await prisma.watchListEpisode.update({ + const user = await prisma.watchListEpisode.deleteMany({ where: { - id: id, - }, - data: { - timeWatched: timeWatched, + watchId: id, + userProfileId: name, }, }); - return user; + if (user) { + return user; + } else { + return { message: "Episode not found" }; + } } catch (error) { console.error(error); - throw new Error("Error updating time watched"); + throw new Error("Error deleting episode"); } }; + +// export const updateTimeWatched = async (id, timeWatched) => { +// try { +// const user = await prisma.watchListEpisode.update({ +// where: { +// id: id, +// }, +// data: { +// timeWatched: timeWatched, +// }, +// }); +// return user; +// } catch (error) { +// console.error(error); +// throw new Error("Error updating time watched"); +// } +// }; |