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

76.92% Statements 10/13
75% Branches 3/4
33.33% Functions 1/3
72.72% Lines 8/11

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 2811x 11x 11x 11x       11x 11x     11x               11x                
import { Body, Controller, Get, Param, ParseIntPipe, Patch, Req, UseGuards } from '@nestjs/common';
import { JwtAuthGuard } from '@app/common/guards/jwt-auth.guard';
import { PrismaService } from '@app/modules/prisma/prisma.service';
import { LeadOwnerGuard } from '@app/modules/leads/lead.guard';
 
@Controller('leads')
@UseGuards(JwtAuthGuard)
export class LeadsController {
  constructor(private readonly prisma: PrismaService) {}
 
  @Get('me')
  listMine(@Req() req: any) {
    const user = req.user as { id: number };
    // @ts-ignore
    return this.prisma.client.lead.findMany({ where: { agentId: user.id }, orderBy: { createdAt: 'desc' } });
  }
 
  @Patch(':id/status')
  @UseGuards(LeadOwnerGuard)
  async updateStatus(
    @Param('id', ParseIntPipe) id: number,
    @Body() body: { status: string },
  ) {
    // @ts-ignore
    return this.prisma.client.lead.update({ where: { id }, data: { status: body.status } });
  }
}