universo-platform-3d
64 строки · 1.8 Кб
1import {
2Body,
3Controller,
4Delete,
5Get,
6Param,
7Patch,
8Post,
9UsePipes,
10ValidationPipe
11} from '@nestjs/common'
12import { ApiCreatedResponse, ApiParam } from '@nestjs/swagger'
13import { ApiResponseProperty } from '@nestjs/swagger/dist/decorators/api-property.decorator'
14import { FirebaseTokenAuthGuard } from '../auth/auth.guard'
15import { CreateFavoriteDto } from './dto/create-favorite.dto'
16import { UpdateFavoriteDto } from './dto/update-favorite.dto'
17import { Favorite } from './favorite.schema'
18import { FavoriteService } from './favorite.service'
19
20class CreateFavoriteResponse extends Favorite {
21@ApiResponseProperty()
22_id: string
23}
24
25@Controller('favorite')
26@FirebaseTokenAuthGuard()
27@UsePipes(new ValidationPipe({ whitelist: true }))
28export class FavoriteController {
29constructor(private readonly favoriteService: FavoriteService) {}
30
31@Post()
32@ApiCreatedResponse({
33type: CreateFavoriteResponse
34})
35public async create(@Body() createFavoriteDto: CreateFavoriteDto) {
36return await this.favoriteService.create(createFavoriteDto)
37}
38
39@Get()
40public async findAllForUser(userId: string) {
41return await this.favoriteService.findAllForUser(userId)
42}
43
44@Get(':id')
45@ApiParam({ name: 'id', type: 'string', required: true })
46public async findOne(@Param('id') id: string) {
47return await this.favoriteService.findOne(id)
48}
49
50@Patch(':id')
51@ApiParam({ name: 'id', type: 'string', required: true })
52public async update(
53@Param('id') id: string,
54@Body() updateFavoriteDto: UpdateFavoriteDto
55) {
56return await this.favoriteService.update(id, updateFavoriteDto)
57}
58
59@Delete(':id')
60@ApiParam({ name: 'id', type: 'string', required: true })
61public async remove(@Param('id') id: string) {
62return await this.favoriteService.remove(id)
63}
64}
65