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 3ecf653
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 24 deletions.
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,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
13 changes: 9 additions & 4 deletions src/templates/pages/users/_form.njk
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,34 @@
</div>
</div>

<div class="pc-grid pc-gap" style="--grid-cols: 3">
<div class="pc-grid pc-gap" style="--grid-cols: 4">
<div class="pc-input-group">
<label class="pc-label required" for="annualEarnings">{{ 'users-annualEarnings'|trans }}</label>
<input type="number" min="0" id="annualEarnings" name="annualEarnings" required value="{% if userAdministrative %}{{ userAdministrative.annualEarnings }}{% else %}0{% endif %}">
</div>

<div class="pc-input-group">
<label class="pc-label required" for="transportFee">{{ 'users-transportFee'|trans }}</label>
<input type="number" min="0" step="any" id="transportFee" name="transportFee" required value="{% if userAdministrative %}{{ userAdministrative.transportFee }}{% else %}0{% endif %}">
</div>

<div class="pc-input-group">
<label class="pc-label required" for="sustainableMobilityFee">{{ 'users-sustainableMobilityFee'|trans }}</label>
<input type="number" min="0" step="any" id="sustainableMobilityFee" name="sustainableMobilityFee" required value="{% if userAdministrative %}{{ userAdministrative.sustainableMobilityFee }}{% else %}0{% endif %}">
</div>

<div class="pc-input-group">
<label class="pc-label required" for="sportsPassFee">{{ 'users-sportsPassFee'|trans }}</label>
<input type="number" min="0" step="any" id="sportsPassFee" name="sportsPassFee" required value="{% if userAdministrative %}{{ userAdministrative.sportsPassFee }}{% else %}0{% endif %}">
</div>
</div>

<div class="pc-grid pc-gap" style="--grid-cols: 2">
<div class="pc-input-group">
<label class="pc-label required" for="joiningDate">{{ 'users-joiningDate'|trans }}</label>
<input type="date" id="joiningDate" name="joiningDate" required {% if userAdministrative %}value="{{ userAdministrative.joiningDate }}"{% endif %}>
</div>

<div class="pc-input-group">
<label class="pc-label" for="leavingDate">{{ 'users-leavingDate'|trans }}</label>
<input type="date" id="leavingDate" name="leavingDate" {% if userAdministrative %}value="{{ userAdministrative.leavingDate }}"{% endif %}>
Expand Down
1 change: 1 addition & 0 deletions src/translations/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ users-healthInsurance = Mutuelle
users-annualEarnings = Salaire annuel brut
users-transportFee = Frais de transport
users-sustainableMobilityFee = Forfait mobilité durable
users-sportsPassFee = Forfait abonnement sportif
users-joiningDate = Date d'entrée
users-leavingDate = Date de sortie
Expand Down

0 comments on commit 3ecf653

Please sign in to comment.