Many improvements.

This commit is contained in:
Daniel
2023-03-06 00:33:20 +03:30
parent f3e104aafe
commit cff10fa9b6
19 changed files with 314 additions and 79 deletions
+33
View File
@@ -0,0 +1,33 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { prisma } from "@/lib/api/db";
import { Session } from "next-auth";
export default async function (
req: NextApiRequest,
res: NextApiResponse,
session: Session
) {
const tags = await prisma.link.findMany({
where: {
collection: {
OR: [
{
ownerId: session?.user.id,
},
{
members: {
some: {
userId: session?.user.id,
},
},
},
],
},
},
include: { tags: true },
});
return res.status(200).json({
response: tags || [],
});
}
+5 -15
View File
@@ -1,18 +1,7 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { prisma } from "@/lib/api/db";
import { Session } from "next-auth";
import { Link } from "@prisma/client";
interface LinkObject {
id: number;
name: string;
url: string;
tags: string[];
collectionId: {
id: string | number;
isNew: boolean | undefined;
};
}
import { LinkAndTags, NewLink } from "@/types/global";
export default async function (
req: NextApiRequest,
@@ -24,7 +13,7 @@ export default async function (
}
const email: string = session.user.email;
const link: LinkObject = req?.body;
const link: NewLink = req?.body;
if (!link.name) {
return res
@@ -70,10 +59,10 @@ export default async function (
const collectionId = link.collectionId.id as number;
const createLink: Link = await prisma.link.create({
const createLink: LinkAndTags = await prisma.link.create({
data: {
name: link.name,
url: "https://www.example.com",
url: link.url,
collection: {
connect: {
id: collectionId,
@@ -98,6 +87,7 @@ export default async function (
})),
},
},
include: { tags: true },
});
return res.status(200).json({