fix(duplicate-day): extract userId before closure to satisfy TS strict null check

session.user is narrowed inside the early-return guard but TypeScript
does not carry that narrowing into the Prisma transaction callback.
Extract to a const immediately after the guard.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-25 08:41:56 +02:00
parent d3f1753555
commit b4067c7685
+2 -1
View File
@@ -5,6 +5,7 @@ import { prisma } from "@/lib/prisma";
export async function POST(req: Request) { export async function POST(req: Request) {
const session = await auth(); const session = await auth();
if (!session?.user?.id) return NextResponse.json({ error: "Non autorisé" }, { status: 401 }); if (!session?.user?.id) return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
const userId = session.user.id;
const { babyId, sourceDate, targetDate } = await req.json(); const { babyId, sourceDate, targetDate } = await req.json();
@@ -49,7 +50,7 @@ export async function POST(req: Request) {
prisma.event.create({ prisma.event.create({
data: { data: {
babyId, babyId,
userId: session.user.id, userId,
type: ev.type, type: ev.type,
startedAt: new Date(ev.startedAt.getTime() + offsetMs), startedAt: new Date(ev.startedAt.getTime() + offsetMs),
endedAt: ev.endedAt ? new Date(ev.endedAt.getTime() + offsetMs) : null, endedAt: ev.endedAt ? new Date(ev.endedAt.getTime() + offsetMs) : null,