minor changes

This commit is contained in:
daniel31x13
2024-11-02 20:43:53 -04:00
parent 2e1e94112f
commit 4febe1ace5
21 changed files with 4603 additions and 21657 deletions
+17 -10
View File
@@ -1,5 +1,5 @@
import getPublicLinksUnderCollection from "@/lib/api/controllers/public/links/getPublicLinksUnderCollection";
import getTags from "@/lib/api/controllers/tags/getTags";
import { prisma } from "@/lib/api/db";
import { LinkRequestQuery } from "@/types/global";
import type { NextApiRequest, NextApiResponse } from "next";
@@ -22,14 +22,21 @@ export default async function collections(
.json({ response: "Please choose a valid collection." });
}
const links = await getPublicLinksUnderCollection(convertedData, true);
const tags = await getTags();
const tagsInLinks = links.response.map(l => l.tags).flat().filter((value, index, self) =>
index === self.findIndex((t) => (
t.name === value.name
))).map(t => t.id);
const tagsWithCount = tags.response.filter(tag => tagsInLinks.includes(tag.id));
return res.status(links.status).json({ response: tagsWithCount });
const collection = await prisma.collection.findFirst({
where: {
id: convertedData.collectionId,
isPublic: true,
},
});
if (!collection) {
return res.status(404).json({ response: "Collection not found." });
}
const tags = await getTags({
collectionId: collection.id,
});
return res.status(tags.status).json({ response: tags.response });
}
}
+3 -1
View File
@@ -7,7 +7,9 @@ export default async function tags(req: NextApiRequest, res: NextApiResponse) {
if (!user) return;
if (req.method === "GET") {
const tags = await getTags(user.id);
const tags = await getTags({
userId: user.id,
});
return res.status(tags.status).json({ response: tags.response });
}
}