enzostvs HF Staff commited on
Commit
f7561cb
·
1 Parent(s): 80165bc
Files changed (1) hide show
  1. 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 collections = await prisma.collection.findMany({
19
  orderBy: {
20
  id: 'desc'
21
  },
22
- where: {
 
 
 
 
 
23
  userId: {
24
  equals: userId
25
  },
26
  is_visible: {
27
- equals: userId ? true : is_admin ? undefined : true
28
  }
29
- },
30
- take: 15,
31
- skip: page * 15
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