From e9f1360c228f105cfed6a0012a09bf5abfae32e5 Mon Sep 17 00:00:00 2001 From: Jason Woltje Date: Sun, 1 Mar 2026 15:34:39 -0600 Subject: [PATCH] feat(api): GET /api/workspaces/:id/stats endpoint --- apps/api/src/workspaces/workspaces.controller.ts | 9 +++++++++ apps/api/src/workspaces/workspaces.service.ts | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/apps/api/src/workspaces/workspaces.controller.ts b/apps/api/src/workspaces/workspaces.controller.ts index 40844d9..d2cad92 100644 --- a/apps/api/src/workspaces/workspaces.controller.ts +++ b/apps/api/src/workspaces/workspaces.controller.ts @@ -29,6 +29,15 @@ export class WorkspacesController { return this.workspacesService.getUserWorkspaces(user.id); } + /** + * GET /api/workspaces/:workspaceId/stats + * Returns member, project, and domain counts for a workspace. + */ + @Get(":workspaceId/stats") + async getStats(@Param("workspaceId") workspaceId: string) { + return this.workspacesService.getStats(workspaceId); + } + /** * POST /api/workspaces/:workspaceId/members * Add a member to a workspace with the specified role. diff --git a/apps/api/src/workspaces/workspaces.service.ts b/apps/api/src/workspaces/workspaces.service.ts index 18a5c9a..8aabd49 100644 --- a/apps/api/src/workspaces/workspaces.service.ts +++ b/apps/api/src/workspaces/workspaces.service.ts @@ -342,4 +342,15 @@ export class WorkspacesService { private isUniqueConstraintError(error: unknown): error is Prisma.PrismaClientKnownRequestError { return error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2002"; } + + async getStats( + workspaceId: string + ): Promise<{ memberCount: number; projectCount: number; domainCount: number }> { + const [memberCount, projectCount, domainCount] = await Promise.all([ + this.prisma.workspaceMember.count({ where: { workspaceId } }), + this.prisma.project.count({ where: { workspaceId } }), + this.prisma.domain.count({ where: { workspaceId } }), + ]); + return { memberCount, projectCount, domainCount }; + } } -- 2.49.1