61 lines
2.2 KiB
TypeScript
61 lines
2.2 KiB
TypeScript
import { Controller, Post, Get, Param, Body, Query } from '@nestjs/common';
|
|
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
|
import { GroupsService } from './groups.service';
|
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
|
import { User } from '@coursecraft/database';
|
|
|
|
@ApiTags('groups')
|
|
@Controller('groups')
|
|
@ApiBearerAuth()
|
|
export class GroupsController {
|
|
constructor(private groupsService: GroupsService) {}
|
|
|
|
@Post()
|
|
async createGroup(@Body() body: { courseId: string; name: string; description?: string }, @CurrentUser() user: User): Promise<any> {
|
|
return this.groupsService.createGroup(body.courseId, user.id, body.name, body.description);
|
|
}
|
|
|
|
@Post(':groupId/members')
|
|
async addMember(@Param('groupId') groupId: string, @Body('userId') userId: string, @CurrentUser() user: User): Promise<any> {
|
|
return this.groupsService.addMember(groupId, user.id, userId);
|
|
}
|
|
|
|
@Get('course/:courseId/default')
|
|
async getDefaultGroup(@Param('courseId') courseId: string, @CurrentUser() user: User): Promise<any> {
|
|
return this.groupsService.getDefaultGroup(courseId, user.id);
|
|
}
|
|
|
|
@Get(':groupId/members')
|
|
async getMembers(@Param('groupId') groupId: string, @CurrentUser() user: User): Promise<any> {
|
|
return this.groupsService.getGroupMembers(groupId, user.id);
|
|
}
|
|
|
|
@Get(':groupId/messages')
|
|
async getMessages(
|
|
@Param('groupId') groupId: string,
|
|
@Query('lessonId') lessonId: string | undefined,
|
|
@CurrentUser() user: User
|
|
): Promise<any> {
|
|
return this.groupsService.getGroupMessages(groupId, user.id, lessonId);
|
|
}
|
|
|
|
@Post(':groupId/messages')
|
|
async sendMessage(
|
|
@Param('groupId') groupId: string,
|
|
@Body() body: { content: string; lessonId?: string },
|
|
@CurrentUser() user: User
|
|
): Promise<any> {
|
|
return this.groupsService.sendMessage(groupId, user.id, body.content, body.lessonId);
|
|
}
|
|
|
|
@Post(':groupId/invite-link')
|
|
async createInviteLink(@Param('groupId') groupId: string, @CurrentUser() user: User): Promise<any> {
|
|
return this.groupsService.createInviteLink(groupId, user.id);
|
|
}
|
|
|
|
@Post('join/:groupId')
|
|
async joinByInvite(@Param('groupId') groupId: string, @CurrentUser() user: User): Promise<any> {
|
|
return this.groupsService.joinByInvite(groupId, user.id);
|
|
}
|
|
}
|