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.

Filter `GET /discount-codes` by `code`

Steven Tey6d711c98a038
diff --git a/apps/web/app/(ee)/api/discount-codes/route.ts b/apps/web/app/(ee)/api/discount-codes/route.ts
index c79d0ba8ca..fc93ecd65a 100644
--- a/apps/web/app/(ee)/api/discount-codes/route.ts
+++ b/apps/web/app/(ee)/api/discount-codes/route.ts
@@ -24,6 +24,7 @@ export const GET = withWorkspace(
const {
partnerId,
discountId,
+ code,
page = 1,
pageSize,
} = getDiscountCodesQuerySchema.parse(searchParams);
@@ -48,6 +49,7 @@ export const GET = withWorkspace(
programId,
...(partnerId && { partnerId }),
...(discountId && { discountId }),
+ ...(code && { code }),
},
orderBy: {
createdAt: "desc",
diff --git a/apps/web/lib/openapi/discount-codes/list-discount-codes.ts b/apps/web/lib/openapi/discount-codes/list-discount-codes.ts
index d35965253f..478ab0c97a 100644
--- a/apps/web/lib/openapi/discount-codes/list-discount-codes.ts
+++ b/apps/web/lib/openapi/discount-codes/list-discount-codes.ts
@@ -11,7 +11,7 @@ export const listDiscountCodes: ZodOpenApiOperationObject = {
"x-speakeasy-name-override": "list",
summary: "List discount codes",
description:
- "Retrieve a paginated list of discount codes for a partner / a given discount / the whole program.",
+ "Retrieve a paginated list of discount codes in a program or filtered by partner, discount, or code.",
requestParams: {
query: getDiscountCodesQuerySchema,
},
diff --git a/apps/web/lib/zod/schemas/discount.ts b/apps/web/lib/zod/schemas/discount.ts
index b51405a8df..5dd6a1147a 100644
--- a/apps/web/lib/zod/schemas/discount.ts
+++ b/apps/web/lib/zod/schemas/discount.ts
@@ -128,6 +128,12 @@ export const getDiscountCodesQuerySchema = z
.string()
.optional()
.describe("Filter discount codes by discount ID."),
+ code: z
+ .string()
+ .optional()
+ .describe(
+ "Filter discount codes by the alphanumeric code (e.g. `PARTNER10OFF`).",
+ ),
})
.extend(getPaginationQuerySchema({ pageSize: 100 }));
diff --git a/apps/web/playwright/api/discount-codes/discount-codes.spec.ts b/apps/web/playwright/api/discount-codes/discount-codes.spec.ts
index f501f93410..a08bbd1d0b 100644
--- a/apps/web/playwright/api/discount-codes/discount-codes.spec.ts
+++ b/apps/web/playwright/api/discount-codes/discount-codes.spec.ts
@@ -590,6 +590,24 @@ test("GET /discount-codes – by discountId", async ({ api }) => {
}
});
+test("GET /discount-codes – by code", async ({ api }) => {
+ let partnerId: string | undefined;
+
+ try {
+ const created = await createDiscountCode(api);
+ partnerId = created.partner.id;
+
+ const { status, data } = await api.get<DiscountCode[]>(
+ `/api/discount-codes?code=${encodeURIComponent(created.data.code)}`,
+ );
+
+ expect(status).toEqual(200);
+ expect(data).toEqual([created.data]);
+ } finally {
+ await deletePartner(partnerId);
+ }
+});
+
test("GET /discount-codes – pagination", async ({ api }) => {
let partnerIdA: string | undefined;
let partnerIdB: string | undefined;