Spaces:
Runtime error
Runtime error
File size: 1,040 Bytes
4f2c36e 03138b9 4f2c36e 17f8f56 6233641 17f8f56 848e268 03138b9 6233641 7e19cbb 5881efa cca515d 63bd9dc 6233641 cca515d 848e268 5881efa 4f2c36e 7e19cbb 848e268 7e19cbb 848e268 6407b30 848e268 4f2c36e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
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
}
)
} |