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.

support updating/deleting customers by external id

Steven Teyce76850a0af8
diff --git a/apps/web/app/api/customers/[id]/route.ts b/apps/web/app/api/customers/[id]/route.ts
index 7642072f0d..b62a58604e 100644
--- a/apps/web/app/api/customers/[id]/route.ts
+++ b/apps/web/app/api/customers/[id]/route.ts
@@ -40,15 +40,15 @@ export const PATCH = withWorkspace(
await parseRequestBody(req),
);
- await getCustomerOrThrow({
+ const customer = await getCustomerOrThrow({
id,
workspaceId: workspace.id,
});
try {
- const customer = await prisma.customer.update({
+ const updatedCustomer = await prisma.customer.update({
where: {
- id,
+ id: customer.id,
},
data: { name, email, avatar, externalId },
include: {
@@ -56,7 +56,7 @@ export const PATCH = withWorkspace(
},
});
- return NextResponse.json(CustomerSchema.parse(customer));
+ return NextResponse.json(CustomerSchema.parse(updatedCustomer));
} catch (error) {
if (error.code === "P2002") {
throw new DubApiError({
@@ -81,19 +81,19 @@ export const DELETE = withWorkspace(
async ({ workspace, params }) => {
const { id } = params;
- await getCustomerOrThrow({
+ const customer = await getCustomerOrThrow({
id,
workspaceId: workspace.id,
});
await prisma.customer.delete({
where: {
- id,
+ id: customer.id,
},
});
return NextResponse.json({
- id,
+ id: customer.id,
});
},
{