From 212dbf4ceee8d7502be6b76eedd1147b3ed8a5d9 Mon Sep 17 00:00:00 2001 From: mmarchois Date: Thu, 14 Mar 2024 16:10:58 +0100 Subject: [PATCH] Add sports pass fee --- .../User/Command/CreateUserCommand.ts | 1 + .../User/Command/CreateUserCommandHandler.ts | 6 ++++-- .../User/Command/UpdateUserCommand.ts | 3 ++- .../User/Command/UpdateUserCommandHandler.spec.ts | 12 ++++++++---- .../User/Command/UpdateUserCommandHandler.ts | 6 ++++-- .../GetUserAdministrativeByIdQueryHandler.ts | 3 ++- .../User/View/UserAdministrativeView.ts | 3 ++- .../User/UserAdministrative.entity.spec.ts | 11 ++++++++--- .../User/UserAdministrative.entity.ts | 15 +++++++++++++-- .../User/DTO/UserAdministrativeDTO.spec.ts | 1 + .../User/DTO/UserAdministrativeDTO.ts | 5 +++++ .../Repository/UserAdministrativeRepository.ts | 3 ++- 12 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/Application/HumanResource/User/Command/CreateUserCommand.ts b/src/Application/HumanResource/User/Command/CreateUserCommand.ts index 5b92064c..4ba7a5bd 100644 --- a/src/Application/HumanResource/User/Command/CreateUserCommand.ts +++ b/src/Application/HumanResource/User/Command/CreateUserCommand.ts @@ -15,6 +15,7 @@ export interface IUserAdministrativeCommand { leavingDate: string; transportFee: number; sustainableMobilityFee: number; + sportsPassFee: number; } export class CreateUserCommand implements ICommand { diff --git a/src/Application/HumanResource/User/Command/CreateUserCommandHandler.ts b/src/Application/HumanResource/User/Command/CreateUserCommandHandler.ts index ec37978b..21377dbb 100644 --- a/src/Application/HumanResource/User/Command/CreateUserCommandHandler.ts +++ b/src/Application/HumanResource/User/Command/CreateUserCommandHandler.ts @@ -76,7 +76,8 @@ export class CreateUserCommandHandler { joiningDate, leavingDate, transportFee, - sustainableMobilityFee + sustainableMobilityFee, + sportsPassFee } = userAdministrative; return await this.userAdministrativeRepository.save( @@ -89,7 +90,8 @@ export class CreateUserCommandHandler { joiningDate, leavingDate ? leavingDate : null, transportFee ? Math.round(transportFee * 100) : 0, - sustainableMobilityFee ? Math.round(sustainableMobilityFee * 100) : 0 + sustainableMobilityFee ? Math.round(sustainableMobilityFee * 100) : 0, + sportsPassFee ? Math.round(sportsPassFee * 100) : 0, ) ); } diff --git a/src/Application/HumanResource/User/Command/UpdateUserCommand.ts b/src/Application/HumanResource/User/Command/UpdateUserCommand.ts index 04564022..d46ad4d2 100644 --- a/src/Application/HumanResource/User/Command/UpdateUserCommand.ts +++ b/src/Application/HumanResource/User/Command/UpdateUserCommand.ts @@ -17,6 +17,7 @@ export class UpdateUserCommand implements ICommand { public readonly joiningDate: string, public readonly leavingDate: string, public readonly transportFee: number, - public readonly sustainableMobilityFee: number + public readonly sustainableMobilityFee: number, + public readonly sportsPassFee: number ) {} } diff --git a/src/Application/HumanResource/User/Command/UpdateUserCommandHandler.spec.ts b/src/Application/HumanResource/User/Command/UpdateUserCommandHandler.spec.ts index 16dc4e7e..fced8ab3 100644 --- a/src/Application/HumanResource/User/Command/UpdateUserCommandHandler.spec.ts +++ b/src/Application/HumanResource/User/Command/UpdateUserCommandHandler.spec.ts @@ -31,7 +31,8 @@ describe('UpdateProfileCommandHandler', () => { '2018-01-01', null, 75.2, - 70 + 70, + 30 ); beforeEach(() => { @@ -74,7 +75,8 @@ describe('UpdateProfileCommandHandler', () => { '2017-08-01', '2018-12-31', null, - 7000 + 7000, + 3000, ); const user = new User( 'John', @@ -105,7 +107,8 @@ describe('UpdateProfileCommandHandler', () => { '2018-01-01', null, 7520, - 7000 + 7000, + 3000, ); verify( userRepository.save( @@ -137,7 +140,8 @@ describe('UpdateProfileCommandHandler', () => { '2017-08-01', '2018-12-31', null, - 7000 + 7000, + 3000 ); const user = new User( 'John', diff --git a/src/Application/HumanResource/User/Command/UpdateUserCommandHandler.ts b/src/Application/HumanResource/User/Command/UpdateUserCommandHandler.ts index 7de3b084..1b843439 100644 --- a/src/Application/HumanResource/User/Command/UpdateUserCommandHandler.ts +++ b/src/Application/HumanResource/User/Command/UpdateUserCommandHandler.ts @@ -27,7 +27,8 @@ export class UpdateUserCommandHandler { joiningDate, leavingDate, transportFee, - sustainableMobilityFee + sustainableMobilityFee, + sportsPassFee } = command; const user = await this.userRepository.findOneById(id); @@ -53,7 +54,8 @@ export class UpdateUserCommandHandler { joiningDate, leavingDate ? leavingDate : null, transportFee ? Math.round(transportFee * 100) : 0, - sustainableMobilityFee ? Math.round(sustainableMobilityFee * 100) : 0 + sustainableMobilityFee ? Math.round(sustainableMobilityFee * 100) : 0, + sportsPassFee ? Math.round(sportsPassFee * 100) : 0 ); await this.userRepository.save(user); diff --git a/src/Application/HumanResource/User/Query/GetUserAdministrativeByIdQueryHandler.ts b/src/Application/HumanResource/User/Query/GetUserAdministrativeByIdQueryHandler.ts index 5d1e5b54..623c5472 100644 --- a/src/Application/HumanResource/User/Query/GetUserAdministrativeByIdQueryHandler.ts +++ b/src/Application/HumanResource/User/Query/GetUserAdministrativeByIdQueryHandler.ts @@ -37,7 +37,8 @@ export class GetUserAdministrativeByIdQueryHandler { userAdministrative.getJoiningDate(), userAdministrative.getLeavingDate(), userAdministrative.getTransportFee() * 0.01, - userAdministrative.getSustainableMobilityFee() * 0.01 + userAdministrative.getSustainableMobilityFee() * 0.01, + userAdministrative.getSportsPassFee() * 0.01, ); } diff --git a/src/Application/HumanResource/User/View/UserAdministrativeView.ts b/src/Application/HumanResource/User/View/UserAdministrativeView.ts index 18cede88..ad4ef8d7 100644 --- a/src/Application/HumanResource/User/View/UserAdministrativeView.ts +++ b/src/Application/HumanResource/User/View/UserAdministrativeView.ts @@ -13,6 +13,7 @@ export class UserAdministrativeView { public readonly joiningDate: string, public readonly leavingDate: string, public readonly transportFee: number, - public readonly sustainableMobilityFee: number + public readonly sustainableMobilityFee: number, + public readonly sportsPassFee: number ) {} } diff --git a/src/Domain/HumanResource/User/UserAdministrative.entity.spec.ts b/src/Domain/HumanResource/User/UserAdministrative.entity.spec.ts index cc874df6..ce5a667c 100644 --- a/src/Domain/HumanResource/User/UserAdministrative.entity.spec.ts +++ b/src/Domain/HumanResource/User/UserAdministrative.entity.spec.ts @@ -15,7 +15,8 @@ describe('UserAdministrative.entity', () => { '2020-01-01', '2021-01-01', 7550, - 7000 + 7000, + 3000, ); expect(admin.getId()).toBe(undefined); @@ -28,6 +29,7 @@ describe('UserAdministrative.entity', () => { expect(admin.isExecutivePosition()).toBe(true); expect(admin.haveHealthInsurance()).toBe(true); expect(admin.getSustainableMobilityFee()).toBe(7000); + expect(admin.getSportsPassFee()).toBe(3000); }); it('testUpdate', () => { @@ -40,7 +42,8 @@ describe('UserAdministrative.entity', () => { '2020-01-01', null, 7550, - 7000 + 7000, + 3000, ); admin.update( @@ -52,7 +55,8 @@ describe('UserAdministrative.entity', () => { '2020-01-02', '2021-01-02', null, - 3000 + 3000, + 2000, ); expect(admin.getAnnualEarnings()).toBe(3000000); expect(admin.getContract()).toBe(ContractType.APPRENTICESHIP); @@ -63,5 +67,6 @@ describe('UserAdministrative.entity', () => { expect(admin.getLeavingDate()).toBe('2021-01-02'); expect(admin.getTransportFee()).toBe(null); expect(admin.getSustainableMobilityFee()).toBe(3000); + expect(admin.getSportsPassFee()).toBe(2000); }); }); diff --git a/src/Domain/HumanResource/User/UserAdministrative.entity.ts b/src/Domain/HumanResource/User/UserAdministrative.entity.ts index 80f56f21..f8adbfd9 100644 --- a/src/Domain/HumanResource/User/UserAdministrative.entity.ts +++ b/src/Domain/HumanResource/User/UserAdministrative.entity.ts @@ -34,6 +34,9 @@ export class UserAdministrative { @Column({ type: 'integer', default: 0, nullable: true }) private sustainableMobilityFee: number; + @Column({ type: 'integer', default: 0, nullable: true }) + private sportsPassFee: number; + @Column({ type: 'boolean', nullable: false }) private healthInsurance: boolean; @@ -61,7 +64,8 @@ export class UserAdministrative { joiningDate: string, leavingDate?: string, transportFee?: number, - sustainableMobilityFee?: number + sustainableMobilityFee?: number, + sportsPassFee?: number ) { this.annualEarnings = annualEarnings; this.healthInsurance = healthInsurance; @@ -72,6 +76,7 @@ export class UserAdministrative { this.leavingDate = leavingDate; this.transportFee = transportFee; this.sustainableMobilityFee = sustainableMobilityFee; + this.sportsPassFee = sportsPassFee; } public getId(): string { @@ -98,6 +103,10 @@ export class UserAdministrative { return this.sustainableMobilityFee; } + public getSportsPassFee(): number { + return this.sportsPassFee; + } + public haveHealthInsurance(): boolean { return this.healthInsurance; } @@ -123,7 +132,8 @@ export class UserAdministrative { joiningDate: string, leavingDate: string | null, transportFee: number, - sustainableMobilityFee: number + sustainableMobilityFee: number, + sportsPassFee: number ): void { this.annualEarnings = annualEarnings; this.contract = contract; @@ -134,5 +144,6 @@ export class UserAdministrative { this.leavingDate = leavingDate; this.transportFee = transportFee; this.sustainableMobilityFee = sustainableMobilityFee; + this.sportsPassFee = sportsPassFee; } } diff --git a/src/Infrastructure/HumanResource/User/DTO/UserAdministrativeDTO.spec.ts b/src/Infrastructure/HumanResource/User/DTO/UserAdministrativeDTO.spec.ts index b516dc9d..4e3f1d79 100644 --- a/src/Infrastructure/HumanResource/User/DTO/UserAdministrativeDTO.spec.ts +++ b/src/Infrastructure/HumanResource/User/DTO/UserAdministrativeDTO.spec.ts @@ -16,6 +16,7 @@ describe('UserAdministrativeDTO', () => { dto.executivePosition = true; dto.healthInsurance = true; dto.transportFee = 75.2; + dto.sportsPassFee = 30; dto.joiningDate = '2020-12-17T03:24:00'; dto.leavingDate = '2021-12-17T03:24:00'; diff --git a/src/Infrastructure/HumanResource/User/DTO/UserAdministrativeDTO.ts b/src/Infrastructure/HumanResource/User/DTO/UserAdministrativeDTO.ts index 2f50fc7c..19cc6375 100644 --- a/src/Infrastructure/HumanResource/User/DTO/UserAdministrativeDTO.ts +++ b/src/Infrastructure/HumanResource/User/DTO/UserAdministrativeDTO.ts @@ -37,6 +37,11 @@ export class UserAdministrativeDTO { @Min(0) public sustainableMobilityFee: number; + @IsOptional() + @IsNumber() + @Min(0) + public sportsPassFee: number; + @IsNotEmpty() @Transform((_, { healthInsurance }) => healthInsurance === 'true') @IsBoolean() diff --git a/src/Infrastructure/HumanResource/User/Repository/UserAdministrativeRepository.ts b/src/Infrastructure/HumanResource/User/Repository/UserAdministrativeRepository.ts index ad9baa13..8d5bd85a 100644 --- a/src/Infrastructure/HumanResource/User/Repository/UserAdministrativeRepository.ts +++ b/src/Infrastructure/HumanResource/User/Repository/UserAdministrativeRepository.ts @@ -27,7 +27,8 @@ export class UserAdministrativeRepository 'userAdministrative.executivePosition', 'userAdministrative.contract', 'userAdministrative.workingTime', - 'userAdministrative.sustainableMobilityFee' + 'userAdministrative.sustainableMobilityFee', + 'userAdministrative.sportsPassFee' ]) .innerJoin('userAdministrative.user', 'user') .where('user.id = :userId', { userId })