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.

add relation between customer and link tables

Steven Tey5c410a0ab405
diff --git a/apps/web/lib/api/customers/get-customer-or-throw.ts b/apps/web/lib/api/customers/get-customer-or-throw.ts
index d5026ad732..66fdbb1aed 100644
--- a/apps/web/lib/api/customers/get-customer-or-throw.ts
+++ b/apps/web/lib/api/customers/get-customer-or-throw.ts
@@ -19,6 +19,9 @@ export const getCustomerOrThrow = async ({
}
: { id }),
},
+ include: {
+ link: true,
+ },
});
if (!customer || customer.projectId !== workspaceId) {
diff --git a/apps/web/lib/zod/schemas/customers.ts b/apps/web/lib/zod/schemas/customers.ts
index 0f26582498..836c179f1a 100644
--- a/apps/web/lib/zod/schemas/customers.ts
+++ b/apps/web/lib/zod/schemas/customers.ts
@@ -37,6 +37,13 @@ export const CustomerSchema = z.object({
avatar: z.string().nullish().describe("Avatar URL of the customer."),
country: z.string().nullish().describe("Country of the customer."),
createdAt: z.date().describe("The date the customer was created."),
+ link: LinkSchema.pick({
+ id: true,
+ domain: true,
+ key: true,
+ shortLink: true,
+ programId: true,
+ }).nullish(),
});
export const CUSTOMERS_MAX_PAGE_SIZE = 100;
diff --git a/packages/prisma/schema/customer.prisma b/packages/prisma/schema/customer.prisma
index d2b5443541..dc8d0fbdc8 100644
--- a/packages/prisma/schema/customer.prisma
+++ b/packages/prisma/schema/customer.prisma
@@ -15,11 +15,13 @@ model Customer {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
+ link Link? @relation(fields: [linkId], references: [id])
sales Sale[]
@@unique([projectId, externalId])
@@unique([projectConnectId, externalId])
- @@index(projectId)
- @@index(projectConnectId)
- @@index(externalId)
+ @@index([projectId])
+ @@index([projectConnectId])
+ @@index([externalId])
+ @@index([linkId])
}
diff --git a/packages/prisma/schema/link.prisma b/packages/prisma/schema/link.prisma
index 9f0a6dc15e..ec27e44e2a 100644
--- a/packages/prisma/schema/link.prisma
+++ b/packages/prisma/schema/link.prisma
@@ -68,6 +68,7 @@ model Link {
programId String?
program Program? @relation(fields: [programId], references: [id])
+ customers Customer[]
@@unique([domain, key])
@@unique([projectId, externalId])