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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | import { Controller, Get, Post, Put, Body, Param, Query, UseGuards, Request, } from '@nestjs/common'; import { ProductPricingService } from '../services/product-pricing.service'; import { PermissionGuard } from '../../../platform/permissions/permission.guard'; import { RequirePermission } from '../../../platform/permissions/permission.decorator'; import { Types } from 'mongoose'; import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger'; @Controller('crm/products-pricing') @UseGuards(PermissionGuard) @ApiTags('ProductPricing') export class ProductPricingController { constructor(private readonly productPricingService: ProductPricingService) {} // ── CATEGORIES ── @Post('categories') @RequirePermission('crm_config', 'update') @ApiOperation({ summary: 'Create category operation' }) @ApiResponse({ status: 201, description: 'Operation successful' }) async createCategory(@Request() req: any, @Body() body: any) { const tenantId = new Types.ObjectId(req.user.tenantId); return this.productPricingService.createCategory(tenantId, body); } @Get('categories') @RequirePermission('crm_config', 'read') @ApiOperation({ summary: 'List categories operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async listCategories(@Request() req: any) { const tenantId = new Types.ObjectId(req.user.tenantId); return this.productPricingService.listCategories(tenantId); } // ── PRODUCTS ── @Post('products') @RequirePermission('crm_product', 'create') @ApiOperation({ summary: 'Create product operation' }) @ApiResponse({ status: 201, description: 'Operation successful' }) async createProduct(@Request() req: any, @Body() body: any) { const tenantId = new Types.ObjectId(req.user.tenantId); return this.productPricingService.createProduct(tenantId, body); } @Get('products') @RequirePermission('crm_product', 'read') @ApiOperation({ summary: 'List products operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async listProducts( @Request() req: any, @Query('categoryId') categoryId?: string, @Query('active') active?: string, @Query('type') type?: string, @Query('search') search?: string, @Query('page') page?: number, @Query('limit') limit?: number, ) { const tenantId = new Types.ObjectId(req.user.tenantId); const act = active === 'true' ? true : active === 'false' ? false : undefined; return this.productPricingService.listProducts( tenantId, { categoryId, active: act, type, search }, page ? Number(page) : 1, limit ? Number(limit) : 25, ); } @Get('products/:id') @RequirePermission('crm_product', 'read') @ApiOperation({ summary: 'Get product by id operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async getProductById(@Request() req: any, @Param('id') id: string) { const tenantId = new Types.ObjectId(req.user.tenantId); return this.productPricingService.getProductById(tenantId, id); } @Put('products/:id') @RequirePermission('crm_product', 'update') @ApiOperation({ summary: 'Update product operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async updateProduct( @Request() req: any, @Param('id') id: string, @Body() body: any, ) { const tenantId = new Types.ObjectId(req.user.tenantId); return this.productPricingService.updateProduct(tenantId, id, body); } // ── PRICE BOOKS ── @Post('price-books') @RequirePermission('crm_config', 'update') @ApiOperation({ summary: 'Create price book operation' }) @ApiResponse({ status: 201, description: 'Operation successful' }) async createPriceBook(@Request() req: any, @Body() body: any) { const tenantId = new Types.ObjectId(req.user.tenantId); return this.productPricingService.createPriceBook(tenantId, body); } @Get('price-books') @RequirePermission('crm_config', 'read') @ApiOperation({ summary: 'List price books operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async listPriceBooks(@Request() req: any) { const tenantId = new Types.ObjectId(req.user.tenantId); return this.productPricingService.listPriceBooks(tenantId); } @Post('price-books/entries') @RequirePermission('crm_config', 'update') @ApiOperation({ summary: 'Add price book entry operation' }) @ApiResponse({ status: 201, description: 'Operation successful' }) async addPriceBookEntry(@Request() req: any, @Body() body: any) { const tenantId = new Types.ObjectId(req.user.tenantId); return this.productPricingService.addPriceBookEntry(tenantId, body); } @Get('price-books/:priceBookId/entries') @RequirePermission('crm_config', 'read') @ApiOperation({ summary: 'Get price book entries operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async getPriceBookEntries( @Request() req: any, @Param('priceBookId') priceBookId: string, ) { const tenantId = new Types.ObjectId(req.user.tenantId); return this.productPricingService.getPriceBookEntries( tenantId, priceBookId, ); } @Get('resolve-price') @RequirePermission('crm_product', 'read') @ApiOperation({ summary: 'Resolve price operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async resolvePrice( @Request() req: any, @Query('productId') productId: string, @Query('quantity') quantity: number, @Query('priceBookId') priceBookId?: string, ) { const tenantId = new Types.ObjectId(req.user.tenantId); return this.productPricingService.resolvePrice( tenantId, productId, Number(quantity), priceBookId, ); } // ── LOSS REASONS ── @Post('loss-reasons') @RequirePermission('crm_config', 'update') @ApiOperation({ summary: 'Create loss reason operation' }) @ApiResponse({ status: 201, description: 'Operation successful' }) async createLossReason(@Request() req: any, @Body() body: any) { const tenantId = new Types.ObjectId(req.user.tenantId); return this.productPricingService.createLossReason(tenantId, body); } @Get('loss-reasons') @RequirePermission('crm_config', 'read') @ApiOperation({ summary: 'List loss reasons operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) async listLossReasons(@Request() req: any) { const tenantId = new Types.ObjectId(req.user.tenantId); return this.productPricingService.listLossReasons(tenantId); } } |