Spaces:
Runtime error
Runtime error
rewrite
Browse files- app/api/collections/route.ts +19 -7
app/api/collections/route.ts
CHANGED
@@ -15,21 +15,33 @@ export async function GET(request: Request) {
|
|
15 |
is_admin = await isAdmin(headers) as boolean
|
16 |
}
|
17 |
|
18 |
-
const
|
19 |
orderBy: {
|
20 |
id: 'desc'
|
21 |
},
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
23 |
userId: {
|
24 |
equals: userId
|
25 |
},
|
26 |
is_visible: {
|
27 |
-
equals:
|
28 |
}
|
29 |
-
}
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
const total = await prisma.collection.count()
|
35 |
|
|
|
15 |
is_admin = await isAdmin(headers) as boolean
|
16 |
}
|
17 |
|
18 |
+
const query: Record<string, any> = {
|
19 |
orderBy: {
|
20 |
id: 'desc'
|
21 |
},
|
22 |
+
take: 15,
|
23 |
+
skip: page * 15
|
24 |
+
}
|
25 |
+
|
26 |
+
if (userId) {
|
27 |
+
query.where = {
|
28 |
userId: {
|
29 |
equals: userId
|
30 |
},
|
31 |
is_visible: {
|
32 |
+
equals: true
|
33 |
}
|
34 |
+
}
|
35 |
+
}
|
36 |
+
if (!is_admin) {
|
37 |
+
query.where = {
|
38 |
+
is_visible: {
|
39 |
+
equals: true
|
40 |
+
}
|
41 |
+
}
|
42 |
+
}
|
43 |
+
|
44 |
+
const collections = await prisma.collection.findMany(query)
|
45 |
|
46 |
const total = await prisma.collection.count()
|
47 |
|