Added tag support + Post link and many more changes and optimizations.

This commit is contained in:
Daniel
2023-02-24 21:02:28 +03:30
parent e0f4c71eb2
commit 9b53608097
36 changed files with 1062 additions and 176 deletions
+3 -3
View File
@@ -2,13 +2,13 @@ import type { NextApiRequest, NextApiResponse } from "next";
import { getServerSession } from "next-auth/next";
import { authOptions } from "pages/api/auth/[...nextauth]";
import getCollections from "@/lib/api/controllers/collections/getCollections";
import postCollections from "@/lib/api/controllers/collections/postCollection";
import postCollection from "@/lib/api/controllers/collections/postCollection";
type Data = {
response: object[] | string;
};
export default async function handler(
export default async function (
req: NextApiRequest,
res: NextApiResponse<Data>
) {
@@ -20,5 +20,5 @@ export default async function handler(
if (req.method === "GET") return await getCollections(req, res, session);
if (req.method === "POST") return await postCollections(req, res, session);
if (req.method === "POST") return await postCollection(req, res, session);
}
+24
View File
@@ -0,0 +1,24 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { getServerSession } from "next-auth/next";
import { authOptions } from "pages/api/auth/[...nextauth]";
import postLink from "@/lib/api/controllers/links/postLink";
type Data = {
response: object[] | string;
};
export default async function (
req: NextApiRequest,
res: NextApiResponse<Data>
) {
const session = await getServerSession(req, res, authOptions);
if (!session?.user?.email) {
return res.status(401).json({ response: "You must be logged in." });
}
// Check if user is unauthorized to the collection (If isn't owner or doesn't has the required permission...)
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (req.method === "POST") return await postLink(req, res, session);
}
+21
View File
@@ -0,0 +1,21 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { getServerSession } from "next-auth/next";
import { authOptions } from "pages/api/auth/[...nextauth]";
import getTags from "@/lib/api/controllers/tags/getTags";
type Data = {
response: object[] | string;
};
export default async function (
req: NextApiRequest,
res: NextApiResponse<Data>
) {
const session = await getServerSession(req, res, authOptions);
if (!session?.user?.email) {
return res.status(401).json({ response: "You must be logged in." });
}
if (req.method === "GET") return await getTags(req, res, session);
}