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

68.75% Statements 11/16
66.66% Branches 8/12
0% Functions 0/3
64.28% Lines 9/14

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 3311x 11x 11x 11x 11x 11x         11x           11x                       11x        
import { Body, Controller, Param, ParseIntPipe, Post, Req } from '@nestjs/common';
import { BoostService } from '@app/modules/boost/boost.service';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { CreateBoostDto } from '@app/modules/boost/dto/create-boost.dto';
import { Roles } from '@app/common/decorators/roles.decorator';
import { Request } from 'express';
 
@ApiTags('Boost')
@ApiBearerAuth()
@Controller()
export class BoostController {
  constructor(private readonly boostService: BoostService) {}
 
  @Post('/listings/:id/boost')
  @Roles('AGENT', 'ADMIN')
  @ApiOperation({ summary: 'Create boost checkout session', description: 'Roles: AGENT or ADMIN.' })
  async createBoost(
    @Param('id', ParseIntPipe) listingId: number,
    @Body() dto: CreateBoostDto,
    @Req() req: Request,
  ) {
    // Assume req.user.id is set by auth middleware
    const userId = (req as any).user.id;
    return this.boostService.createSession(listingId, dto.tier, userId);
  }
 
  @Post('/boost/webhook')
  @ApiOperation({ summary: 'Boost payment webhook' })
  async boostWebhook(@Body() body: { listingId: number; success: boolean }) {
    await this.boostService.handleWebhook(body.listingId, body.success);
    return { ok: true };
  }
}