- Remove newUser variable and directly return created user from Prisma transaction in register route - Add explicit casts for Prisma QueryMode to avoid TypeScript widening in listings search - Fix items search and getItemBySource with any cast and ts-expect-error to satisfy type checks Improves readability and type safety without changing behavior.
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { secureLogger } from "@/lib/secure-logger";
|
|
import { requireAuth } from "@/lib/auth/middleware";
|
|
import { markAsRead } from "@/lib/prisma/queries/notifications";
|
|
|
|
/**
|
|
* POST /api/notifications/[id]/read
|
|
* Marca uma notificação específica como lida
|
|
*/
|
|
export async function POST(
|
|
request: NextRequest,
|
|
{ params }: { params: Promise<{ id: string }> }
|
|
) {
|
|
try {
|
|
const authResult = await requireAuth(request);
|
|
if (authResult instanceof NextResponse) return authResult;
|
|
const auth = authResult;
|
|
|
|
const { id } = await params;
|
|
const notificationId = parseInt(id, 10);
|
|
if (isNaN(notificationId)) {
|
|
return NextResponse.json(
|
|
{ success: false, error: "ID de notificação inválido" },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
const success = await markAsRead(notificationId, auth.userId);
|
|
|
|
if (!success) {
|
|
return NextResponse.json(
|
|
{ success: false, error: "Notificação não encontrada ou já está lida" },
|
|
{ status: 404 }
|
|
);
|
|
}
|
|
|
|
return NextResponse.json(
|
|
{
|
|
success: true,
|
|
message: "Notificação marcada como lida",
|
|
},
|
|
{ status: 200 }
|
|
);
|
|
} catch (error) {
|
|
secureLogger.error("❌ Erro ao marcar notificação como lida", {
|
|
error: error instanceof Error ? error.message : "Erro desconhecido",
|
|
});
|
|
|
|
return NextResponse.json(
|
|
{ success: false, error: "Erro ao marcar notificação como lida" },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|