homemanager-be/src/app-group/app-group.controller.ts
2023-01-12 20:10:36 +02:00

52 lines
1.3 KiB
TypeScript

import {
Body,
ClassSerializerInterceptor,
Controller,
Get,
Post,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import {
ApiBody,
ApiOkResponse,
ApiOperation,
ApiSecurity,
ApiTags,
} from '@nestjs/swagger';
import { User } from 'src/objects/user/user.entity';
import { LoggedInUser } from 'src/shared/decorators/user.decorator';
import { AuthGuard } from 'src/shared/guards/auth.guard';
import { AppGroupService } from './app-group.service';
import { CreateGroupRequestDto } from './dto/groups-create-request.dto';
import { GroupsResponseDto } from './dto/groups-response.dto';
@Controller({
path: 'groups',
})
@ApiTags('groups')
@ApiSecurity('Bearer token')
@UseInterceptors(ClassSerializerInterceptor)
@UseGuards(AuthGuard)
export class AppGroupController {
constructor(private readonly service: AppGroupService) {}
@Get()
@ApiOperation({ summary: 'Get user groups' })
@ApiOkResponse({ type: GroupsResponseDto, isArray: true })
async getGroups(@LoggedInUser() user: User) {
return this.service.getUserGroups(user);
}
@Post()
@ApiOperation({ summary: 'Create a new group' })
@ApiBody({ type: CreateGroupRequestDto })
@ApiOkResponse({ type: GroupsResponseDto })
async createGroup(
@LoggedInUser() user: User,
@Body() body: CreateGroupRequestDto,
) {
return this.service.createNewGroup(user, body);
}
}