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.

update deleteWorkspace

Steven Tey760cdb23e99b
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
index 4cf7685eb2..2e4b494d5e 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
@@ -80,8 +80,9 @@ export const PUT = withWorkspace(
// DELETE /api/workspaces/[idOrSlug] – delete a specific project
export const DELETE = withWorkspace(
async ({ workspace }) => {
- const response = await deleteWorkspace(workspace);
- return NextResponse.json(response);
+ await deleteWorkspace(workspace);
+
+ return NextResponse.json(workspace);
},
{
requiredRole: ["owner"],
diff --git a/apps/web/lib/api/workspaces.ts b/apps/web/lib/api/workspaces.ts
index 0d7d7aca54..5b922b36fc 100644
--- a/apps/web/lib/api/workspaces.ts
+++ b/apps/web/lib/api/workspaces.ts
@@ -40,9 +40,9 @@ export async function deleteWorkspace(
}),
]);
- const response = await prisma.project.delete({
+ const response = await prisma.projectUsers.deleteMany({
where: {
- slug: workspace.slug,
+ projectId: workspace.id,
},
});
@@ -64,6 +64,7 @@ export async function deleteWorkspace(
pipeline.hdel(domain.toLowerCase(), ...links);
});
+ // delete all domains, links, and uploaded images associated with the workspace
await Promise.allSettled([
...customDomains.map(({ slug }) => deleteDomainAndLinks(slug)),
// delete all default domain links from redis
@@ -74,11 +75,20 @@ export async function deleteWorkspace(
? storage.delete(`images/${id}`)
: Promise.resolve(),
),
+ ]);
+
+ await Promise.all([
// delete workspace logo if it's a custom logo stored in R2
workspace.logo?.startsWith(process.env.STORAGE_BASE_URL as string) &&
storage.delete(`logos/${workspace.id}`),
// if they have a Stripe subscription, cancel it
workspace.stripeId && cancelSubscription(workspace.stripeId),
+ // delete the workspace
+ prisma.project.delete({
+ where: {
+ slug: workspace.slug,
+ },
+ }),
]);
})(),
);