Spaces:
Runtime error
Runtime error
import { PrismaClient } from '@prisma/client' | |
import { isAdmin } from '@/utils/checker/is_admin' | |
const prisma = new PrismaClient() | |
export async function GET(request: Request) { | |
const { headers } = request | |
const { searchParams } = new URL(request.url) | |
const userId = searchParams.get('id') ?? undefined | |
const page = searchParams.get('page') ? parseInt(searchParams.get('page') as string) : 0 | |
let is_admin = false | |
if (headers.get('Authorization') ) { | |
is_admin = await isAdmin(headers) as boolean | |
} | |
const collections = await prisma.collection.findMany({ | |
orderBy: { | |
id: 'desc' | |
}, | |
where: { | |
userId: { | |
equals: userId | |
}, | |
is_visible: { | |
equals: is_admin ? undefined : true | |
} | |
}, | |
take: 15, | |
skip: page * 15 | |
}) | |
const total = await prisma.collection.count() | |
return Response.json( | |
{ | |
collections, | |
pagination: { | |
total, | |
page, | |
total_pages: Math.ceil(total / 15) | |
}, | |
status: 200, | |
ok: true | |
} | |
) | |
} |