universo-platform-3d

Форк
0
64 строки · 1.8 Кб
1
import {
2
  Body,
3
  Controller,
4
  Delete,
5
  Get,
6
  Param,
7
  Patch,
8
  Post,
9
  UsePipes,
10
  ValidationPipe
11
} from '@nestjs/common'
12
import { ApiCreatedResponse, ApiParam } from '@nestjs/swagger'
13
import { ApiResponseProperty } from '@nestjs/swagger/dist/decorators/api-property.decorator'
14
import { FirebaseTokenAuthGuard } from '../auth/auth.guard'
15
import { CreateFavoriteDto } from './dto/create-favorite.dto'
16
import { UpdateFavoriteDto } from './dto/update-favorite.dto'
17
import { Favorite } from './favorite.schema'
18
import { FavoriteService } from './favorite.service'
19

20
class CreateFavoriteResponse extends Favorite {
21
  @ApiResponseProperty()
22
  _id: string
23
}
24

25
@Controller('favorite')
26
@FirebaseTokenAuthGuard()
27
@UsePipes(new ValidationPipe({ whitelist: true }))
28
export class FavoriteController {
29
  constructor(private readonly favoriteService: FavoriteService) {}
30

31
  @Post()
32
  @ApiCreatedResponse({
33
    type: CreateFavoriteResponse
34
  })
35
  public async create(@Body() createFavoriteDto: CreateFavoriteDto) {
36
    return await this.favoriteService.create(createFavoriteDto)
37
  }
38

39
  @Get()
40
  public async findAllForUser(userId: string) {
41
    return await this.favoriteService.findAllForUser(userId)
42
  }
43

44
  @Get(':id')
45
  @ApiParam({ name: 'id', type: 'string', required: true })
46
  public async findOne(@Param('id') id: string) {
47
    return await this.favoriteService.findOne(id)
48
  }
49

50
  @Patch(':id')
51
  @ApiParam({ name: 'id', type: 'string', required: true })
52
  public async update(
53
    @Param('id') id: string,
54
    @Body() updateFavoriteDto: UpdateFavoriteDto
55
  ) {
56
    return await this.favoriteService.update(id, updateFavoriteDto)
57
  }
58

59
  @Delete(':id')
60
  @ApiParam({ name: 'id', type: 'string', required: true })
61
  public async remove(@Param('id') id: string) {
62
    return await this.favoriteService.remove(id)
63
  }
64
}
65

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.