Compare commits
3 Commits
fix/ci-lin
...
fix/worksp
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e0425177d | |||
| 2463b7b8ba | |||
| 5b235a668f |
@@ -29,6 +29,25 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/workspaces/:workspaceId/members
|
||||||
|
* Returns the list of members for a workspace.
|
||||||
|
*/
|
||||||
|
@Get(":workspaceId/members")
|
||||||
|
@UseGuards(WorkspaceGuard)
|
||||||
|
async getMembers(@Param("workspaceId") workspaceId: string) {
|
||||||
|
return this.workspacesService.getMembers(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.
|
||||||
|
|||||||
@@ -321,6 +321,18 @@ export class WorkspacesService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get members of a workspace.
|
||||||
|
*/
|
||||||
|
async getMembers(workspaceId: string) {
|
||||||
|
return this.prisma.workspaceMember.findMany({
|
||||||
|
where: { workspaceId },
|
||||||
|
include: {
|
||||||
|
user: { select: { id: true, name: true, email: true, createdAt: true } },
|
||||||
|
},
|
||||||
|
orderBy: { joinedAt: "asc" },
|
||||||
|
});
|
||||||
|
}
|
||||||
private assertCanAssignRole(
|
private assertCanAssignRole(
|
||||||
actorRole: WorkspaceMemberRole,
|
actorRole: WorkspaceMemberRole,
|
||||||
requestedRole: WorkspaceMemberRole
|
requestedRole: WorkspaceMemberRole
|
||||||
@@ -342,4 +354,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 };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user