All files / src/domains/hr/dashboard dashboard.controller.ts

0% Statements 0/27
0% Branches 0/10
0% Functions 0/10
0% Lines 0/25

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                                                                                                                                                                                                                                                                                       
import { Controller, Get, Query, Request, UseGuards } from '@nestjs/common';
import { HrDashboardService } from './dashboard.service';
import {
  ApiTags,
  ApiBearerAuth,
  ApiOperation,
  ApiResponse,
} from '@nestjs/swagger';
 
import { PermissionGuard } from '../../../platform/permissions/permission.guard';
import { RequirePermission } from '../../../platform/permissions/permission.decorator';
 
@ApiTags('HR - Dashboard')
@ApiBearerAuth()
@UseGuards(PermissionGuard)
@Controller('api/v1/hr/dashboard')
export class HrDashboardController {
  constructor(private readonly dashboardService: HrDashboardService) {}
 
  @Get('summary')
  @RequirePermission('hr.employee', 'read')
  @ApiOperation({ summary: 'Get summary operation' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async getSummary(@Request() req: any) {
    return {
      success: true,
      data: await this.dashboardService.getSummary(req.user.tenantId),
    };
  }
 
  @Get('headcount-trend')
  @RequirePermission('hr.employee', 'read')
  @ApiOperation({ summary: 'Get headcount trend operation' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async getHeadcountTrend(
    @Request() req: any,
    @Query('months') months: string,
  ) {
    return {
      success: true,
      data: await this.dashboardService.getHeadcountTrend(
        req.user.tenantId,
        months ? +months : 12,
      ),
    };
  }
 
  @Get('employee-status')
  @RequirePermission('hr.employee', 'read')
  @ApiOperation({ summary: 'Get status distribution operation' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async getStatusDistribution(@Request() req: any) {
    return {
      success: true,
      data: await this.dashboardService.getStatusDistribution(
        req.user.tenantId,
      ),
    };
  }
 
  @Get('department-distribution')
  @RequirePermission('hr.employee', 'read')
  @ApiOperation({ summary: 'Get dept distribution operation' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async getDeptDistribution(@Request() req: any) {
    return {
      success: true,
      data: await this.dashboardService.getHeadcountByDepartment(
        req.user.tenantId,
      ),
    };
  }
 
  @Get('branch-distribution')
  @RequirePermission('hr.employee', 'read')
  @ApiOperation({ summary: 'Get branch distribution operation' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async getBranchDistribution(@Request() req: any) {
    return {
      success: true,
      data: await this.dashboardService.getHeadcountByBranch(req.user.tenantId),
    };
  }
 
  @Get('employment-types')
  @RequirePermission('hr.employee', 'read')
  @ApiOperation({ summary: 'Get employment types operation' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async getEmploymentTypes(@Request() req: any) {
    return {
      success: true,
      data: await this.dashboardService.getEmploymentTypeDistribution(
        req.user.tenantId,
      ),
    };
  }
 
  @Get('new-joiners')
  @RequirePermission('hr.employee', 'read')
  @ApiOperation({ summary: 'Get new joiners operation' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async getNewJoiners(@Request() req: any, @Query('days') days: string) {
    return {
      success: true,
      data: await this.dashboardService.getNewJoiners(
        req.user.tenantId,
        days ? +days : 30,
      ),
    };
  }
 
  @Get('upcoming-confirmations')
  @RequirePermission('hr.employee', 'read')
  @ApiOperation({ summary: 'Get upcoming confirmations operation' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async getUpcomingConfirmations(
    @Request() req: any,
    @Query('days') days: string,
  ) {
    return {
      success: true,
      data: await this.dashboardService.getUpcomingConfirmations(
        req.user.tenantId,
        days ? +days : 30,
      ),
    };
  }
 
  @Get('recent-activity')
  @RequirePermission('hr.employee', 'read')
  @ApiOperation({ summary: 'Get recent activity operation' })
  @ApiResponse({ status: 200, description: 'Operation successful' })
  async getRecentActivity(@Request() req: any) {
    return {
      success: true,
      data: await this.dashboardService.getRecentActivity(req.user.tenantId),
    };
  }
}