diff options
| author | Factiven <[email protected]> | 2023-08-09 15:11:53 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-08-09 15:11:53 +0700 |
| commit | bae1f53877c3447d3ba940f823e5a8a097f5b22c (patch) | |
| tree | 98abb195bcad6f3e6c61c76c62fc238f227b0ead /prisma | |
| parent | Update package-lock.json (diff) | |
| download | moopa-3.9.0.tar.xz moopa-3.9.0.zip | |
Update v3.9.0 - Merged Beta to Main (#41)v3.9.0
* initial commit
* Update_v.3.6.7-beta-v1.2
* Update_v.3.6.7-beta-v1.3
* Update_v.3.6.7-beta-v1.3
> update API
* Fixed mediaList won't update
* added .env disqus shortname
* Update_v3.6.7-beta-v1.4
>Implementing database
* Create main.yml
* Update v3.6.7-beta-v1.5
small patch
* title home page
* Update content.js
* Delete db-test.js
* Update content.js
* Update home page card
* Update v3.7.0
* Update v3.7.1-beta
> migrating backend to main code
> fixed schedule component
* Update v3.8.0
> Added dub options
> Moved schedule backend
* Update v.3.8.1
> Fixed episodes on watch page isn't dubbed
* Update v3.8.1-patch-1
* Update v3.8.1-patch-2
> Another patch for dub
* Update v3.8.2
> Removed prisma configuration for database since it's not stable yet
* Update v3.8.3
> Fixed different provider have same id
* Update v.3.8.3
> Fixed player bug where the controls won't hide after updating anilist progress
* Update v3.8.4-patch-2
* Update v3.8.5
> Update readme.md
> Update .env.example
* Update next.config.js
* small adjusment info page
* Update v3.8.6
> Minor update for Android 13 user
* Update v3.8.7
> Added prev and next button to mediaSession
* Update v3.8.7-beta-v2
* Beta v2 (#37)
* Update schema.prisma
* Update schema.prisma
* Update schema.prisma
* Update 3.9.0-beta-v2.1
> Implemented database for storing user Watch List and settings
> Added buttons to auto-play next episodes
* Update v3.9.0-beta-v2.2
* Update README.md
---------
Co-authored-by: Chitraksh Maheshwari <[email protected]>
Diffstat (limited to 'prisma')
| -rw-r--r-- | prisma/schema.prisma | 31 | ||||
| -rw-r--r-- | prisma/user.js | 203 |
2 files changed, 234 insertions, 0 deletions
diff --git a/prisma/schema.prisma b/prisma/schema.prisma new file mode 100644 index 0000000..f336e54 --- /dev/null +++ b/prisma/schema.prisma @@ -0,0 +1,31 @@ +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} + +generator client { + provider = "prisma-client-js" +} + +model UserProfile { + id String @id @default(cuid()) + name String @unique + setting Json? + WatchListEpisode WatchListEpisode[] +} + +model WatchListEpisode { + id String @id @default(cuid()) + aniId String? + title String? + aniTitle String? + image String? + episode Int? + timeWatched Int? + duration Int? + provider String? + createdDate DateTime? @default(now()) + userProfile UserProfile @relation(fields: [userProfileId], references: [name]) + userProfileId String + watchId String +} diff --git a/prisma/user.js b/prisma/user.js new file mode 100644 index 0000000..04222d5 --- /dev/null +++ b/prisma/user.js @@ -0,0 +1,203 @@ +// import { prisma } from "../lib/prisma"; +import { PrismaClient } from "@prisma/client"; +const prisma = new PrismaClient(); + +export const createUser = async (name, setting) => { + const checkUser = await prisma.userProfile.findUnique({ + where: { + name: name, + }, + }); + if (!checkUser) { + const user = await prisma.userProfile.create({ + data: { + name: name, + setting, + }, + }); + + return user; + } else { + return null; + } +}; + +export const updateUser = async (name, anime) => { + const checkAnime = await prisma.watchListItem.findUnique({ + where: { + title: anime.title, + userProfileId: name, + }, + }); + if (checkAnime) { + const checkEpisode = await prisma.watchListEpisode.findUnique({ + where: { + url: anime.id, + }, + }); + if (checkEpisode) { + return null; + } else { + const user = await prisma.watchListItem.update({ + where: { + title: anime.title, + userProfileId: name, + }, + }); + } + } else { + const user = await prisma.userProfile.update({ + where: { name: name }, + data: { + watchList: { + create: { + title: anime.title, + episodes: { + create: { + url: anime.id, + }, + }, + }, + }, + }, + include: { + watchList: true, + }, + }); + + return user; + } +}; + +export const getUser = async (name) => { + if (!name) { + const user = await prisma.userProfile.findMany({ + include: { + WatchListEpisode: true, + }, + }); + return user; + } else { + const user = await prisma.userProfile.findFirst({ + where: { + name: name, + }, + include: { + WatchListEpisode: { + orderBy: { + createdDate: "desc", + }, + }, + }, + }); + return user; + } +}; + +export const deleteUser = async (name) => { + const user = await prisma.userProfile.delete({ + where: { + name: name, + }, + }); + return user; +}; + +export const createList = async (name, id, title) => { + const checkEpisode = await prisma.watchListEpisode.findFirst({ + where: { + userProfileId: name, + watchId: id, + }, + }); + if (checkEpisode) { + return null; + } else { + const episode = await prisma.userProfile.update({ + where: { name: name }, + data: { + WatchListEpisode: { + create: [ + { + watchId: id, + }, + ], + }, + }, + include: { + WatchListEpisode: true, + }, + }); + return episode; + } +}; + +export const getEpisode = async (name, id) => { + console.log({ name, id }); + const episode = await prisma.watchListEpisode.findMany({ + // where: { + // AND: [{ userProfileId: name }, { watchId: id }], + // }, + where: { + AND: [ + { + userProfileId: name, + }, + { + watchId: { + equals: id, + }, + }, + ], + }, + }); + return episode; +}; + +export const updateUserEpisode = async ({ + name, + id, + watchId, + title, + image, + number, + duration, + timeWatched, + aniTitle, + provider, +}) => { + const user = await prisma.watchListEpisode.updateMany({ + where: { + userProfileId: name, + watchId: watchId, + }, + data: { + title: title, + aniTitle: aniTitle, + image: image, + aniId: id, + provider: provider, + duration: duration, + episode: number, + timeWatched: timeWatched, + createdDate: new Date(), + }, + }); + + // const user = name; + + return user; +}; + +export const updateTimeWatched = async (id, timeWatched) => { + const user = await prisma.watchListEpisode.update({ + where: { + id: id, + // userProfileId: name, + }, + data: { + timeWatched: timeWatched, + }, + }); + return user; +}; |