All files / src/band band.controller.ts

90% Statements 18/20
100% Branches 0/0
80% Functions 4/5
88.88% Lines 16/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 586x                         6x 6x 6x   6x       6x 6x       6x                 6x 3x       6x       4x 4x       6x       2x 2x      
import {
  Controller,
  Post,
  Body,
  HttpCode,
  HttpStatus,
  Get,
  Put,
  Query,
  Req,
  UseGuards,
  Param,
} from '@nestjs/common';
import { BandService } from './band.service';
import { BandDto, CreateBandDto } from './dto/band.dto';
import { AuthGuard } from '../auth/auth.guard';
import { SearchBandDto } from './dto/search-band.dto';
import { UpdateBandDto } from './dto/update-band.dto';
 
@Controller('bands')
@UseGuards(AuthGuard)
export class BandController {
  constructor(private readonly bandService: BandService) {}
 
  @Post('/')
  @HttpCode(HttpStatus.CREATED)
  async createBand(
    @Req() req: Request,
    @Body() bandDTO: CreateBandDto,
  ): Promise<{ message: string }> {
    const founderId = (req as any).user.userId;
    return await this.bandService.create(bandDTO, founderId);
  }
 
  @Get('search')
  async searchBands(@Query('name') name: string): Promise<SearchBandDto[]> {
    return this.bandService.searchBands(name);
  }
 
  @Put()
  async updateBand(
    @Req() req: Request,
    @Body() updateBandDto: UpdateBandDto,
  ): Promise<{ message: string }> {
    const userId = (req as any).user.id;
    return await this.bandService.updateBand(userId, updateBandDto);
  }
 
  @Get(':id')
  async getBandById(
    @Req() req: Request,
    @Param('id') bandId: string,
  ): Promise<BandDto> {
    const userId = (req as any).user.id;
    return await this.bandService.getBandById(userId, bandId);
  }
}