Fix user-pastes

This commit is contained in:
UltraLionFr
2025-08-20 18:15:23 +02:00
parent f620af83be
commit 8394fdd43f
+14 -12
View File
@@ -1,5 +1,6 @@
import { authOptions } from '@/lib/auth'; import { authOptions } from '@/lib/auth';
import { prisma } from '@/lib/prisma'; import { prisma } from '@/lib/prisma';
import { Prisma } from '@prisma/client';
import { getServerSession } from 'next-auth'; import { getServerSession } from 'next-auth';
import { NextResponse } from 'next/server'; import { NextResponse } from 'next/server';
@@ -17,17 +18,18 @@ export async function GET(req: Request) {
const search = searchParams.get('q') || ''; const search = searchParams.get('q') || '';
const filter = { // ✅ Typage explicite avec Prisma
createdBy: session.user.id, const filter: Prisma.PasteWhereInput = {
...(search createdBy: session.user.id,
? { ...(search
title: { ? {
contains: search, title: {
mode: 'insensitive', contains: search,
}, mode: 'insensitive', // correspond au type Prisma.QueryMode
} },
: {}), }
} as const; : {}),
};
const [pastes, total] = await Promise.all([ const [pastes, total] = await Promise.all([
prisma.paste.findMany({ prisma.paste.findMany({
@@ -42,4 +44,4 @@ const filter = {
]); ]);
return NextResponse.json({ pastes, total }); return NextResponse.json({ pastes, total });
} }