aboutsummaryrefslogtreecommitdiff
path: root/prisma
diff options
context:
space:
mode:
authorFactiven <[email protected]>2023-09-13 00:45:53 +0700
committerGitHub <[email protected]>2023-09-13 00:45:53 +0700
commit7327a69b55a20b99b14ee0803d6cf5f8b88c45ef (patch)
treecbcca777593a8cc4b0282e7d85a6fc51ba517e25 /prisma
parentUpdate issue templates (diff)
downloadmoopa-7327a69b55a20b99b14ee0803d6cf5f8b88c45ef.tar.xz
moopa-7327a69b55a20b99b14ee0803d6cf5f8b88c45ef.zip
Update v4 - Merge pre-push to main (#71)
* Create build-test.yml * initial v4 commit * update: github workflow * update: push on branch * Update .github/ISSUE_TEMPLATE/bug_report.md * configuring next.config.js file
Diffstat (limited to 'prisma')
-rw-r--r--prisma/migrations/20230817034249_added_next_episode_for_recent_watch/migration.sql3
-rw-r--r--prisma/migrations/20230821135544_add_dub_to_watchlist/migration.sql2
-rw-r--r--prisma/schema.prisma3
-rw-r--r--prisma/user.js120
4 files changed, 85 insertions, 43 deletions
diff --git a/prisma/migrations/20230817034249_added_next_episode_for_recent_watch/migration.sql b/prisma/migrations/20230817034249_added_next_episode_for_recent_watch/migration.sql
new file mode 100644
index 0000000..45b596a
--- /dev/null
+++ b/prisma/migrations/20230817034249_added_next_episode_for_recent_watch/migration.sql
@@ -0,0 +1,3 @@
+-- AlterTable
+ALTER TABLE "WatchListEpisode" ADD COLUMN "nextId" TEXT,
+ADD COLUMN "nextNumber" INTEGER;
diff --git a/prisma/migrations/20230821135544_add_dub_to_watchlist/migration.sql b/prisma/migrations/20230821135544_add_dub_to_watchlist/migration.sql
new file mode 100644
index 0000000..72e2727
--- /dev/null
+++ b/prisma/migrations/20230821135544_add_dub_to_watchlist/migration.sql
@@ -0,0 +1,2 @@
+-- AlterTable
+ALTER TABLE "WatchListEpisode" ADD COLUMN "dub" BOOLEAN;
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 072415b..040864e 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -24,6 +24,9 @@ model WatchListEpisode {
timeWatched Int?
duration Int?
provider String?
+ nextId String?
+ nextNumber Int?
+ dub Boolean?
createdDate DateTime? @default(now())
userProfile UserProfile @relation(fields: [userProfileId], references: [name], onDelete: Cascade)
userProfileId String
diff --git a/prisma/user.js b/prisma/user.js
index dd61078..c2ba5fd 100644
--- a/prisma/user.js
+++ b/prisma/user.js
@@ -36,64 +36,73 @@ export const createUser = async (name) => {
}
};
-export const updateUser = async (name, anime) => {
+export const updateUser = async (name, setting) => {
try {
- const checkAnime = await prisma.watchListItem.findUnique({
+ const user = await prisma.userProfile.updateMany({
where: {
- title: anime.title,
- userProfileId: name,
+ name: name,
+ },
+ data: {
+ setting,
},
});
- 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;
+ // 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;
- }
+ // return user;
+ // }
} catch (error) {
console.error(error);
throw new Error("Error updating user");
}
};
-export const getUser = async (name) => {
+export const getUser = async (name, list = true) => {
try {
if (!name) {
const user = await prisma.userProfile.findMany({
include: {
- WatchListEpisode: true,
+ WatchListEpisode: list,
},
});
return user;
@@ -200,6 +209,9 @@ export const updateUserEpisode = async ({
timeWatched,
aniTitle,
provider,
+ nextId,
+ nextNumber,
+ dub,
}) => {
try {
const user = await prisma.watchListEpisode.updateMany({
@@ -216,6 +228,9 @@ export const updateUserEpisode = async ({
duration: duration,
episode: number,
timeWatched: timeWatched,
+ nextId: nextId,
+ nextNumber: nextNumber,
+ dub: dub,
createdDate: new Date(),
},
});
@@ -246,6 +261,25 @@ export const deleteEpisode = async (name, id) => {
}
};
+export const deleteList = async (name, id) => {
+ try {
+ const user = await prisma.watchListEpisode.deleteMany({
+ where: {
+ aniId: id,
+ userProfileId: name,
+ },
+ });
+ if (user) {
+ return user;
+ } else {
+ return { message: "Episode not found" };
+ }
+ } catch (error) {
+ console.error(error);
+ throw new Error("Error deleting list");
+ }
+};
+
// export const updateTimeWatched = async (id, timeWatched) => {
// try {
// const user = await prisma.watchListEpisode.update({