2023-10-23 09:45:48 -05:00
|
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
import { LinkRequestQuery } from "@/types/global";
|
|
|
|
import getDashboardData from "@/lib/api/controllers/dashboard/getDashboardData";
|
2023-11-02 13:59:31 -05:00
|
|
|
import authenticateUser from "@/lib/api/authenticateUser";
|
2023-10-23 09:45:48 -05:00
|
|
|
|
|
|
|
export default async function links(req: NextApiRequest, res: NextApiResponse) {
|
2023-11-02 13:59:31 -05:00
|
|
|
const user = await authenticateUser({ req, res });
|
|
|
|
if (!user) return res.status(404).json({ response: "User not found." });
|
2023-10-23 09:45:48 -05:00
|
|
|
|
|
|
|
if (req.method === "GET") {
|
|
|
|
const convertedData: LinkRequestQuery = {
|
|
|
|
sort: Number(req.query.sort as string),
|
|
|
|
cursor: req.query.cursor ? Number(req.query.cursor as string) : undefined,
|
|
|
|
};
|
|
|
|
|
2023-11-02 13:59:31 -05:00
|
|
|
const links = await getDashboardData(user.id, convertedData);
|
2023-10-23 09:45:48 -05:00
|
|
|
return res.status(links.status).json({ response: links.response });
|
|
|
|
}
|
|
|
|
}
|