Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/group/group.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,40 @@ export class GroupController {
@HttpCode(HttpStatus.OK)
async join(@Param('id') groupId: string, @Body('userId') userId: string) {
await this.groupService.joinGroup(groupId, userId);
// success
const group = await this.groupService.findOne(groupId);
return {
message: `User with ID ${userId} has successfully joined the group with ID ${groupId}`,
invite_code: group.invite_code,
};
}

// TODO #98: Add missing endpoints
@Post(':id/leave')
@HttpCode(HttpStatus.OK)
async leave(@Param('id') groupId: string, @Body('userId') userId: string) {
await this.groupService.leaveGroup(groupId, userId);
return {
message: `User with ID ${userId} has successfully left the group with ID ${groupId}`,
};
}

@Get(':id/members')
async getMembers(@Param('id') groupId: string) {
const group = await this.groupService.findOne(groupId);
return group.members;
}

@Get(':id/group-info')
async getGroupInfo(@Param('id') groupId: string) {
const group = await this.groupService.findOne(groupId);
return {
id: group.group_id,
name: group.group_name,
invite_code: group.invite_code,
members: group.members,
messages: group.messages,
challenges: group.challenges,
};
}

@Put(':id')
update(@Param('id') id: string, @Body() updateGroupDto: UpdateGroupDto) {
Expand Down
Loading