All files / src/interfaces/mobile-api/employee mobile-inventory.controller.ts

0% Statements 0/32
0% Branches 0/12
0% Functions 0/9
0% Lines 0/30

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                                                                                                                                             
import { Controller, Get, Post, Body, Param, Req, Query } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { InventoryService } from '../../../domains/inventory/services/inventory.service';
 
@ApiTags('MobileInventory')
@ApiBearerAuth()
@Controller('api/v1/mobile/inventory')
export class MobileInventoryController {
  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 };
  }
 
  @Get('dashboard')
  @ApiOperation({ summary: 'Warehouse operator stats overview' })
  async getDashboard(@Req() req: any) {
    const ctx = this.getContext(req);
    const config = await this.inventoryService.configService.getConfiguration(ctx.tenantId);
    const items = await this.inventoryService.itemService.getItems(ctx.tenantId);
    const transfers = await this.inventoryService.movementService.getTransfers(ctx.tenantId);
 
    return {
      activeWarehousesCount: 1,
      catalogItemsCount: items.length,
      pendingTransfersCount: transfers.filter(t => t.status === 'approved' || t.status === 'dispatched').length,
      negativeStockAllowed: config.negativeStockAllowed,
    };
  }
 
  @Get('lookup')
  @ApiOperation({ summary: 'Barcode lookup check for scanner app' })
  async lookupItem(@Query('code') barcode: string, @Req() req: any) {
    const ctx = this.getContext(req);
    // Find item matching barcode/code
    const item = await this.inventoryService.itemService.getItemByCode(ctx.tenantId, barcode);
    const balances = await this.inventoryService.ledgerService.getBalances(ctx.tenantId, { itemCode: item.itemCode });
 
    return {
      itemCode: item.itemCode,
      itemName: item.itemName,
      baseUom: item.baseUom,
      trackingType: item.trackingType,
      availableStock: balances.reduce((sum, b) => sum + b.quantityAvailable, 0),
    };
  }
 
  @Post('transfers/:id/dispatch')
  @ApiOperation({ summary: 'Scan and 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: 'Scan and receive transfer 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);
  }
 
  @Post('counts/:id/enter')
  @ApiOperation({ summary: 'Enter count values from scanner' })
  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);
  }
}