-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Affiche le nb de congés payés restants
- Loading branch information
1 parent
26b471a
commit 35072a1
Showing
14 changed files
with
184 additions
and
3 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
src/Application/HumanResource/Leave/Query/GetLeaveRequestsOverviewQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { IQuery } from 'src/Application/IQuery'; | ||
import { User } from 'src/Domain/HumanResource/User/User.entity'; | ||
|
||
export class GetLeaveRequestsOverviewQuery implements IQuery { | ||
constructor(public readonly date: Date, public readonly user: User) {} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Application/HumanResource/Leave/Query/GetLeaveRequestsOverviewQueryHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Inject } from '@nestjs/common'; | ||
import { QueryHandler } from '@nestjs/cqrs'; | ||
import { GetLeaveRequestsOverviewQuery } from './GetLeaveRequestsOverviewQuery'; | ||
import { ILeaveRequestsOverview } from 'src/Domain/HumanResource/Leave/ILeaveRequestsOverview'; | ||
import { IDateUtils } from 'src/Application/IDateUtils'; | ||
import { ILeaveRepository } from 'src/Domain/HumanResource/Leave/Repository/ILeaveRepository'; | ||
|
||
@QueryHandler(GetLeaveRequestsOverviewQuery) | ||
export class GetLeaveRequestsOverviewQueryHandler { | ||
constructor( | ||
@Inject('IDateUtils') | ||
private readonly dateUtils: IDateUtils, | ||
@Inject('ILeaveRepository') | ||
private readonly leaveRepository: ILeaveRepository | ||
) {} | ||
|
||
public async execute( | ||
query: GetLeaveRequestsOverviewQuery | ||
): Promise<ILeaveRequestsOverview> { | ||
const [startDate, endDate] = this.dateUtils.getLeaveReferencePeriodDays( | ||
query.date | ||
); | ||
|
||
const numDaysPerWeek = this.dateUtils.getWorkedDaysPerWeek(); | ||
const numWeeks = this.dateUtils.getNumberOfPaidLeaveWeeks(); | ||
const daysPerYear = numWeeks * numDaysPerWeek; | ||
const totalDurationTaken = await this.leaveRepository.getSumOfDurationsBetween( | ||
startDate, | ||
endDate, | ||
query.user | ||
); | ||
const daysTaken = this.dateUtils.getLeaveDurationAsDays(totalDurationTaken); | ||
const daysRemaining = daysPerYear - daysTaken; | ||
|
||
return { | ||
daysPerYear, | ||
daysTaken, | ||
daysRemaining | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface ILeaveRequestsOverview { | ||
daysPerYear: number; | ||
daysTaken: number; | ||
daysRemaining: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/Infrastructure/HumanResource/Leave/Table/LeaveRequestOverviewTableFactory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { ILeaveRequestsOverview } from 'src/Domain/HumanResource/Leave/ILeaveRequestsOverview'; | ||
import { Table } from 'src/Infrastructure/Tables'; | ||
import { RowFactory } from 'src/Infrastructure/Tables/RowFactory'; | ||
|
||
@Injectable() | ||
export class LeaveRequestsOverviewTableFactory { | ||
constructor(private rowFactory: RowFactory) {} | ||
|
||
public create(overview: ILeaveRequestsOverview): Table { | ||
const columns = []; | ||
const rowBuilder = this.rowFactory.createBuilder(); | ||
|
||
for (const type in overview) { | ||
columns.push(`leaves-overview-${type}`); | ||
rowBuilder.template('pages/leave_requests/_overview_badge.njk', { | ||
type, | ||
days: overview[type] | ||
}); | ||
} | ||
|
||
const row = rowBuilder.build(); | ||
|
||
return new Table(columns, [row]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<span class="pc-badge pc-bold" style="--badge-color: var(--leave-{{ type }}-text); --badge-background: var(--leave-{{ type }}-background)"> | ||
{{ 'leaves-overview-days'|trans({ days: days }) }} | ||
</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters