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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | import { Controller, Get, Post, Put, Body, Param, Req } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth } from '@nestjs/swagger'; import { ProcurementService } from '../services/procurement.service'; @ApiTags('Procurement') @ApiBearerAuth() @Controller('api/v1/procurement') export class ProcurementController { constructor(private readonly procurementService: ProcurementService) {} private getContext(req: any) { const tenantId = req.user?.tenantId || req.headers['x-tenant-id'] || 'SYSTEM'; const userId = req.user?.id || req.headers['x-user-id'] || 'system'; const employeeId = req.user?.employeeId || req.headers['x-employee-id'] || 'SYSTEM'; return { tenantId, userId, employeeId }; } // ========================================================================= // VENDORS // ========================================================================= @Get('vendors') @ApiOperation({ summary: 'Get all vendors' }) @ApiResponse({ status: 200, description: 'List of vendors' }) async getVendors(@Req() req: any) { const ctx = this.getContext(req); return this.procurementService.vendorService.getVendors(ctx.tenantId); } @Post('vendors') @ApiOperation({ summary: 'Create a new vendor' }) @ApiResponse({ status: 201, description: 'Vendor created successfully' }) async createVendor(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.vendorService.createVendor(ctx.tenantId, body, ctx.userId); } @Get('vendors/:id') @ApiOperation({ summary: 'Get vendor details by ID' }) async getVendorById(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.vendorService.getVendorById(ctx.tenantId, id, ctx.userId); } @Put('vendors/:id') @ApiOperation({ summary: 'Update vendor details' }) async updateVendor(@Param('id') id: string, @Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.vendorService.updateVendor(ctx.tenantId, id, body, ctx.userId); } @Post('vendors/:id/approve-kyc') @ApiOperation({ summary: 'Approve vendor KYC' }) async approveKyc(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.vendorService.approveKyc(ctx.tenantId, id, ctx.userId); } @Post('vendors/:id/block') @ApiOperation({ summary: 'Block vendor' }) async blockVendor(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.vendorService.blockVendor(ctx.tenantId, id, ctx.userId); } // ========================================================================= // CONFIGURATIONS // ========================================================================= @Get('configuration') @ApiOperation({ summary: 'Get configuration settings' }) async getConfiguration(@Req() req: any) { const ctx = this.getContext(req); return this.procurementService.configService.getConfiguration(ctx.tenantId); } @Put('configuration') @ApiOperation({ summary: 'Update configuration settings' }) async updateConfiguration(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.configService.updateConfiguration(ctx.tenantId, body); } // ========================================================================= // PURCHASE REQUISITIONS // ========================================================================= @Get('requisitions') @ApiOperation({ summary: 'Get all requisitions' }) async getRequisitions(@Req() req: any) { const ctx = this.getContext(req); return this.procurementService.requisitionService.getRequisitions(ctx.tenantId); } @Post('requisitions') @ApiOperation({ summary: 'Submit purchase requisition' }) async createRequisition(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.requisitionService.createRequisition(ctx.tenantId, ctx.employeeId, body, ctx.userId); } @Get('requisitions/:id') @ApiOperation({ summary: 'Get requisition details by ID' }) async getRequisitionById(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.requisitionService.getRequisitionById(ctx.tenantId, id); } @Post('requisitions/:id/approve') @ApiOperation({ summary: 'Approve a purchase requisition' }) async approveRequisition(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.requisitionService.approveRequisition(ctx.tenantId, id, ctx.userId); } @Post('requisitions/:id/reject') @ApiOperation({ summary: 'Reject a purchase requisition' }) async rejectRequisition(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.requisitionService.rejectRequisition(ctx.tenantId, id, ctx.userId); } // ========================================================================= // RFQS / SOURCING // ========================================================================= @Get('rfqs') @ApiOperation({ summary: 'List all RFQs' }) async getRfqs(@Req() req: any) { const ctx = this.getContext(req); return this.procurementService.sourcingService.getRfqs(ctx.tenantId); } @Post('rfqs') @ApiOperation({ summary: 'Create RFQ' }) async createRfq(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.sourcingService.createRfq(ctx.tenantId, body, ctx.userId); } @Get('rfqs/:id') @ApiOperation({ summary: 'Get RFQ by ID' }) async getRfqById(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.sourcingService.getRfqById(ctx.tenantId, id); } @Post('quotations') @ApiOperation({ summary: 'Submit vendor quotation' }) async submitQuotation(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.sourcingService.submitQuotation(ctx.tenantId, body, ctx.userId); } @Get('rfqs/:id/quotations') @ApiOperation({ summary: 'Get quotations for RFQ' }) async getQuotationsForRfq(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.sourcingService.getQuotationsForRfq(ctx.tenantId, id, ctx.userId); } @Post('quotations/:id/evaluate') @ApiOperation({ summary: 'Evaluate technical/commercial scores for quotation' }) async evaluateQuotation(@Param('id') id: string, @Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.sourcingService.evaluateQuotation(ctx.tenantId, id, body, ctx.userId); } @Post('quotations/:id/award') @ApiOperation({ summary: 'Award quotation' }) async awardQuotation(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.sourcingService.awardQuotation(ctx.tenantId, id, ctx.userId); } // ========================================================================= // PURCHASE ORDERS // ========================================================================= @Get('purchase-orders') @ApiOperation({ summary: 'Get all purchase orders' }) async getPurchaseOrders(@Req() req: any) { const ctx = this.getContext(req); return this.procurementService.poService.getPurchaseOrders(ctx.tenantId); } @Post('purchase-orders') @ApiOperation({ summary: 'Create purchase order' }) async createPurchaseOrder(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.poService.createPurchaseOrder(ctx.tenantId, body, ctx.userId); } @Get('purchase-orders/:id') @ApiOperation({ summary: 'Get purchase order details' }) async getPurchaseOrderById(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.poService.getPurchaseOrderById(ctx.tenantId, id); } @Post('purchase-orders/:id/approve') @ApiOperation({ summary: 'Approve a purchase order' }) async approvePurchaseOrder(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.poService.approvePurchaseOrder(ctx.tenantId, id, ctx.userId); } @Post('purchase-orders/:id/deliver') @ApiOperation({ summary: 'Deliver a purchase order (legacy direct action)' }) async deliverPurchaseOrder(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.poService.recordReceipt(ctx.tenantId, id, 'fully_received'); } // ========================================================================= // RECEIPTS // ========================================================================= @Get('receipts/goods') @ApiOperation({ summary: 'Get all goods receipts' }) async getGoodsReceipts(@Req() req: any) { const ctx = this.getContext(req); return this.procurementService.receiptService.getGoodsReceipts(ctx.tenantId); } @Post('receipts/goods') @ApiOperation({ summary: 'Create goods receipt' }) async createGoodsReceipt(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.receiptService.createGoodsReceipt(ctx.tenantId, body, ctx.userId); } @Post('receipts/goods/:id/reverse') @ApiOperation({ summary: 'Reverse a goods receipt' }) async reverseGoodsReceipt(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.receiptService.reverseGoodsReceipt(ctx.tenantId, id, ctx.userId); } @Get('receipts/services') @ApiOperation({ summary: 'Get all service receipts' }) async getServiceReceipts(@Req() req: any) { const ctx = this.getContext(req); return this.procurementService.receiptService.getServiceReceipts(ctx.tenantId); } @Post('receipts/services') @ApiOperation({ summary: 'Create service receipt' }) async createServiceReceipt(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.receiptService.createServiceReceipt(ctx.tenantId, body, ctx.userId); } // ========================================================================= // INSPECTIONS // ========================================================================= @Get('inspections') @ApiOperation({ summary: 'Get all inspections' }) async getInspections(@Req() req: any) { const ctx = this.getContext(req); return this.procurementService.inspectionService.getInspections(ctx.tenantId); } @Post('inspections') @ApiOperation({ summary: 'Create quality inspection decision' }) async createInspection(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.inspectionService.createInspection(ctx.tenantId, body, ctx.userId); } // ========================================================================= // RETURNS // ========================================================================= @Get('returns') @ApiOperation({ summary: 'Get all returns' }) async getReturns(@Req() req: any) { const ctx = this.getContext(req); return this.procurementService.returnService.getReturns(ctx.tenantId); } @Post('returns') @ApiOperation({ summary: 'Create vendor return' }) async createReturn(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.returnService.createReturn(ctx.tenantId, body, ctx.userId); } // ========================================================================= // BILLS & 3-WAY MATCHING // ========================================================================= @Get('bills') @ApiOperation({ summary: 'Get all vendor bills' }) async getBills(@Req() req: any) { const ctx = this.getContext(req); return this.procurementService.billService.getBills(ctx.tenantId); } @Post('bills') @ApiOperation({ summary: 'Create vendor bill and run 3-way match' }) async createBill(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.billService.createBill(ctx.tenantId, body, ctx.userId); } @Get('bills/:id') @ApiOperation({ summary: 'Get bill details by ID' }) async getBillById(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.billService.getBillById(ctx.tenantId, id); } @Post('bills/:id/approve') @ApiOperation({ summary: 'Approve vendor bill' }) async approveBill(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.billService.approveBill(ctx.tenantId, id, ctx.userId); } @Post('bills/:id/release-hold') @ApiOperation({ summary: 'Release variance exception hold' }) async releaseHold(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.procurementService.billService.releaseHold(ctx.tenantId, id, ctx.userId); } // ========================================================================= // SEED // ========================================================================= @Post('seed') @ApiOperation({ summary: 'Seed procurement initial data' }) async seedData(@Req() req: any) { const ctx = this.getContext(req); await this.procurementService.seed(ctx.tenantId, ctx.userId); return { success: true }; } } |