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 tagId array logic and remove unused utility method

Tim Wilson2fd6ee0f8ea5
diff --git a/apps/web/app/api/admin/links/count/route.ts b/apps/web/app/api/admin/links/count/route.ts
index 39389327ed..cd8eba2f7a 100644
--- a/apps/web/app/api/admin/links/count/route.ts
+++ b/apps/web/app/api/admin/links/count/route.ts
@@ -12,6 +12,8 @@ export const GET = withAdmin(async ({ searchParams }) => {
tagId?: string;
};
+ const tagIds = tagId ? tagId.split(",") : [];
+
let response;
if (groupBy) {
@@ -69,7 +71,7 @@ export const GET = withAdmin(async ({ searchParams }) => {
in: DUB_DOMAINS.map((domain) => domain.slug),
},
}),
- ...(tagId && {
+ ...(tagIds.length > 0 && {
tags: {
some: {
id: tagId,
diff --git a/apps/web/app/api/admin/links/route.ts b/apps/web/app/api/admin/links/route.ts
index d3fa1f1974..f1d7de5254 100644
--- a/apps/web/app/api/admin/links/route.ts
+++ b/apps/web/app/api/admin/links/route.ts
@@ -1,7 +1,7 @@
import { withAdmin } from "@/lib/auth";
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
-import { DUB_DOMAINS, LEGAL_USER_ID, ensureArray } from "@dub/utils";
+import { DUB_DOMAINS, LEGAL_USER_ID } from "@dub/utils";
// GET /api/admin/links
export const GET = withAdmin(async ({ searchParams }) => {
diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.ts
index 05afdc0a07..54dde0b2ba 100644
--- a/apps/web/lib/api/links.ts
+++ b/apps/web/lib/api/links.ts
@@ -10,7 +10,6 @@ import {
DEFAULT_REDIRECTS,
DUB_DOMAINS,
SHORT_DOMAIN,
- ensureArray,
getDomainWithoutWWW,
getParamsFromURL,
getUrlFromString,
@@ -66,7 +65,7 @@ export async function getLinksForProject({
},
],
}),
- ...(tagIds?.length && {
+ ...(tagIds.length > 0 && {
tags: { some: { tagId: { in: tagIds } } },
}),
...(userId && { userId }),
@@ -175,7 +174,7 @@ export async function getLinksCount({
} else {
const where = {
...linksWhere,
- ...(tagIds?.length && {
+ ...(tagIds.length > 0 && {
tags: {
some: {
id: {
diff --git a/packages/utils/src/functions/ensure-array.ts b/packages/utils/src/functions/ensure-array.ts
deleted file mode 100644
index ddcab0a31a..0000000000
--- a/packages/utils/src/functions/ensure-array.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-/**
- * Wraps the provided item in an array if it isn't already one
- */
-export function ensureArray<T>(itemOrArray: T | T[]) {
- return Array.isArray(itemOrArray) ? itemOrArray : [itemOrArray];
-}
diff --git a/packages/utils/src/functions/index.ts b/packages/utils/src/functions/index.ts
index 30cedb7519..a866b92bff 100644
--- a/packages/utils/src/functions/index.ts
+++ b/packages/utils/src/functions/index.ts
@@ -5,7 +5,6 @@ export * from "./construct-metadata";
export * from "./datetime";
export * from "./deep-equal";
export * from "./domains";
-export * from "./ensure-array";
export * from "./fetch-with-timeout";
export * from "./fetcher";
export * from "./hash";