tomodachi-share/src/app/api/mii/[id]/like/route.ts
2026-04-17 01:14:58 +01:00

59 lines
1.6 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { auth } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { idSchema } from "@/lib/schemas";
import { RateLimit } from "@/lib/rate-limit";
export async function PATCH(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
// const session = await auth();
// if (!session) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
// const rateLimit = new RateLimit(request, 100, "/api/mii/like");
// const check = await rateLimit.handle();
// if (check) return check;
// const { id: slugId } = await params;
// const parsed = idSchema.safeParse(slugId);
// if (!parsed.success) return rateLimit.sendResponse({ error: parsed.error.issues[0].message }, 400);
// const miiId = parsed.data;
// const result = await prisma.$transaction(async (tx) => {
// const existingLike = await tx.like.findUnique({
// where: {
// userId_miiId: {
// userId: Number(session.user?.id),
// miiId,
// },
// },
// });
// if (existingLike) {
// // Remove the like if it exists
// await tx.like.delete({
// where: {
// userId_miiId: {
// userId: Number(session.user?.id),
// miiId,
// },
// },
// });
// } else {
// // Add a like if it doesn't exist
// await tx.like.create({
// data: {
// userId: Number(session.user?.id),
// miiId,
// },
// });
// }
// const likeCount = await tx.like.count({
// where: { miiId },
// });
// return { liked: !existingLike, count: likeCount };
// });
return NextResponse.json({ success: false });
}