Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
✨ Add endpoint for subgroups
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 16, 2020
1 parent ef2dc72 commit 666e37e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/modules/groups/groups.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,23 @@ export class GroupController {
): Promise<Expose<groups>> {
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<string, number | string>,
@Query('where', WherePipe) where?: Record<string, number | string>,
@Query('orderBy', OrderByPipe) orderBy?: Record<string, 'asc' | 'desc'>,
): Promise<Expose<groups>[]> {
return this.groupsService.getSubgroups(id, {
skip,
take,
orderBy,
cursor,
where,
});
}
}
21 changes: 21 additions & 0 deletions src/modules/groups/groups.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,25 @@ export class GroupsService {
});
return this.prisma.expose<groups>(group);
}

async getSubgroups(
id: number,
params: {
skip?: number;
take?: number;
cursor?: groupsWhereUniqueInput;
where?: groupsWhereInput;
orderBy?: groupsOrderByInput;
},
): Promise<Expose<groups>[]> {
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<groups>(user));
}
}

0 comments on commit 666e37e

Please sign in to comment.