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 | import { Controller, Get, Post, Put, Body, Param, Req, Query } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger'; import { InventoryService } from '../services/inventory.service'; @ApiTags('Inventory') @ApiBearerAuth() @Controller('api/v1/inventory') export class InventoryController { constructor(private readonly inventoryService: InventoryService) {} 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'; return { tenantId, userId }; } @Post('seed') @ApiOperation({ summary: 'Seed initial inventory configurations and items' }) async seed(@Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.seed(ctx.tenantId); } // ========================================================================= // CONFIGURATIONS // ========================================================================= @Get('configuration') @ApiOperation({ summary: 'Get inventory configurations settings' }) async getConfiguration(@Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.configService.getConfiguration(ctx.tenantId); } @Put('configuration') @ApiOperation({ summary: 'Update inventory configurations settings' }) async updateConfiguration(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.configService.updateConfiguration(ctx.tenantId, body); } // ========================================================================= // ITEMS // ========================================================================= @Get('items') @ApiOperation({ summary: 'List all inventory items' }) async getItems(@Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.itemService.getItems(ctx.tenantId); } @Post('items') @ApiOperation({ summary: 'Create new inventory item' }) async createItem(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.itemService.createItem(ctx.tenantId, body); } @Get('items/:code') @ApiOperation({ summary: 'Get item detail by code' }) async getItemByCode(@Param('code') code: string, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.itemService.getItemByCode(ctx.tenantId, code); } // ========================================================================= // WAREHOUSES // ========================================================================= @Get('warehouses') @ApiOperation({ summary: 'List all warehouses' }) async getWarehouses(@Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.warehouseService.getWarehouses(ctx.tenantId); } @Post('warehouses') @ApiOperation({ summary: 'Create warehouse' }) async createWarehouse(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.warehouseService.createWarehouse(ctx.tenantId, body); } @Post('locations') @ApiOperation({ summary: 'Create storage bin location' }) async createLocation(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.warehouseService.createLocation(ctx.tenantId, body); } @Get('warehouses/:id/locations') @ApiOperation({ summary: 'Get locations for warehouse' }) async getLocations(@Param('id') warehouseId: string, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.warehouseService.getLocations(ctx.tenantId, warehouseId); } // ========================================================================= // STOCK LEDGER & BALANCES // ========================================================================= @Get('balances') @ApiOperation({ summary: 'List stock balances' }) async getBalances(@Query() query: any, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.ledgerService.getBalances(ctx.tenantId, query); } @Get('ledger') @ApiOperation({ summary: 'Get stock ledger entries' }) async getLedgerEntries(@Query('itemCode') itemCode: string, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.ledgerService.getLedgerEntries(ctx.tenantId, itemCode); } // ========================================================================= // BATCHES & SERIALS // ========================================================================= @Get('batches') @ApiOperation({ summary: 'List item batches' }) async getBatches(@Query('itemCode') itemCode: string, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.batchSerialService.getBatches(ctx.tenantId, itemCode); } @Get('serials') @ApiOperation({ summary: 'List item serial numbers' }) async getSerials(@Query('itemCode') itemCode: string, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.batchSerialService.getSerials(ctx.tenantId, itemCode); } // ========================================================================= // RESERVATIONS // ========================================================================= @Post('reservations') @ApiOperation({ summary: 'Create stock reservation' }) async createReservation(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.reservationService.createReservation(ctx.tenantId, body); } @Post('reservations/:id/release') @ApiOperation({ summary: 'Release stock reservation' }) async releaseReservation(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.reservationService.releaseReservation(ctx.tenantId, id); } // ========================================================================= // TRANSFERS // ========================================================================= @Get('transfers') @ApiOperation({ summary: 'List all transfer orders' }) async getTransfers(@Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.movementService.getTransfers(ctx.tenantId); } @Post('transfers') @ApiOperation({ summary: 'Create transfer order' }) async createTransfer(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.movementService.createTransfer(ctx.tenantId, body); } @Post('transfers/:id/dispatch') @ApiOperation({ summary: 'Dispatch transfer order' }) async dispatchTransfer(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.movementService.dispatchTransfer(ctx.tenantId, id, ctx.userId); } @Post('transfers/:id/receive') @ApiOperation({ summary: 'Receive transfer order lines' }) async receiveTransfer(@Param('id') id: string, @Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.movementService.receiveTransfer(ctx.tenantId, id, body.lines, ctx.userId); } // ========================================================================= // ADJUSTMENTS // ========================================================================= @Get('adjustments') @ApiOperation({ summary: 'List stock adjustments' }) async getAdjustments(@Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.adjustmentService.getAdjustments(ctx.tenantId); } @Post('adjustments') @ApiOperation({ summary: 'Create stock adjustment' }) async createAdjustment(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.adjustmentService.createAdjustment(ctx.tenantId, body); } @Post('adjustments/:id/approve') @ApiOperation({ summary: 'Approve stock adjustment' }) async approveAdjustment(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.adjustmentService.approveAdjustment(ctx.tenantId, id, ctx.userId); } // ========================================================================= // COUNTS // ========================================================================= @Get('counts') @ApiOperation({ summary: 'List inventory counting sessions' }) async getCountSessions(@Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.countService.getCountSessions(ctx.tenantId); } @Post('counts') @ApiOperation({ summary: 'Create inventory count session' }) async createCountSession(@Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.countService.createCountSession(ctx.tenantId, body); } @Post('counts/:id/enter') @ApiOperation({ summary: 'Enter counting lines values' }) async enterCount(@Param('id') id: string, @Body() body: any, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.countService.enterCount(ctx.tenantId, id, body.lines); } @Post('counts/:id/approve') @ApiOperation({ summary: 'Approve count session and post variances' }) async approveCountSession(@Param('id') id: string, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.countService.approveCountSession(ctx.tenantId, id, ctx.userId); } // ========================================================================= // REPLENISHMENT & VALUATION & TRACEABILITY // ========================================================================= @Post('replenishment/calculate') @ApiOperation({ summary: 'Calculate replenishment reorder recommendations' }) async calculateReplenishment(@Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.replenishmentService.calculateReplenishmentSuggestions(ctx.tenantId); } @Get('valuation/layers') @ApiOperation({ summary: 'Get cost layers' }) async getCostLayers(@Query('itemCode') itemCode: string, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.valuationService.getCostLayers(ctx.tenantId, itemCode); } @Get('traceability/item/:code') @ApiOperation({ summary: 'Get item traceability timeline graph' }) async getItemTraceability(@Param('code') code: string, @Req() req: any) { const ctx = this.getContext(req); return this.inventoryService.traceabilityService.getItemTraceability(ctx.tenantId, code); } } |