test(glm47): workspace stats endpoint (#633)

Co-authored-by: Jason Woltje <[email protected]>
Co-committed-by: Jason Woltje <[email protected]>
This commit is contained in:
2026-03-01 21:46:48 +00:00
committed by jason.woltje
parent 5b235a668f
commit 2463b7b8ba
2 changed files with 20 additions and 0 deletions
@@ -29,6 +29,15 @@ export class WorkspacesController {
return this.workspacesService.getUserWorkspaces(user.id); 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 * POST /api/workspaces/:workspaceId/members
* Add a member to a workspace with the specified role. * Add a member to a workspace with the specified role.
@@ -342,4 +342,15 @@ export class WorkspacesService {
private isUniqueConstraintError(error: unknown): error is Prisma.PrismaClientKnownRequestError { private isUniqueConstraintError(error: unknown): error is Prisma.PrismaClientKnownRequestError {
return error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2002"; 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 };
}
} }