feat(contracts): finishing touch for the contracts model
This commit is contained in:
parent
a5bd7d54fe
commit
a6d2a3b3cd
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<Result<Contract, string>> => {
|
||||
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' };
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
GET http://localhost:3000/contracts/details/matthieuh@targointernet.com
|
||||
|
|
@ -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 { };
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user