diff --git a/src/modules/archival/archival.module.ts b/src/modules/archival/archival.module.ts index 926cf3f..6c2dd28 100644 --- a/src/modules/archival/archival.module.ts +++ b/src/modules/archival/archival.module.ts @@ -5,6 +5,11 @@ import { ExpensesModule } from "../expenses/expenses.module"; import { ShiftsModule } from "../shifts/shifts.module"; import { LeaveRequestsModule } from "../leave-requests/leave-requests.module"; import { ArchivalService } from "./services/archival.service"; +import { EmployeesArchiveController } from "./controllers/employees-archive.controller"; +import { ExpensesArchiveController } from "./controllers/expenses-archive.controller"; +import { LeaveRequestsArchiveController } from "./controllers/leave-requests-archive.controller"; +import { ShiftsArchiveController } from "./controllers/shifts-archive.controller"; +import { TimesheetsArchiveController } from "./controllers/timesheets-archive.controller"; @Module({ imports: [ @@ -15,6 +20,13 @@ import { ArchivalService } from "./services/archival.service"; LeaveRequestsModule, ], providers: [ArchivalService], + controllers: [ + EmployeesArchiveController, + ExpensesArchiveController, + LeaveRequestsArchiveController, + ShiftsArchiveController, + TimesheetsArchiveController, + ] }) export class ArchivalModule {} \ No newline at end of file diff --git a/src/modules/archival/controllers/employees-archive.controller.ts b/src/modules/archival/controllers/employees-archive.controller.ts new file mode 100644 index 0000000..07ec791 --- /dev/null +++ b/src/modules/archival/controllers/employees-archive.controller.ts @@ -0,0 +1,34 @@ +import { Controller, Get, NotFoundException, Param, ParseIntPipe, UseGuards } from "@nestjs/common"; +import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger"; +import { RolesAllowed } from "src/common/decorators/roles.decorators"; +import { EmployeesArchive, Roles as RoleEnum } from '@prisma/client'; +import { JwtAuthGuard } from "src/modules/authentication/guards/jwt-auth.guard"; +import { EmployeesService } from "src/modules/employees/services/employees.service"; + +@ApiTags('Employee Archives') +@UseGuards(JwtAuthGuard) +@Controller('archives/employees') +export class EmployeesArchiveController { + constructor(private readonly employeesService: EmployeesService) {} + + @Get() + @RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR) + @ApiOperation({ summary: 'List of archived employees'}) + @ApiResponse({ status: 200, description: 'List of archived employees', isArray: true }) + async findAllArchived(): Promise { + return this.employeesService.findAllArchived(); + } + + @Get() + @RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR,RoleEnum.SUPERVISOR) + @ApiOperation({ summary: 'Fetch employee in archives with its Id'}) + @ApiResponse({ status: 200, description: 'Archived employee found'}) + async findOneArchived(@Param('id', ParseIntPipe) id: number ): Promise { + try{ + return await this.employeesService.findOneArchived(id); + }catch { + throw new NotFoundException(`Archived employee #${id} not found`); + } + } + +} \ No newline at end of file diff --git a/src/modules/archival/controllers/expenses-archive.controller.ts b/src/modules/archival/controllers/expenses-archive.controller.ts new file mode 100644 index 0000000..01b544a --- /dev/null +++ b/src/modules/archival/controllers/expenses-archive.controller.ts @@ -0,0 +1,33 @@ +import { UseGuards, Controller, Get, Param, ParseIntPipe, NotFoundException } from "@nestjs/common"; +import { ApiTags, ApiOperation, ApiResponse } from "@nestjs/swagger"; +import { ExpensesArchive,Roles as RoleEnum } from "@prisma/client"; +import { RolesAllowed } from "src/common/decorators/roles.decorators"; +import { JwtAuthGuard } from "src/modules/authentication/guards/jwt-auth.guard"; +import { ExpensesService } from "src/modules/expenses/services/expenses.service"; + +@ApiTags('Expense Archives') +@UseGuards(JwtAuthGuard) +@Controller('archives/expenses') +export class ExpensesArchiveController { + constructor(private readonly expensesService: ExpensesService) {} + + @Get() + @RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR) + @ApiOperation({ summary: 'List of archived expenses'}) + @ApiResponse({ status: 200, description: 'List of archived expenses', isArray: true }) + async findAllArchived(): Promise { + return this.expensesService.findAllArchived(); + } + + @Get() + @RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR) + @ApiOperation({ summary: 'Fetch expense in archives with its Id'}) + @ApiResponse({ status: 200, description: 'Archived expense found'}) + async findOneArchived(@Param('id', ParseIntPipe) id: number ): Promise { + try{ + return await this.expensesService.findOneArchived(id); + }catch { + throw new NotFoundException(`Archived expense #${id} not found`); + } + } +} \ No newline at end of file diff --git a/src/modules/archival/controllers/leave-requests-archive.controller.ts b/src/modules/archival/controllers/leave-requests-archive.controller.ts new file mode 100644 index 0000000..c7fe0ca --- /dev/null +++ b/src/modules/archival/controllers/leave-requests-archive.controller.ts @@ -0,0 +1,33 @@ +import { Get, Param, ParseIntPipe, NotFoundException, Controller, UseGuards } from "@nestjs/common"; +import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger"; +import { LeaveRequestsArchive, Roles as RoleEnum } from "@prisma/client"; +import { RolesAllowed } from "src/common/decorators/roles.decorators"; +import { JwtAuthGuard } from "src/modules/authentication/guards/jwt-auth.guard"; +import { LeaveRequestsService } from "src/modules/leave-requests/services/leave-request.service"; + +@ApiTags('LeaveRequests Archives') +@UseGuards(JwtAuthGuard) +@Controller('archives/leaveRequests') +export class LeaveRequestsArchiveController { + constructor(private readonly leaveRequestsService: LeaveRequestsService) {} + + @Get() + @RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR) + @ApiOperation({ summary: 'List of archived leaveRequests'}) + @ApiResponse({ status: 200, description: 'List of archived leaveRequests', isArray: true }) + async findAllArchived(): Promise { + return this.leaveRequestsService.findAllArchived(); + } + + @Get() + @RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR) + @ApiOperation({ summary: 'Fetch leaveRequest in archives with its Id'}) + @ApiResponse({ status: 200, description: 'Archived leaveRequest found'}) + async findOneArchived(@Param('id', ParseIntPipe) id: number ): Promise { + try{ + return await this.leaveRequestsService.findOneArchived(id); + }catch { + throw new NotFoundException(`Archived leaveRequest #${id} not found`); + } + } +} \ No newline at end of file diff --git a/src/modules/archival/controllers/shifts-archive.controller.ts b/src/modules/archival/controllers/shifts-archive.controller.ts new file mode 100644 index 0000000..d8fc568 --- /dev/null +++ b/src/modules/archival/controllers/shifts-archive.controller.ts @@ -0,0 +1,33 @@ +import { Get, Param, ParseIntPipe, NotFoundException, Controller, UseGuards } from "@nestjs/common"; +import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger"; +import { ShiftsArchive, Roles as RoleEnum } from "@prisma/client"; +import { RolesAllowed } from "src/common/decorators/roles.decorators"; +import { JwtAuthGuard } from "src/modules/authentication/guards/jwt-auth.guard"; +import { ShiftsService } from "src/modules/shifts/services/shifts.service"; + +@ApiTags('Shift Archives') +@UseGuards(JwtAuthGuard) +@Controller('archives/shifts') +export class ShiftsArchiveController { + constructor(private readonly shiftsService:ShiftsService) {} + + @Get() + @RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR) + @ApiOperation({ summary: 'List of archived shifts'}) + @ApiResponse({ status: 200, description: 'List of archived shifts', isArray: true }) + async findAllArchived(): Promise { + return this.shiftsService.findAllArchived(); + } + + @Get() + @RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR,RoleEnum.SUPERVISOR) + @ApiOperation({ summary: 'Fetch shift in archives with its Id'}) + @ApiResponse({ status: 200, description: 'Archived shift found'}) + async findOneArchived(@Param('id', ParseIntPipe) id: number ): Promise { + try{ + return await this.shiftsService.findOneArchived(id); + }catch { + throw new NotFoundException(`Archived shift #${id} not found`); + } + } +} \ No newline at end of file diff --git a/src/modules/archival/controllers/timesheets-archive.controller.ts b/src/modules/archival/controllers/timesheets-archive.controller.ts new file mode 100644 index 0000000..0fcb8e5 --- /dev/null +++ b/src/modules/archival/controllers/timesheets-archive.controller.ts @@ -0,0 +1,34 @@ +import { Controller, Get, NotFoundException, Param, ParseIntPipe, UseGuards } from "@nestjs/common"; +import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger"; +import { RolesAllowed } from "src/common/decorators/roles.decorators"; +import { TimesheetsArchive, Roles as RoleEnum } from '@prisma/client'; +import { TimesheetsService } from "src/modules/timesheets/services/timesheets.service"; +import { JwtAuthGuard } from "src/modules/authentication/guards/jwt-auth.guard"; + +@ApiTags('Timesheet Archives') +@UseGuards(JwtAuthGuard) +@Controller('archives/timesheets') +export class TimesheetsArchiveController { + constructor(private readonly timesheetsService: TimesheetsService) {} + + @Get() + @RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR) + @ApiOperation({ summary: 'List of archived timesheets'}) + @ApiResponse({ status: 200, description: 'List of archived timesheets', isArray: true }) + async findAllArchived(): Promise { + return this.timesheetsService.findAllArchived(); + } + + @Get() + @RolesAllowed(RoleEnum.ADMIN, RoleEnum.HR, RoleEnum.SUPERVISOR) + @ApiOperation({ summary: 'Fetch timesheet in archives with its Id'}) + @ApiResponse({ status: 200, description: 'Archived timesheet found'}) + async findOneArchived(@Param('id', ParseIntPipe) id: number ): Promise { + try{ + return await this.timesheetsService.findOneArchived(id); + }catch { + throw new NotFoundException(`Archived timesheet #${id} not found`); + } + } + +} \ No newline at end of file diff --git a/src/modules/employees/services/employees.service.ts b/src/modules/employees/services/employees.service.ts index 9a16821..183c1b0 100644 --- a/src/modules/employees/services/employees.service.ts +++ b/src/modules/employees/services/employees.service.ts @@ -2,7 +2,7 @@ import { Injectable, NotFoundException } from '@nestjs/common'; import { PrismaService } from 'src/prisma/prisma.service'; import { CreateEmployeeDto } from '../dtos/create-employee.dto'; import { UpdateEmployeeDto } from '../dtos/update-employee.dto'; -import { Employees, Users } from '@prisma/client'; +import { Employees, EmployeesArchive, Users } from '@prisma/client'; @Injectable() export class EmployeesService { @@ -109,7 +109,8 @@ async update( } - //archivation function + //archivation functions ****************************************************** + async patchEmployee(id: number, dto: UpdateEmployeeDto): Promise { //fetching existing employee const existing = await this.prisma.employees.findUnique({ @@ -189,4 +190,15 @@ async update( return restored; }); } + + //fetches all archived employees + async findAllArchived(): Promise { + return this.prisma.employeesArchive.findMany(); + } + + //fetches an archived employee + async findOneArchived(id: number): Promise { + return this.prisma.employeesArchive.findUniqueOrThrow({ where: { id } }); + } + } diff --git a/src/modules/expenses/services/expenses.service.ts b/src/modules/expenses/services/expenses.service.ts index 2be085e..9f8c0e2 100644 --- a/src/modules/expenses/services/expenses.service.ts +++ b/src/modules/expenses/services/expenses.service.ts @@ -1,7 +1,7 @@ import { Injectable, NotFoundException } from "@nestjs/common"; import { PrismaService } from "src/prisma/prisma.service"; import { CreateExpenseDto } from "../dtos/create-expense"; -import { Expenses } from "@prisma/client"; +import { Expenses, ExpensesArchive } from "@prisma/client"; import { UpdateExpenseDto } from "../dtos/update-expense"; @Injectable() @@ -88,7 +88,8 @@ export class ExpensesService { } - //archivation function + //archivation functions ****************************************************** + async archiveOld(): Promise { //fetches archived timesheet's Ids const archivedTimesheets = await this.prisma.timesheetsArchive.findMany({ @@ -132,4 +133,14 @@ export class ExpensesService { }) } + + //fetches all archived timesheets + async findAllArchived(): Promise { + return this.prisma.expensesArchive.findMany(); + } + + //fetches an archived timesheet + async findOneArchived(id: number): Promise { + return this.prisma.expensesArchive.findUniqueOrThrow({ where: { id } }); + } } \ No newline at end of file diff --git a/src/modules/leave-requests/services/leave-request.service.ts b/src/modules/leave-requests/services/leave-request.service.ts index 2d2bd84..e8315a7 100644 --- a/src/modules/leave-requests/services/leave-request.service.ts +++ b/src/modules/leave-requests/services/leave-request.service.ts @@ -1,7 +1,7 @@ import { Injectable, NotFoundException } from "@nestjs/common"; import { PrismaService } from "src/prisma/prisma.service"; import { CreateLeaveRequestsDto } from "../dtos/create-leave-requests.dto"; -import { LeaveRequests } from "@prisma/client"; +import { LeaveRequests, LeaveRequestsArchive } from "@prisma/client"; import { UpdateLeaveRequestsDto } from "../dtos/update-leave-requests.dto"; @Injectable() @@ -107,7 +107,8 @@ export class LeaveRequestsService { }); } - //archivation function + //archivation functions ****************************************************** + async archiveExpired(): Promise { const now = new Date(); @@ -136,6 +137,15 @@ export class LeaveRequestsService { where: { id: { in: expired.map(request => request.id ) } }, }); }); + } + //fetches all archived employees + async findAllArchived(): Promise { + return this.prisma.leaveRequestsArchive.findMany(); + } + + //fetches an archived employee + async findOneArchived(id: number): Promise { + return this.prisma.leaveRequestsArchive.findUniqueOrThrow({ where: { id } }); } } \ No newline at end of file diff --git a/src/modules/shifts/services/shifts.service.ts b/src/modules/shifts/services/shifts.service.ts index 161e05c..2844bcb 100644 --- a/src/modules/shifts/services/shifts.service.ts +++ b/src/modules/shifts/services/shifts.service.ts @@ -1,7 +1,7 @@ import { Injectable, NotFoundException } from "@nestjs/common"; import { PrismaService } from "src/prisma/prisma.service"; import { CreateShiftDto } from "../dtos/create-shifts.dto"; -import { Shifts } from "@prisma/client"; +import { Shifts, ShiftsArchive } from "@prisma/client"; import { UpdateShiftsDto } from "../dtos/update-shifts.dto"; @Injectable() @@ -87,7 +87,8 @@ export class ShiftsService { return this.prisma.shifts.delete({ where: { id } }); } - //archivation function + //archivation functions ****************************************************** + async archiveOld(): Promise { //fetches archived timesheet's Ids const archivedTimesheets = await this.prisma.timesheetsArchive.findMany({ @@ -130,4 +131,14 @@ export class ShiftsService { }) } + //fetches all archived timesheets + async findAllArchived(): Promise { + return this.prisma.shiftsArchive.findMany(); + } + + //fetches an archived timesheet + async findOneArchived(id: number): Promise { + return this.prisma.shiftsArchive.findUniqueOrThrow({ where: { id } }); + } + } \ No newline at end of file diff --git a/src/modules/timesheets/services/timesheets.service.ts b/src/modules/timesheets/services/timesheets.service.ts index 84db6e4..c8fcff3 100644 --- a/src/modules/timesheets/services/timesheets.service.ts +++ b/src/modules/timesheets/services/timesheets.service.ts @@ -1,7 +1,7 @@ import { Injectable, NotFoundException } from '@nestjs/common'; import { PrismaService } from 'src/prisma/prisma.service'; import { CreateTimesheetDto } from '../dtos/create-timesheet.dto'; -import { Timesheets } from '@prisma/client'; +import { Timesheets, TimesheetsArchive } from '@prisma/client'; import { UpdateTimesheetDto } from '../dtos/update-timesheet.dto'; @Injectable() @@ -75,7 +75,8 @@ export class TimesheetsService { } - //Archivation function +//archivation functions ****************************************************** + async archiveOld(): Promise { //calcul du cutoff pour archivation const cutoff = new Date(); @@ -115,4 +116,14 @@ export class TimesheetsService { }); }); } + + //fetches all archived timesheets + async findAllArchived(): Promise { + return this.prisma.timesheetsArchive.findMany(); + } + + //fetches an archived timesheet + async findOneArchived(id: number): Promise { + return this.prisma.timesheetsArchive.findUniqueOrThrow({ where: { id } }); + } }