diff --git a/src/modules/groups/groups.controller.ts b/src/modules/groups/groups.controller.ts index e0cc222c7..74a41460f 100644 --- a/src/modules/groups/groups.controller.ts +++ b/src/modules/groups/groups.controller.ts @@ -78,4 +78,23 @@ export class GroupController { ): Promise> { return this.groupsService.deleteGroup(Number(id)); } + + @Get(':groupId/subgroups') + @Scopes('group-*:read-info') + async getSubgroups( + @Param('groupId', ParseIntPipe) id: number, + @Query('skip', OptionalIntPipe) skip?: number, + @Query('take', OptionalIntPipe) take?: number, + @Query('cursor', CursorPipe) cursor?: Record, + @Query('where', WherePipe) where?: Record, + @Query('orderBy', OrderByPipe) orderBy?: Record, + ): Promise[]> { + return this.groupsService.getSubgroups(id, { + skip, + take, + orderBy, + cursor, + where, + }); + } } diff --git a/src/modules/groups/groups.service.ts b/src/modules/groups/groups.service.ts index ce037b016..84ac95942 100644 --- a/src/modules/groups/groups.service.ts +++ b/src/modules/groups/groups.service.ts @@ -108,4 +108,25 @@ export class GroupsService { }); return this.prisma.expose(group); } + + async getSubgroups( + id: number, + params: { + skip?: number; + take?: number; + cursor?: groupsWhereUniqueInput; + where?: groupsWhereInput; + orderBy?: groupsOrderByInput; + }, + ): Promise[]> { + const { skip, take, cursor, where, orderBy } = params; + const groups = await this.prisma.groups.findMany({ + skip, + take, + cursor, + where: { ...where, parent: { id } }, + orderBy, + }); + return groups.map((user) => this.prisma.expose(user)); + } }