minor changes
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user