bug fix + cleaner code/logic

This commit is contained in:
Daniel
2023-06-15 16:09:30 +03:30
parent 1b6d902c75
commit 4b9b1be80c
11 changed files with 156 additions and 229 deletions
+10 -8
View File
@@ -1,7 +1,10 @@
import { prisma } from "@/lib/api/db";
import { PublicLinkRequestQuery } from "@/types/global";
export default async function getCollection(query: PublicLinkRequestQuery) {
export default async function getCollection(body: string) {
const query: PublicLinkRequestQuery = JSON.parse(decodeURIComponent(body));
console.log(query);
let data;
const collection = await prisma.collection.findFirst({
@@ -14,13 +17,12 @@ export default async function getCollection(query: PublicLinkRequestQuery) {
if (collection) {
const links = await prisma.link.findMany({
take: Number(process.env.PAGINATION_TAKE_COUNT),
skip: query.cursor !== "undefined" ? 1 : undefined,
cursor:
query.cursor !== "undefined"
? {
id: Number(query.cursor),
}
: undefined,
skip: query.cursor ? 1 : undefined,
cursor: query.cursor
? {
id: Number(query.cursor),
}
: undefined,
where: {
collection: {
id: Number(query.collectionId),