-
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
d6088a8
commit 94b16b3
Showing
19 changed files
with
280 additions
and
6 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
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,5 @@ | ||
import { IQuery } from 'src/Application/IQuery'; | ||
|
||
export class GetLeaveRequestsOverviewQuery implements IQuery { | ||
constructor(public readonly date: Date, public readonly userId: string) {} | ||
} |
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.userId | ||
); | ||
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
8 changes: 8 additions & 0 deletions
8
src/Infrastructure/HumanResource/Leave/DTO/ListLeaveRequestsControllerDTO.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,8 @@ | ||
import { IsUUID, IsOptional } from 'class-validator'; | ||
import { PaginationDTO } from 'src/Infrastructure/Common/DTO/PaginationDTO'; | ||
|
||
export class ListLeaveRequestsControllerDTO extends PaginationDTO { | ||
@IsUUID() | ||
@IsOptional() | ||
public userId?: string; | ||
} |
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
22 changes: 22 additions & 0 deletions
22
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,22 @@ | ||
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 = ['leaves-overview-daysRemaining']; | ||
|
||
const row = this.rowFactory | ||
.createBuilder() | ||
.template('pages/leave_requests/_overview_badge.njk', { | ||
overview | ||
}) | ||
.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
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,24 @@ | ||
{% macro filters_form() %} | ||
<pc-auto-form> | ||
<form | ||
method="GET" | ||
action="" | ||
class="pc-cluster pc-gap" | ||
style="--cluster-align: flex-end" | ||
> | ||
<div class="pc-select-group pc-m" style="--m: 0"> | ||
<label class="pc-label" for="userId">{{ 'leaves-user'|trans }}</label> | ||
<select name="userId" id="userId"> | ||
{% for user in users %} | ||
<option value="{{ user.id }}" {% if user.id == userId %}selected{% endif %}>{{ user|fullName }}</option> | ||
{% endfor %} | ||
</select> | ||
</div> | ||
<noscript> | ||
<button type="submit" class="pc-btn pc-btn--secondary"> | ||
{{ 'common-form-update'|trans }} | ||
</button> | ||
</noscript> | ||
</form> | ||
</pc-auto-form> | ||
{% endmacro %} |
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,16 @@ | ||
<span class="pc-badge pc-bold" style="--badge-color: var(--leave-daysRemaining-text); --badge-background: var(--leave-daysRemaining-background)"> | ||
{{ 'leaves-overview-daysRemaining-value'|trans({ daysRemaining: overview.daysRemaining }) }} | ||
</span> | ||
|
||
<span class="pc-relative"> | ||
<button | ||
popovertarget="leaves-explanation" | ||
class="pc-btn pc-btn--secondary pc-btn--circle" | ||
title="{{ 'leaves-overview-daysRemaining-showExplanation'|trans }}" | ||
aria-label="{{ 'leaves-overview-daysRemaining-showExplanation'|trans }}" | ||
>i</button> | ||
|
||
<div id="leaves-explanation" popover> | ||
{{ 'leaves-overview-daysRemaining-explanation-value'|trans({ daysTaken: overview.daysTaken, daysPerYear: overview.daysPerYear }) }} | ||
</div> | ||
</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
Oops, something went wrong.