Added GET and POST routes.

This commit is contained in:
Daniel
2023-02-09 00:41:33 +03:30
parent e5ed2ec5db
commit 0bf1ec0d2a
12 changed files with 198 additions and 36 deletions
+26 -8
View File
@@ -1,10 +1,10 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { getServerSession } from "next-auth/next";
import { authOptions } from "pages/api/auth/[...nextauth]";
import { prisma } from "@/lib/db";
type Data = {
message: string;
data?: object;
response: object[] | string;
};
export default async function handler(
@@ -13,14 +13,32 @@ export default async function handler(
) {
const session = await getServerSession(req, res, authOptions);
if (!session) {
res.status(401).json({ message: "You must be logged in." });
return;
if (!session?.user?.email) {
return res.status(401).json({ response: "You must be logged in." });
}
console.log(session?.user?.email);
const email: string = session.user.email;
return res.json({
message: "Success",
const findCollection = await prisma.user.findFirst({
where: {
email: email,
},
include: {
collections: {
include: {
collection: true,
},
},
},
});
const collections = findCollection?.collections.map((e) => {
return { id: e.collection.id, name: e.collection.name, role: e.role };
});
// console.log(session?.user?.email);
return res.status(200).json({
response: collections || [],
});
}