Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

update count of links

Kiran K1e5da4dc6950
diff --git a/apps/web/lib/actions/update-folder-user-role.ts b/apps/web/lib/actions/update-folder-user-role.ts
index d3581628e4..3f0b778ce2 100644
--- a/apps/web/lib/actions/update-folder-user-role.ts
+++ b/apps/web/lib/actions/update-folder-user-role.ts
@@ -1,7 +1,6 @@
"use server";
import { prisma } from "@/lib/prisma";
-import { FolderUserRole } from "@prisma/client";
import { z } from "zod";
import { getFolderOrThrow } from "../folder/get-folder";
import { folderUserRoleSchema } from "../zod/schemas/folders";
@@ -40,12 +39,12 @@ export const updateFolderUserRoleAction = authActionClient
},
},
update: {
- role: role as FolderUserRole,
+ role,
},
create: {
folderId,
userId,
- role: role as FolderUserRole,
+ role,
},
});
diff --git a/apps/web/lib/api/links/get-links-count.ts b/apps/web/lib/api/links/get-links-count.ts
index 81e4d38ee4..c6f1cae3a8 100644
--- a/apps/web/lib/api/links/get-links-count.ts
+++ b/apps/web/lib/api/links/get-links-count.ts
@@ -50,12 +50,15 @@ export async function getLinksCount({
groupBy !== "userId" && {
userId,
}),
+
...(folderId &&
groupBy !== "folderId" && {
folderId,
}),
- OR: [{ folderId: { in: folderIds } }, { folderId: null }],
+ AND: {
+ OR: [{ folderId: { in: folderIds } }, { folderId: null }],
+ },
};
if (groupBy === "tagId") {
@@ -96,30 +99,11 @@ export async function getLinksCount({
},
}
: {}),
- };
-
- // Get the counts for each folder
- if (groupBy === "folderId") {
- const response = await prisma.folder.findMany({
- where: {
- projectId: workspaceId,
- },
- include: {
- _count: {
- select: {
- links: {
- where: linksWhere,
- },
- },
- },
- },
- });
- return response.map((folder) => ({
- folderId: folder.id,
- count: folder._count.links,
- }));
- }
+ AND: {
+ OR: [{ folderId: { in: folderIds } }, { folderId: null }],
+ },
+ };
if (
groupBy === "domain" ||
diff --git a/apps/web/lib/zod/schemas/folders.ts b/apps/web/lib/zod/schemas/folders.ts
index 49b2dd8248..98a27ce726 100644
--- a/apps/web/lib/zod/schemas/folders.ts
+++ b/apps/web/lib/zod/schemas/folders.ts
@@ -4,6 +4,7 @@ import {
} from "@/lib/folder/constants";
import { FolderAccessLevel } from "@/lib/folder/types";
import z from "@/lib/zod";
+import { FolderUserRole } from "@prisma/client";
export const workspaceAccessLevelSchema = z
.enum(
@@ -17,7 +18,7 @@ export const workspaceAccessLevelSchema = z
.describe("The access level of the folder within the workspace.");
export const folderUserRoleSchema = z
- .enum(Object.keys(FOLDER_USER_ROLE) as [string, ...string[]])
+ .enum(Object.keys(FOLDER_USER_ROLE) as [FolderUserRole, ...FolderUserRole[]])
.describe("The role of the user in the folder.");
export const folderSchema = z.object({