diff options
| author | Factiven <[email protected]> | 2023-04-17 16:17:45 +0700 |
|---|---|---|
| committer | Factiven <[email protected]> | 2023-04-17 16:17:45 +0700 |
| commit | 9a9e892a1f43a61188cfd08ef1faaf5100d0a41a (patch) | |
| tree | 005b6b4e5b786139b266847b6548770f9de6bca3 /pages/api | |
| parent | Update [user].js (diff) | |
| download | moopa-9a9e892a1f43a61188cfd08ef1faaf5100d0a41a.tar.xz moopa-9a9e892a1f43a61188cfd08ef1faaf5100d0a41a.zip | |
4th fixes
Diffstat (limited to 'pages/api')
| -rw-r--r-- | pages/api/get-media.js | 76 | ||||
| -rw-r--r-- | pages/api/get-user.js | 31 | ||||
| -rw-r--r-- | pages/api/update-user.js | 31 | ||||
| -rw-r--r-- | pages/api/watched-episode.js | 43 |
4 files changed, 0 insertions, 181 deletions
diff --git a/pages/api/get-media.js b/pages/api/get-media.js deleted file mode 100644 index 8558f63..0000000 --- a/pages/api/get-media.js +++ /dev/null @@ -1,76 +0,0 @@ -export default async function handler(req, res) { - const { username, status } = req.query; - - try { - const response = await fetch("https://graphql.anilist.co/", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - query: ` - query ($username: String, $status: MediaListStatus) { - MediaListCollection(userName: $username, type: ANIME, status: $status, sort: SCORE_DESC) { - user { - id - name - about (asHtml: true) - createdAt - avatar { - large - } - statistics { - anime { - count - episodesWatched - meanScore - minutesWatched - } - } - bannerImage - mediaListOptions { - animeList { - sectionOrder - } - } - } - lists { - status - name - entries { - id - mediaId - status - progress - score - media { - id - status - title { - english - romaji - } - episodes - coverImage { - large - } - } - } - } - } - } - `, - variables: { - username, - status, - }, - }), - }); - - const data = await response.json(); - res.status(200).json(data.data.MediaListCollection); - } catch (error) { - console.error(error); - res.status(500).json({ message: "Internal server error" }); - } -} diff --git a/pages/api/get-user.js b/pages/api/get-user.js deleted file mode 100644 index 94ec845..0000000 --- a/pages/api/get-user.js +++ /dev/null @@ -1,31 +0,0 @@ -import clientPromise from "../../lib/mongodb"; - -export async function getUser(userId) { - const client = await clientPromise; - const db = client.db("authbase"); - - const collection = db.collection("users"); - const user = await collection.findOne({ id: userId }); - - if (user && user._id) { - user._id = String(user._id); - } - - return user; -} - -export default async function handler(req, res) { - const { userId } = req.query; - - if (!userId) { - return res.status(400).json({ message: "User ID is required" }); - } - - const user = await getUser(userId); - - if (!user) { - return res.status(404).json({ message: "User not found" }); - } - - res.status(200).json(user); -} diff --git a/pages/api/update-user.js b/pages/api/update-user.js deleted file mode 100644 index 67c80d0..0000000 --- a/pages/api/update-user.js +++ /dev/null @@ -1,31 +0,0 @@ -// pages/api/update-user.js -import clientPromise from "../../lib/mongodb"; - -export default async function handler(req, res) { - const client = await clientPromise; - const db = client.db("authbase"); - const collection = db.collection("users"); - - const { name, newData } = req.body; // id is the user ID and newData is the new data you want to set - - try { - const existingData = await collection.findOne({ - name: name, - "recentWatch.id": newData.recentWatch.id, - }); - - if (existingData) { - res.status(200).json({ message: "Data already exists" }); - return; - } - - const result = await collection.updateOne( - { name: name }, - { $addToSet: newData } - ); - - res.status(200).json(result); - } catch (error) { - res.status(500).json({ error: "Unable to update user data" }); - } -} diff --git a/pages/api/watched-episode.js b/pages/api/watched-episode.js deleted file mode 100644 index 271348d..0000000 --- a/pages/api/watched-episode.js +++ /dev/null @@ -1,43 +0,0 @@ -// pages/api/update-user.js -import clientPromise from "../../lib/mongodb"; - -export default async function handler(req, res) { - const client = await clientPromise; - const db = client.db("authbase"); - const collection = db.collection("users"); - - const { username, id, newData } = req.body; // id is the user ID and newData is the new data you want to set - - try { - const result = await collection.updateOne( - { - name: username, - "recentWatch.id": id, - "recentWatch.episode.id": { $ne: newData.id }, - }, - { $addToSet: { "recentWatch.$.episode": newData } } - ); - - if (result.modifiedCount === 0) { - const updateResult = await collection.updateOne( - { - name: username, - "recentWatch.id": id, - "recentWatch.episode.id": newData.id, - "recentWatch.episode.time": { $ne: newData.time }, - }, - { $set: { "recentWatch.$.episode.$[elem].time": newData.time } }, - { arrayFilters: [{ "elem.id": newData.id }] } - ); - if (updateResult.modifiedCount === 0) { - console.log("The episode already exists with the same time."); - } - } - - console.log("Successfully updated the recentWatch collection."); - - res.status(200).json(result); - } catch (error) { - res.status(500).json({ error: "Unable to update user data", dat: newData }); - } -} |