All files / src/modules/promotions promotions.controller.ts

90.9% Statements 20/22
75% Branches 9/12
71.42% Functions 5/7
100% Lines 17/17

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 4212x 12x 12x 12x 12x     12x 12x 12x       12x 1x     12x       12x       1x       12x 1x         12x 1x          
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, Req, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from '@app/common/guards/jwt-auth.guard';
import { PromotionsService } from '@app/modules/promotions/promotions.service';
import { Type } from 'class-transformer';
import { IsDate, IsString } from 'class-validator';
 
class PromotionPurchaseDto {
  @IsString() sku!: 'HIGHLIGHT'|'URGENT'|'TOP_OF_LIST';
  @IsDate() @Type(() => Date) startAt!: Date;
  @IsDate() @Type(() => Date) endAt!: Date;
}
 
@Controller()
export class PromotionsController {
  constructor(private readonly promos: PromotionsService) {}
 
  @Get('promos/options')
  options() { return this.promos.options(); }
 
  @Post('listings/:id/promos')
  @UseGuards(JwtAuthGuard)
  purchase(
    @Param('id', ParseIntPipe) listingId: number,
    @Body() dto: PromotionPurchaseDto,
    @Req() req: any,
  ) { return this.promos.purchase(listingId, req.user.id, dto); }
 
  @Get('listings/:id/promos')
  @UseGuards(JwtAuthGuard)
  list(@Param('id', ParseIntPipe) listingId: number, @Req() req: any) {
    return this.promos.listForOwner(listingId, req.user.id);
  }
 
  @Delete('promos/:promoId')
  @UseGuards(JwtAuthGuard)
  cancel(@Param('promoId', ParseIntPipe) promoId: number, @Req() req: any) {
    return this.promos.cancel(promoId, req.user.id);
  }
}