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 | import { Controller, Get, Post, Body, Param, UseGuards, Request, } from '@nestjs/common'; import { LeaveBalanceEngine } from './leave-balance.engine'; import { PermissionGuard } from '../../../../platform/permissions/permission.guard'; import { RequirePermission } from '../../../../platform/permissions/permission.decorator'; import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger'; @Controller('v1/leave/balances') @UseGuards(PermissionGuard) @ApiTags('LeaveBalance') export class LeaveBalanceController { constructor(private readonly balanceEngine: LeaveBalanceEngine) {} @Get('my') @RequirePermission('leave.balance', 'read') @ApiOperation({ summary: 'Get my balances operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) getMyBalances(@Request() req: any) { const { tenantId, employeeId } = req.user; // In real app, resolve current period first const leavePeriodId = req.query.periodId; return this.balanceEngine.getAllBalancesForEmployee( tenantId, employeeId, leavePeriodId, ); } @Get('employee/:employeeId') @RequirePermission('leave.balance', 'read') @ApiOperation({ summary: 'Get employee balances operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) getEmployeeBalances( @Request() req: any, @Param('employeeId') employeeId: string, ) { const { tenantId } = req.user; const leavePeriodId = req.query.periodId; return this.balanceEngine.getAllBalancesForEmployee( tenantId, employeeId, leavePeriodId, ); } @Get('employee/:employeeId/history') @RequirePermission('leave.balance', 'read') @ApiOperation({ summary: 'Get ledger history operation' }) @ApiResponse({ status: 200, description: 'Operation successful' }) getLedgerHistory( @Request() req: any, @Param('employeeId') employeeId: string, ) { const { tenantId } = req.user; const { leaveTypeId, periodId } = req.query; return this.balanceEngine.getLedgerHistory( tenantId, employeeId, leaveTypeId, periodId, ); } @Post('adjust') @RequirePermission('leave.balance', 'adjust') @ApiOperation({ summary: 'Adjust balance operation' }) @ApiResponse({ status: 201, description: 'Operation successful' }) adjustBalance(@Request() req: any, @Body() dto: any) { return this.balanceEngine.applyAdjustment( req.user.tenantId, dto, req.user.userId, ); } @Post('recalculate') @RequirePermission('leave.balance', 'recalculate') @ApiOperation({ summary: 'Recalculate operation' }) @ApiResponse({ status: 201, description: 'Operation successful' }) recalculate(@Request() req: any, @Body() dto: any) { // Trigger snapshot + recompute for a given employee+type+period return this.balanceEngine.createSnapshot( req.user.tenantId, dto.employeeId, dto.leaveTypeId, dto.leavePeriodId, 'manual', dto.lastLedgerId || 'none', ); } } |