diff --git a/src/identity-and-account/contract/contract.controller.ts b/src/identity-and-account/contract/contract.controller.ts index 8c9d02f..00892bf 100644 --- a/src/identity-and-account/contract/contract.controller.ts +++ b/src/identity-and-account/contract/contract.controller.ts @@ -1,11 +1,16 @@ -import { Controller } from "@nestjs/common"; +import { Controller, Get, Param } from "@nestjs/common"; +// import { Access } from "src/common/decorators/module-access.decorators"; import { ContractService } from "src/identity-and-account/contract/services/contract.service"; -@Controller() +@Controller('contracts') export class ContractController { - constructor(private readonly getService: ContractService) {} - - + constructor(private readonly getService: ContractService) { } + @Get('details/:email') + async getContractDetailsByEmail( + @Param('email') email: string + ) { + return await this.getService.getContractDetailsByEmail(email); + } } \ No newline at end of file diff --git a/src/identity-and-account/contract/contract.dto.ts b/src/identity-and-account/contract/contract.dto.ts index 75c1d3b..301154f 100644 --- a/src/identity-and-account/contract/contract.dto.ts +++ b/src/identity-and-account/contract/contract.dto.ts @@ -1,10 +1,11 @@ import { Type } from "class-transformer"; -import { IsInt, IsString } from "class-validator"; +import { IsArray, IsInt, IsString } from "class-validator"; import { ApplicableOvertime } from "prisma/postgres/generated/prisma/client/postgres/enums"; export class Contract { + @IsInt() id: number; @IsInt() daily_expected_hours: number; - @IsString() applicable_overtime: ApplicableOvertime; + @IsString() @IsArray() applicable_overtime: ApplicableOvertime[]; @Type(() => Number) phone_allocation: number; @Type(() => Number) on_call_allocation: number; @Type(() => Number) weekend_on_call_allocation: number; diff --git a/src/identity-and-account/contract/services/contract.service.ts b/src/identity-and-account/contract/services/contract.service.ts index 8bf0bcd..cf7ee79 100644 --- a/src/identity-and-account/contract/services/contract.service.ts +++ b/src/identity-and-account/contract/services/contract.service.ts @@ -1,6 +1,43 @@ import { Injectable } from "@nestjs/common"; +import { PrismaPostgresService } from "prisma/postgres/prisma-postgres.service"; +import { Result } from "src/common/errors/result-error.factory"; +import { EmailToIdResolver } from "src/common/mappers/email-id.mapper"; +import { Contract } from "src/identity-and-account/contract/contract.dto"; @Injectable() export class ContractService { - + + constructor( + private readonly prisma: PrismaPostgresService, + private readonly emailresolver: EmailToIdResolver, + ) { } + + getContractDetailsByEmail = async (email: string): Promise> => { + try { + const employee = await this.emailresolver.findIdByEmail(email); + if (!employee.success) return { success: false, error: 'EMPLOYEE_NOT_FOUND' }; + + const contract = await this.prisma.contracts.findUnique({ + where: { employee_id: employee.data }, + omit: { employee_id: true }, + }); + if (!contract) return { success: false, error: 'CONTRACT_NOT_FOUND' }; + + const contractDetails: Contract = { + id: contract.id, + daily_expected_hours: contract.daily_expected_hours, + applicable_overtime: contract.applicable_overtime, + on_call_allocation: Number(contract.on_call_allocation), + weekend_on_call_allocation: Number(contract.weekend_on_call_allocation), + phone_allocation: Number(contract.phone_allocation), + }; + + return { success: true, data: contractDetails } + + } catch (error) { + console.error(error); + return { success: false, error: 'CONTRACT_NOT_FOUND' }; + } + + } } \ No newline at end of file diff --git a/src/identity-and-account/http-rest-cli-test/contract-details.test.http b/src/identity-and-account/http-rest-cli-test/contract-details.test.http new file mode 100644 index 0000000..2f7e9c3 --- /dev/null +++ b/src/identity-and-account/http-rest-cli-test/contract-details.test.http @@ -0,0 +1 @@ +GET http://localhost:3000/contracts/details/matthieuh@targointernet.com \ No newline at end of file diff --git a/src/identity-and-account/identity-and-account.module.ts b/src/identity-and-account/identity-and-account.module.ts index 6c238b7..a2e6a73 100644 --- a/src/identity-and-account/identity-and-account.module.ts +++ b/src/identity-and-account/identity-and-account.module.ts @@ -17,6 +17,8 @@ import { EmployeesCreateService } from "src/identity-and-account/employees/servi import { EmployeesUpdateService } from "src/identity-and-account/employees/services/employees-update.service"; import { HomePageController } from "src/identity-and-account/help/help-page.controller"; import { HomePageService } from "src/identity-and-account/help/help-page.service"; +import { ContractController } from "src/identity-and-account/contract/contract.controller"; +import { ContractService } from "src/identity-and-account/contract/services/contract.service"; @Module({ imports: [ @@ -28,6 +30,7 @@ import { HomePageService } from "src/identity-and-account/help/help-page.service ], controllers: [ EmployeesController, + ContractController, PreferencesController, ModuleAccessController, HomePageController, @@ -42,6 +45,7 @@ import { HomePageService } from "src/identity-and-account/help/help-page.service AccessUpdateService, AccessGetService, HomePageService, + ContractService, ], }) export class IdentityAndAccountModule { };