⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
fix: improve tag retrieval logic for user collections
daniel31x13054a82a029cd
diff --git a/apps/web/lib/api/controllers/tags/getTags.ts b/apps/web/lib/api/controllers/tags/getTags.tsindex 1b3ec2b0..80e7fb84 100644--- a/apps/web/lib/api/controllers/tags/getTags.ts+++ b/apps/web/lib/api/controllers/tags/getTags.ts@@ -25,6 +25,19 @@ export default async function getTags({orderBy = [{ links: { _count: "asc" } }, { id: "asc" }];if (userId) {+ const memberCollections = await prisma.usersAndCollections.findMany({+ where: {+ userId,+ },+ select: {+ collectionId: true,+ },+ });++ const memberCollectionIds = memberCollections.map(+ (memberCollection) => memberCollection.collectionId+ );+const tags = await prisma.tag.findMany({take: paginationTakeCount,skip: query.cursor ? 1 : undefined,@@ -32,19 +45,19 @@ export default async function getTags({where: {OR: [{ ownerId: userId }, // Tags owned by the user- {- links: {- some: {- collection: {- members: {+ ...(memberCollectionIds.length > 0+ ? [+ {+ links: {some: {- userId, // Tags from collections where the user is a member+ collectionId: {+ in: memberCollectionIds,+ },},},},- },- },- },+ ]+ : []),],},include: {@@ -70,9 +83,7 @@ export default async function getTags({where: {links: {some: {- collection: {- id: collectionId,- },+ collectionId,},},},