All files / src/domains/hr/attendance/shift/assignment assignment.controller.ts

0% Statements 0/17
0% Branches 0/10
0% Functions 0/4
0% Lines 0/15

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                                                                                                                               
import {
  Controller,
  Get,
  Post,
  Body,
  Param,
  UseGuards,
  Request,
  Query,
} from '@nestjs/common';
import { ShiftAssignmentService } from './assignment.service';
import { AssignShiftDto } from './dto/assignment.dto';
import { PermissionGuard } from '../../../../../platform/permissions/permission.guard';
import { RequirePermission } from '../../../../../platform/permissions/permission.decorator';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
 
@Controller('shift-assignments')
@UseGuards(PermissionGuard)
@ApiTags('ShiftAssignment')
export class ShiftAssignmentController {
  constructor(private readonly assignmentService: ShiftAssignmentService) {}
 
  @Post()
  @RequirePermission('shift_assignment', 'update')
  @ApiOperation({ summary: 'Assign shift operation' })
  @ApiResponse({ status: 201, description: 'Operation successful' })
  assignShift(@Request() req: any, @Body() assignDto: AssignShiftDto) {
    return this.assignmentService.assignShift(req.user.tenantId, assignDto);
  }
 
  @Get('employee/:employeeId')
  @RequirePermission('shift_assignment', 'read')
  @ApiOperation({ summary: 'Get employee assignments operation' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  getEmployeeAssignments(
    @Request() req: any,
    @Param('employeeId') employeeId: string,
  ) {
    return this.assignmentService.getEmployeeAssignments(
      req.user.tenantId,
      employeeId,
    );
  }
 
  @Get('employee/:employeeId/active')
  @RequirePermission('shift_assignment', 'read')
  @ApiOperation({ summary: 'Get active shift for employee on date operation' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  getActiveShiftForEmployeeOnDate(
    @Request() req: any,
    @Param('employeeId') employeeId: string,
    @Query('date') targetDateString: string,
  ) {
    const targetDate = targetDateString
      ? new Date(targetDateString)
      : new Date();
    return this.assignmentService.getActiveShiftForEmployeeOnDate(
      req.user.tenantId,
      employeeId,
      targetDate,
    );
  }
}