Skip to content

Commit

Permalink
Add sports pass fee
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarchois committed Mar 14, 2024
1 parent 1ac13df commit 0ff0e4c
Show file tree
Hide file tree
Showing 21 changed files with 94 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class addSportsPassFeeToUserAdministrative1710429580134 implements MigrationInterface {
name = 'addSportsPassFeeToUserAdministrative1710429580134'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "user_administrative" ADD "sportsPassFee" integer DEFAULT '0'`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "user_administrative" DROP COLUMN "sportsPassFee"`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('GetUserElementsQueryHandler', () => {
const earnings = 2000000;
const rawTransportFee = 7500;
const rawSustainableMobilityFee = 7000;
const rawSportsPassFee = 3000;
const userAdministrative = mock(UserAdministrative);
when(userAdministrative.getContract()).thenReturn(ContractType.CDI);
when(userAdministrative.isExecutivePosition()).thenReturn(true);
Expand All @@ -70,6 +71,9 @@ describe('GetUserElementsQueryHandler', () => {
when(userAdministrative.getSustainableMobilityFee()).thenReturn(
rawSustainableMobilityFee
);
when(userAdministrative.getSportsPassFee()).thenReturn(
rawSportsPassFee
);
when(userAdministrative.haveHealthInsurance()).thenReturn(true);

when(user.getId()).thenReturn('3b8a1954-2ade-44a2-a03c-338985c327ef');
Expand Down Expand Up @@ -146,6 +150,7 @@ describe('GetUserElementsQueryHandler', () => {
const yearlyEarning = earnings * 0.01;
const transportFee = rawTransportFee * 0.01;
const sustainableMobilityFee = rawSustainableMobilityFee * 0.01;
const sportsPassFee = rawSportsPassFee * 0.01;

expect(await queryHandler.execute(query)).toMatchObject([
new UserElementsView(
Expand All @@ -159,6 +164,7 @@ describe('GetUserElementsQueryHandler', () => {
WorkingTimeType.FULL_TIME,
transportFee,
sustainableMobilityFee,
sportsPassFee,
5,
true,
new UserLeavesView(0, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class GetUsersElementsQueryHandler {
user.getUserAdministrative().getWorkingTime(),
user.getUserAdministrative().getTransportFee() * 0.01,
user.getUserAdministrative().getSustainableMobilityFee() * 0.01,
user.getUserAdministrative().getSportsPassFee() * 0.01,
mealTicketsByUser[user.getId()],
user.getUserAdministrative().haveHealthInsurance(),
this.createUserLeavesView(userLeaves.paid, date),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class UserElementsView {
public readonly workingTime: string,
public readonly transportFee: number,
public readonly sustainableMobilityFee: number,
public readonly sportsPassFee: number,
public readonly mealTickets: number,
public readonly healthInsurance: boolean,
public readonly paidLeaves: UserLeavesView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface IUserAdministrativeCommand {
leavingDate: string;
transportFee: number;
sustainableMobilityFee: number;
sportsPassFee: number;
}

export class CreateUserCommand implements ICommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export class CreateUserCommandHandler {
joiningDate,
leavingDate,
transportFee,
sustainableMobilityFee
sustainableMobilityFee,
sportsPassFee
} = userAdministrative;

return await this.userAdministrativeRepository.save(
Expand All @@ -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,
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ describe('UpdateProfileCommandHandler', () => {
'2018-01-01',
null,
75.2,
70
70,
30
);

beforeEach(() => {
Expand Down Expand Up @@ -74,7 +75,8 @@ describe('UpdateProfileCommandHandler', () => {
'2017-08-01',
'2018-12-31',
null,
7000
7000,
3000,
);
const user = new User(
'John',
Expand Down Expand Up @@ -105,7 +107,8 @@ describe('UpdateProfileCommandHandler', () => {
'2018-01-01',
null,
7520,
7000
7000,
3000,
);
verify(
userRepository.save(
Expand Down Expand Up @@ -137,7 +140,8 @@ describe('UpdateProfileCommandHandler', () => {
'2017-08-01',
'2018-12-31',
null,
7000
7000,
3000
);
const user = new User(
'John',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export class UpdateUserCommandHandler {
joiningDate,
leavingDate,
transportFee,
sustainableMobilityFee
sustainableMobilityFee,
sportsPassFee
} = command;

const user = await this.userRepository.findOneById(id);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {}
}
11 changes: 8 additions & 3 deletions src/Domain/HumanResource/User/UserAdministrative.entity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ describe('UserAdministrative.entity', () => {
'2020-01-01',
'2021-01-01',
7550,
7000
7000,
3000,
);

expect(admin.getId()).toBe(undefined);
Expand All @@ -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', () => {
Expand All @@ -40,7 +42,8 @@ describe('UserAdministrative.entity', () => {
'2020-01-01',
null,
7550,
7000
7000,
3000,
);

admin.update(
Expand All @@ -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);
Expand All @@ -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);
});
});
15 changes: 13 additions & 2 deletions src/Domain/HumanResource/User/UserAdministrative.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -72,6 +76,7 @@ export class UserAdministrative {
this.leavingDate = leavingDate;
this.transportFee = transportFee;
this.sustainableMobilityFee = sustainableMobilityFee;
this.sportsPassFee = sportsPassFee;
}

public getId(): string {
Expand All @@ -98,6 +103,10 @@ export class UserAdministrative {
return this.sustainableMobilityFee;
}

public getSportsPassFee(): number {
return this.sportsPassFee;
}

public haveHealthInsurance(): boolean {
return this.healthInsurance;
}
Expand All @@ -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;
Expand All @@ -134,5 +144,6 @@ export class UserAdministrative {
this.leavingDate = leavingDate;
this.transportFee = transportFee;
this.sustainableMobilityFee = sustainableMobilityFee;
this.sportsPassFee = sportsPassFee;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class PayrollElementsTableFactory {
'payroll-elements-workingTime',
'payroll-elements-transportFee',
'payroll-elements-sustainableMobilityFee',
'payroll-elements-sportsPassFee',
'payroll-elements-mealTickets',
'payroll-elements-healthInsurance',
'payroll-elements-paidLeaves',
Expand Down Expand Up @@ -46,6 +47,9 @@ export class PayrollElementsTableFactory {
.trans('common-money', {
value: item.sustainableMobilityFee
})
.trans('common-money', {
value: item.sportsPassFee
})
.value(item.mealTickets)
.trans(item.healthInsurance ? 'common-yes' : 'common-no')
.template('pages/payroll_elements/_leaves.njk', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { IdDTO } from 'src/Infrastructure/Common/DTO/IdDTO';
import { UserAdministrativeDTO } from '../DTO/UserAdministrativeDTO';
import { IsAuthenticatedGuard } from '../Security/IsAuthenticatedGuard';
import { WithName } from 'src/Infrastructure/Common/ExtendedRouting/WithName';
import { GetUserByIdQuery } from 'src/Application/HumanResource/User/Query/GetUserByIdQuery';
import { RouteNameResolver } from 'src/Infrastructure/Common/ExtendedRouting/RouteNameResolver';
import { UserRole } from 'src/Domain/HumanResource/User/User.entity';
import {
Expand Down Expand Up @@ -68,7 +67,8 @@ export class EditUserController {
joiningDate,
leavingDate,
transportFee,
sustainableMobilityFee
sustainableMobilityFee,
sportsPassFee
} = userAdministrativeDto;

try {
Expand All @@ -84,7 +84,8 @@ export class EditUserController {
joiningDate,
leavingDate ? leavingDate : null,
transportFee,
sustainableMobilityFee
sustainableMobilityFee,
sportsPassFee
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export class UserRepository implements IUserRepository {
'userAdministrative.executivePosition',
'userAdministrative.contract',
'userAdministrative.workingTime',
'userAdministrative.sustainableMobilityFee'
'userAdministrative.sustainableMobilityFee',
'userAdministrative.sportsPassFee'
]);
query.innerJoin('user.userAdministrative', 'userAdministrative');
query.andWhere('user.role <> :role', { role: UserRole.ACCOUNTANT });
Expand Down
Loading

0 comments on commit 0ff0e4c

Please sign in to comment.