The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add link ID to completion endpoint route
Tim Wilsonb6db4051a327
diff --git a/apps/web/app/api/cron/links/complete-tests/route.ts b/apps/web/app/api/cron/links/[linkId]/complete-tests/route.tssimilarity index 83%rename from apps/web/app/api/cron/links/complete-tests/route.tsrename to apps/web/app/api/cron/links/[linkId]/complete-tests/route.tsindex 8196d9679f..8b4191e267 100644--- a/apps/web/app/api/cron/links/complete-tests/route.ts+++ b/apps/web/app/api/cron/links/[linkId]/complete-tests/route.ts@@ -6,12 +6,17 @@ import { prisma } from "@dub/prisma";/*** Completes a link's tests if they're ready, scheduled by QStash*/-export async function POST(req: Request) {+export async function POST(+ req: Request,+ { params = {} }: { params: Record<string, string> | undefined },+) {try {const rawBody = await req.text();await verifyQstashSignature({ req, rawBody });- const { linkId } = JSON.parse(rawBody);+ const { linkId } = params;++ if (!linkId) return new Response("Link ID is required.", { status: 400 });const link = await prisma.link.findUnique({where: {diff --git a/apps/web/lib/api/links/schedule-test-completion.ts b/apps/web/lib/api/links/schedule-test-completion.tsindex 63b440d29c..c6dc726984 100644--- a/apps/web/lib/api/links/schedule-test-completion.ts+++ b/apps/web/lib/api/links/schedule-test-completion.ts@@ -3,7 +3,7 @@ import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";import { ExpandedLink } from "./utils";export async function scheduleTestCompletion(link: ExpandedLink) {- const completionUrl = `${APP_DOMAIN_WITH_NGROK}/api/cron/links/complete-tests`;+ const completionUrl = `${APP_DOMAIN_WITH_NGROK}/api/cron/links/${link.id}/complete-tests`;// Remove any previously scheduled completion jobstry {@@ -43,9 +43,6 @@ export async function scheduleTestCompletion(link: ExpandedLink) {await qstash.publishJSON({url: completionUrl,delay: (testsCompleteAt.getTime() - new Date().getTime()) / 1000,- body: {- linkId: link.id,- },});}}