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 bulk-update-links.ts

Steven Tey2192d565e325
diff --git a/apps/web/lib/api/links/bulk-update-links.ts b/apps/web/lib/api/links/bulk-update-links.ts
index 500d9087c8..1503f0c6fb 100644
--- a/apps/web/lib/api/links/bulk-update-links.ts
+++ b/apps/web/lib/api/links/bulk-update-links.ts
@@ -2,13 +2,7 @@ import { prisma } from "@/lib/prisma";
import { isStored, storage } from "@/lib/storage";
import z from "@/lib/zod";
import { bulkUpdateLinksBodySchema } from "@/lib/zod/schemas/links";
-import {
- R2_URL,
- getParamsFromURL,
- linkConstructor,
- nanoid,
- truncate,
-} from "@dub/utils";
+import { R2_URL, getParamsFromURL, nanoid, truncate } from "@dub/utils";
import { Prisma } from "@prisma/client";
import { waitUntil } from "@vercel/functions";
import { propagateBulkLinkChanges } from "./propagate-bulk-link-changes";
@@ -41,17 +35,11 @@ export async function bulkUpdateLinks(
const imageUrlNonce = nanoid(7);
const updatedLinks = await Promise.all(
- linkIds.map(async (linkId) => {
- const link = await prisma.link.findUnique({
- where: { id: linkId },
- });
-
- if (!link) {
- throw new Error(`Link with id ${linkId} not found`);
- }
-
- return prisma.link.update({
- where: { id: linkId },
+ linkIds.map((linkId) =>
+ prisma.link.update({
+ where: {
+ id: linkId,
+ },
data: {
...rest,
url,
@@ -60,15 +48,11 @@ export async function bulkUpdateLinks(
description: truncate(description, 240),
image:
proxy && image && !isStored(image)
- ? `${R2_URL}/images/${linkId}_${imageUrlNonce}`
+ ? `${R2_URL}/images/${linkIds[0]}_${imageUrlNonce}`
: image,
expiresAt: expiresAt ? new Date(expiresAt) : null,
geo: geo || Prisma.JsonNull,
...(url && getParamsFromURL(url)),
- shortLink: linkConstructor({
- domain: link.domain,
- key: link.key,
- }),
// Associate tags by tagNames
...(tagNames &&
workspaceId && {
@@ -111,8 +95,8 @@ export async function bulkUpdateLinks(
},
},
},
- });
- }),
+ }),
+ ),
);
waitUntil(