All files / sales sales.controller.ts

0% Statements 0/23
0% Branches 0/6
0% Functions 0/8
0% Lines 0/21

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 58 59 60 61 62 63 64 65 66 67                                                                                                                                     
import { Controller, Get, Post, Put, Body, Param, Query, UseGuards } from '@nestjs/common';
import { SalesService } from './sales.service';
import { JwtAuthGuard } from '../../platform/auth/jwt-auth.guard';
 
@Controller('api/v1/sales')
@UseGuards(JwtAuthGuard)
export class SalesController {
  constructor(private readonly salesService: SalesService) {}
 
  @Put('quotations/:id/revise')
  async reviseQuotation(
    @Param('id') quotationId: string,
    @Query('tenantId') tenantId: string,
    @Body() body: any
  ) {
    return this.salesService.reviseQuotation(tenantId, quotationId, body);
  }
 
  @Put('contracts/:id/amend')
  async amendContract(
    @Param('id') contractId: string,
    @Query('tenantId') tenantId: string,
    @Body() body: any
  ) {
    return this.salesService.amendContract(tenantId, contractId, body);
  }
 
  @Post('orders')
  async createSalesOrder(@Query('tenantId') tenantId: string, @Body() body: any) {
    return this.salesService.createSalesOrder(tenantId, body);
  }
 
  @Put('orders/:id/approve')
  async approveSalesOrder(
    @Param('id') orderId: string,
    @Query('tenantId') tenantId: string,
    @Query('managerId') managerId: string
  ) {
    return this.salesService.approveSalesOrder(tenantId, orderId, managerId);
  }
 
  @Get('cpq/price')
  async getPrice(
    @Query('tenantId') tenantId: string,
    @Query('productId') productId: string,
    @Query('quantity') quantity: string,
    @Query('priceBookId') priceBookId?: string
  ) {
    const qty = parseInt(quantity, 10) || 1;
    const price = await this.salesService.calculateCPQPrice(tenantId, productId, qty, priceBookId);
    return { unitPriceMinor: price };
  }
 
  @Post('subscriptions')
  async createSubscription(@Query('tenantId') tenantId: string, @Body() body: any) {
    return this.salesService.createSubscription(tenantId, body);
  }
 
  @Get('customer360/:accountId')
  async getCustomer360(
    @Param('accountId') accountId: string,
    @Query('tenantId') tenantId: string
  ) {
    return this.salesService.getCustomer360Profile(tenantId, accountId);
  }
}