el.xwx.moe/pages/api/routes/collections/index.ts

25 lines
808 B
TypeScript
Raw Normal View History

2023-02-06 11:59:23 -06:00
import type { NextApiRequest, NextApiResponse } from "next";
import { getServerSession } from "next-auth/next";
import { authOptions } from "pages/api/auth/[...nextauth]";
2023-02-18 21:32:02 -06:00
import getCollections from "@/lib/api/controllers/collections/getCollections";
import postCollections from "@/lib/api/controllers/collections/postCollection";
2023-02-06 11:59:23 -06:00
type Data = {
2023-02-08 15:11:33 -06:00
response: object[] | string;
2023-02-06 11:59:23 -06:00
};
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
const session = await getServerSession(req, res, authOptions);
2023-02-08 15:11:33 -06:00
if (!session?.user?.email) {
return res.status(401).json({ response: "You must be logged in." });
2023-02-06 11:59:23 -06:00
}
2023-02-18 21:32:02 -06:00
if (req.method === "GET") return await getCollections(req, res, session);
2023-02-06 11:59:23 -06:00
2023-02-18 21:32:02 -06:00
if (req.method === "POST") return await postCollections(req, res, session);
2023-02-06 11:59:23 -06:00
}