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.

Refactor domain selection in GET and POST routes

Kiran K11be28d3da04
diff --git a/apps/web/app/api/workspaces/route.ts b/apps/web/app/api/workspaces/route.ts
index 4de8511db1..a4bbc3a358 100644
--- a/apps/web/app/api/workspaces/route.ts
+++ b/apps/web/app/api/workspaces/route.ts
@@ -29,7 +29,12 @@ export const GET = withSession(async ({ session }) => {
role: true,
},
},
- domains: true,
+ domains: {
+ select: {
+ slug: true,
+ primary: true,
+ },
+ },
},
});
return NextResponse.json(
@@ -113,7 +118,13 @@ export const POST = withSession(async ({ req, session }) => {
},
},
include: {
- domains: true,
+ domains: {
+ select: {
+ id: true,
+ slug: true,
+ primary: true,
+ },
+ },
users: {
select: {
role: true,
@@ -134,5 +145,13 @@ export const POST = withSession(async ({ req, session }) => {
});
}
- return NextResponse.json(projectResponse);
+ const response = {
+ ...projectResponse,
+ domains: projectResponse.domains.map(({ slug, primary }) => ({
+ slug,
+ primary,
+ })),
+ };
+
+ return NextResponse.json(response);
});
diff --git a/apps/web/lib/zod/schemas/workspaces.ts b/apps/web/lib/zod/schemas/workspaces.ts
index fedba049f5..932cd3f0f5 100644
--- a/apps/web/lib/zod/schemas/workspaces.ts
+++ b/apps/web/lib/zod/schemas/workspaces.ts
@@ -8,6 +8,13 @@ import {
import slugify from "@sindresorhus/slugify";
import { planSchema, roleSchema } from ".";
+export const DomainSchema = z.object({
+ slug: z.string().describe("The domain of the workspace."),
+ primary: z
+ .boolean()
+ .describe("Indicates if the domain is the primary domain."),
+});
+
export const WorkspaceSchema = z
.object({
id: z.string().describe("The unique ID of the workspace."),
@@ -42,16 +49,7 @@ export const WorkspaceSchema = z
}),
)
.describe("The role of the authenticated user in the workspace."),
-
- // TODO:
- // Update the domains schema to include the domain object
- domains: z
- .array(
- z.object({
- slug: z.string().describe("The domain of the workspace."),
- }),
- )
- .describe("The domains of the workspace."),
+ domains: z.array(DomainSchema).describe("The domains of the workspace."),
})
.openapi({
title: "Workspace",