@@ -3,7 +3,10 @@ import { LinkRequestQuery } from "@/types/global";
|
||||
import getDashboardData from "@/lib/api/controllers/dashboard/getDashboardData";
|
||||
import verifyUser from "@/lib/api/verifyUser";
|
||||
|
||||
export default async function links(req: NextApiRequest, res: NextApiResponse) {
|
||||
export default async function dashboard(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
) {
|
||||
const user = await verifyUser({ req, res });
|
||||
if (!user) return;
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import verifyByCredentials from "@/lib/api/verifyByCredentials";
|
||||
import createSession from "@/lib/api/controllers/session/createSession";
|
||||
|
||||
export default async function session(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
) {
|
||||
const { username, password, sessionName } = req.body;
|
||||
|
||||
const user = await verifyByCredentials({ username, password });
|
||||
|
||||
if (!user)
|
||||
return res.status(400).json({
|
||||
response:
|
||||
"Invalid credentials. You might need to reset your password if you're sure you already signed up with the current username/email.",
|
||||
});
|
||||
|
||||
if (req.method === "POST") {
|
||||
const token = await createSession(user.id, sessionName);
|
||||
return res.status(token.status).json({ response: token.response });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { LinkRequestQuery } from "@/types/global";
|
||||
import getDashboardDataV2 from "@/lib/api/controllers/dashboard/getDashboardDataV2";
|
||||
import verifyUser from "@/lib/api/verifyUser";
|
||||
|
||||
export default async function dashboard(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
) {
|
||||
const user = await verifyUser({ req, res });
|
||||
if (!user) return;
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
const data = await getDashboardDataV2(user.id, convertedData);
|
||||
return res.status(data.status).json({
|
||||
data: {
|
||||
links: data.data.links,
|
||||
numberOfPinnedLinks: data.data.numberOfPinnedLinks,
|
||||
},
|
||||
message: data.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user