Spaces:
Runtime error
Runtime error
rewrite function
Browse files
app/api/collections/route.ts
CHANGED
@@ -29,28 +29,22 @@ export async function GET(request: Request) {
|
|
29 |
}
|
30 |
|
31 |
if (userId) {
|
32 |
-
query.where
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
}
|
35 |
}
|
36 |
|
37 |
-
// if (userId) {
|
38 |
-
// query.where = {
|
39 |
-
// userId: {
|
40 |
-
// equals: userId
|
41 |
-
// },
|
42 |
-
// is_visible: {
|
43 |
-
// equals: true
|
44 |
-
// }
|
45 |
-
// }
|
46 |
-
// } else if (is_admin) {
|
47 |
-
// query.where = {
|
48 |
-
// is_visible: {
|
49 |
-
// equals: undefined
|
50 |
-
// }
|
51 |
-
// }
|
52 |
-
// }
|
53 |
-
|
54 |
const collections = await prisma.collection.findMany(query)
|
55 |
|
56 |
const total = await prisma.collection.count()
|
|
|
29 |
}
|
30 |
|
31 |
if (userId) {
|
32 |
+
query.where = {
|
33 |
+
userId: {
|
34 |
+
equals: userId
|
35 |
+
},
|
36 |
+
is_visible: {
|
37 |
+
equals: true
|
38 |
+
}
|
39 |
+
}
|
40 |
+
} else if (is_admin) {
|
41 |
+
query.where = {
|
42 |
+
is_visible: {
|
43 |
+
equals: undefined
|
44 |
+
}
|
45 |
}
|
46 |
}
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
const collections = await prisma.collection.findMany(query)
|
49 |
|
50 |
const total = await prisma.collection.count()
|
components/main/hooks/useCollections.ts
CHANGED
@@ -19,7 +19,9 @@ export const useCollections = (category: string) => {
|
|
19 |
["collections"],
|
20 |
async () => {
|
21 |
const queryParams = new URLSearchParams();
|
22 |
-
|
|
|
|
|
23 |
queryParams.append('page', '0');
|
24 |
|
25 |
const response = await fetch(`/api/collections?${queryParams.toString()}`, {
|
@@ -50,7 +52,9 @@ export const useCollections = (category: string) => {
|
|
50 |
const infiniteRefetch = async () => {
|
51 |
setLoading(true);
|
52 |
const queryParams = new URLSearchParams();
|
53 |
-
|
|
|
|
|
54 |
queryParams.append('page', data?.pagination?.page + 1);
|
55 |
|
56 |
const response = await fetch(`/api/collections?${queryParams.toString()}`, {
|
|
|
19 |
["collections"],
|
20 |
async () => {
|
21 |
const queryParams = new URLSearchParams();
|
22 |
+
if (category === 'my-own') {
|
23 |
+
queryParams.append('userId', user?.sub);
|
24 |
+
}
|
25 |
queryParams.append('page', '0');
|
26 |
|
27 |
const response = await fetch(`/api/collections?${queryParams.toString()}`, {
|
|
|
52 |
const infiniteRefetch = async () => {
|
53 |
setLoading(true);
|
54 |
const queryParams = new URLSearchParams();
|
55 |
+
if (category === 'my-own') {
|
56 |
+
queryParams.append('userId', user?.sub);
|
57 |
+
}
|
58 |
queryParams.append('page', data?.pagination?.page + 1);
|
59 |
|
60 |
const response = await fetch(`/api/collections?${queryParams.toString()}`, {
|