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

Steven Teyd23e4ed1764f
diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.ts
index 24f1d7be29..ba05827e18 100644
--- a/apps/web/lib/api/links.ts
+++ b/apps/web/lib/api/links.ts
@@ -379,6 +379,8 @@ export async function processLink({
status: 422,
};
}
+ // we check if a key exists in bulk creation because
+ // for regular creation we check it in the addLink function
const exists = await checkIfKeyExists(domain, key);
if (exists) {
return {
@@ -387,6 +389,31 @@ export async function processLink({
status: 409,
};
}
+
+ // only perform tag validity checks if:
+ // - not bulk creation (we do that check in bulkCreateLinks)
+ // - tagIds are present
+ } else if (tagIds.length > 0) {
+ const tags = await prisma.tag.findMany({
+ select: {
+ id: true,
+ },
+ where: { projectId: project?.id, id: { in: tagIds } },
+ });
+
+ if (tags.length !== tagIds.length) {
+ return {
+ link: payload,
+ error:
+ "Invalid tagIds: " +
+ tagIds
+ .filter(
+ (tagId) => tags.find(({ id }) => tagId === id) === undefined,
+ )
+ .join(", "),
+ status: 422,
+ };
+ }
}
// custom social media image checks
@@ -419,30 +446,6 @@ export async function processLink({
}
}
- // tag validity checks
- if (tagIds.length > 0) {
- const tags = await prisma.tag.findMany({
- select: {
- id: true,
- },
- where: { projectId: project?.id, id: { in: tagIds } },
- });
-
- if (tags.length !== tagIds.length) {
- return {
- link: payload,
- error:
- "Invalid tagIds: " +
- tagIds
- .filter(
- (tagId) => tags.find(({ id }) => tagId === id) === undefined,
- )
- .join(", "),
- status: 422,
- };
- }
- }
-
// remove polyfill attributes from payload
delete payload["shortLink"];
delete payload["qrCode"];