-
DESKTOP-9FO96TP\hehexd authoredDESKTOP-9FO96TP\hehexd authored
route.ts 1.00 KiB
import { Prisma } from "@prisma/client";
import { NextRequest, NextResponse } from "next/server";
import { putLike, putLikeComment } from "./likeService";
import { getServerSession } from "next-auth/next";
import { authOptions } from "@/lib/auth";
import { revalidatePath } from "next/cache";
type like = Prisma.LikeUncheckedCreateInput
export async function PUT(req: NextRequest) {
const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ status: 401 });
}
const userId = session.user.id
const data: like = await req.json()
data.userId = userId;
console.log("router data: " + data, "status:")
try {
if (data.commentId == undefined) {
const msg = await putLike(data)
} else {
putLikeComment(data)
}
const path = req.nextUrl.searchParams.get('path') || '/';
revalidatePath(path);
return NextResponse.json({ status: 200, message: 'Like handled' })
} catch (error) {
console.log("fail" + error);
return NextResponse.json(error, { status: 500 });
}
}