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.

Make sure tags are returned in creation order

Steven Teyc0b48e2363fd
diff --git a/apps/web/lib/api/links/bulk-create-links.ts b/apps/web/lib/api/links/bulk-create-links.ts
index 226c962bbe..3ea5ff8190 100644
--- a/apps/web/lib/api/links/bulk-create-links.ts
+++ b/apps/web/lib/api/links/bulk-create-links.ts
@@ -63,7 +63,7 @@ export async function bulkCreateLinks({
...(tagNames?.length &&
link.projectId && {
tags: {
- create: tagNames.filter(Boolean).map((tagName) => ({
+ create: tagNames.filter(Boolean).map((tagName, idx) => ({
tag: {
connect: {
name_projectId: {
@@ -72,6 +72,7 @@ export async function bulkCreateLinks({
},
},
},
+ createdAt: new Date(new Date().getTime() + idx * 100), // increment by 100ms for correct order
})),
},
}),
@@ -81,9 +82,10 @@ export async function bulkCreateLinks({
combinedTagIds.length > 0 && {
tags: {
createMany: {
- data: combinedTagIds
- .filter(Boolean)
- .map((tagId) => ({ tagId })),
+ data: combinedTagIds.filter(Boolean).map((tagId, idx) => ({
+ tagId,
+ createdAt: new Date(new Date().getTime() + idx * 100), // increment by 100ms for correct order
+ })),
},
},
}),
@@ -110,6 +112,9 @@ export async function bulkCreateLinks({
},
},
},
+ orderBy: {
+ createdAt: "asc",
+ },
},
webhooks: hasWebhooks,
},
diff --git a/apps/web/lib/api/links/bulk-update-links.ts b/apps/web/lib/api/links/bulk-update-links.ts
index 1503f0c6fb..34b9bfe5b6 100644
--- a/apps/web/lib/api/links/bulk-update-links.ts
+++ b/apps/web/lib/api/links/bulk-update-links.ts
@@ -58,7 +58,7 @@ export async function bulkUpdateLinks(
workspaceId && {
tags: {
deleteMany: {},
- create: tagNames.map((tagName) => ({
+ create: tagNames.map((tagName, idx) => ({
tag: {
connect: {
name_projectId: {
@@ -67,6 +67,7 @@ export async function bulkUpdateLinks(
},
},
},
+ createdAt: new Date(new Date().getTime() + idx * 100), // increment by 100ms for correct order
})),
},
}),
@@ -75,8 +76,9 @@ export async function bulkUpdateLinks(
...(combinedTagIds && {
tags: {
deleteMany: {},
- create: combinedTagIds.map((tagId) => ({
+ create: combinedTagIds.map((tagId, idx) => ({
tagId,
+ createdAt: new Date(new Date().getTime() + idx * 100), // increment by 100ms for correct order
})),
},
}),
@@ -93,6 +95,9 @@ export async function bulkUpdateLinks(
},
},
},
+ orderBy: {
+ createdAt: "asc",
+ },
},
},
}),
diff --git a/apps/web/lib/api/links/create-link.ts b/apps/web/lib/api/links/create-link.ts
index fbf59361b2..b01a4357a4 100644
--- a/apps/web/lib/api/links/create-link.ts
+++ b/apps/web/lib/api/links/create-link.ts
@@ -47,13 +47,14 @@ export async function createLink(link: ProcessedLinkProps) {
...(tagNames?.length &&
link.projectId && {
tags: {
- create: tagNames.map((tagName) => ({
+ create: tagNames.map((tagName, idx) => ({
tag: {
connect: {
name_projectId: {
name: tagName,
projectId: link.projectId as string,
},
+ createdAt: new Date(new Date().getTime() + idx * 100), // increment by 100ms for correct order
},
},
})),
@@ -65,7 +66,10 @@ export async function createLink(link: ProcessedLinkProps) {
combinedTagIds.length > 0 && {
tags: {
createMany: {
- data: combinedTagIds.map((tagId) => ({ tagId })),
+ data: combinedTagIds.map((tagId, idx) => ({
+ tagId,
+ createdAt: new Date(new Date().getTime() + idx * 100), // increment by 100ms for correct order
+ })),
},
},
}),
@@ -93,6 +97,9 @@ export async function createLink(link: ProcessedLinkProps) {
},
},
},
+ orderBy: {
+ createdAt: "asc",
+ },
},
webhooks: webhookIds ? true : false,
},
diff --git a/apps/web/lib/api/links/update-link.ts b/apps/web/lib/api/links/update-link.ts
index d198aaa6f6..2f0c6a61f9 100644
--- a/apps/web/lib/api/links/update-link.ts
+++ b/apps/web/lib/api/links/update-link.ts
@@ -87,13 +87,14 @@ export async function updateLink({
updatedLink.projectId && {
tags: {
deleteMany: {},
- create: tagNames.map((tagName) => ({
+ create: tagNames.map((tagName, idx) => ({
tag: {
connect: {
name_projectId: {
name: tagName,
projectId: updatedLink.projectId as string,
},
+ createdAt: new Date(new Date().getTime() + idx * 100), // increment by 100ms for correct order
},
},
})),
@@ -104,8 +105,9 @@ export async function updateLink({
...(combinedTagIds && {
tags: {
deleteMany: {},
- create: combinedTagIds.map((tagId) => ({
+ create: combinedTagIds.map((tagId, idx) => ({
tagId,
+ createdAt: new Date(new Date().getTime() + idx * 100), // increment by 100ms for correct order
})),
},
}),
@@ -133,6 +135,9 @@ export async function updateLink({
},
},
},
+ orderBy: {
+ createdAt: "asc",
+ },
},
webhooks: webhookIds ? true : false,
},