All files / src/domains/hr/attendance/capture capture.controller.ts

0% Statements 0/20
0% Branches 0/16
0% Functions 0/5
0% Lines 0/18

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                                                                                                                                                                                       
import {
  Controller,
  Get,
  Post,
  Body,
  Param,
  UseGuards,
  Request,
  Ip,
  Query,
} from '@nestjs/common';
import { CaptureService } from './capture.service';
import { RecordPunchDto } from './dto/capture.dto';
import { PermissionGuard } from '../../../../platform/permissions/permission.guard';
import { RequirePermission } from '../../../../platform/permissions/permission.decorator';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
 
@Controller('attendance-capture')
@UseGuards(PermissionGuard)
@ApiTags('Capture')
export class CaptureController {
  constructor(private readonly captureService: CaptureService) {}
 
  @Post('punch')
  @RequirePermission('attendance_punch', 'create')
  @ApiOperation({ summary: 'Record punch operation' })
  @ApiResponse({ status: 201, description: 'Operation successful' })
  recordPunch(
    @Request() req: any,
    @Body() punchDto: RecordPunchDto,
    @Ip() ip: string,
  ) {
    // For self-punch, employeeId comes from JWT
    return this.captureService.recordPunch(
      req.user.tenantId,
      req.user.employeeId,
      punchDto,
      req.user.userId,
      ip,
    );
  }
 
  @Post('punch/employee/:employeeId')
  @RequirePermission('attendance_punch', 'manage')
  @ApiOperation({ summary: 'Record punch for employee operation' })
  @ApiResponse({ status: 201, description: 'Operation successful' }) // Admin punching for someone else
  recordPunchForEmployee(
    @Request() req: any,
    @Param('employeeId') employeeId: string,
    @Body() punchDto: RecordPunchDto,
    @Ip() ip: string,
  ) {
    return this.captureService.recordPunch(
      req.user.tenantId,
      employeeId,
      punchDto,
      req.user.userId,
      ip,
    );
  }
 
  @Get('punches')
  @RequirePermission('attendance_punch', 'read')
  @ApiOperation({ summary: 'Get my punches operation' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  getMyPunches(@Request() req: any, @Query('date') date: string) {
    const targetDate = date || new Date().toISOString().split('T')[0];
    return this.captureService.getEmployeePunches(
      req.user.tenantId,
      req.user.employeeId,
      targetDate,
    );
  }
 
  @Get('punches/employee/:employeeId')
  @RequirePermission('attendance_punch', 'manage')
  @ApiOperation({ summary: 'Get employee punches operation' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  getEmployeePunches(
    @Request() req: any,
    @Param('employeeId') employeeId: string,
    @Query('date') date: string,
  ) {
    const targetDate = date || new Date().toISOString().split('T')[0];
    return this.captureService.getEmployeePunches(
      req.user.tenantId,
      employeeId,
      targetDate,
    );
  }
}