-
Notifications
You must be signed in to change notification settings - Fork 573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat] Employee weekly schedule planning #8741
Open
samuelmbabhazi
wants to merge
19
commits into
develop
Choose a base branch
from
feat/#5293-weekly-schedule-planning
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e00c602
Implementation of employee weekly schedule planning
samuelmbabhazi 7c4e4f5
Feedback integration
samuelmbabhazi ff2bacb
Merge branch 'develop' into feat/#5293-weekly-schedule-planning
samuelmbabhazi c369a13
Feedback integration
samuelmbabhazi f7eb738
Feedback integration
samuelmbabhazi 96052b1
Feedback integration
samuelmbabhazi 6c3ba54
Fix deepscan
samuelmbabhazi 49d09b7
Merge branch 'develop' into feat/#5293-weekly-schedule-planning
rahul-rocket 2b926a6
refactor: updated employee availability feature
rahul-rocket 55092e8
fix: entity metadata for Employee#availabilities was not found
rahul-rocket a6a6e4c
Integration of requested changes
samuelmbabhazi b1dd009
Merge branch 'develop' into feat/#5293-weekly-schedule-planning
rahul-rocket 39e500f
fix: #5293 bulk insert method for employee availability
rahul-rocket 9037f32
fix: #5293 bulk insert method for employee availability
rahul-rocket 413bf4e
fix: #5293 apply validation and permissions guard
rahul-rocket 043f77f
fix: property 'tenantId' does not exist on type 'IEmployeeAvailabilit…
rahul-rocket fdab334
feat: #5293 added permission for Employee Availability
rahul-rocket d51f3f7
feat: #5293 added permission for Employee Availability
rahul-rocket d8ece61
feat: [table migration] for employee availability for all DB types.
rahul-rocket File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,64 @@ | ||
import { IBasePerTenantAndOrganizationEntityModel, ID } from './base-entity.model'; | ||
import { IEmployee } from './employee.model'; | ||
|
||
/** | ||
* Enum representing different availability statuses. | ||
*/ | ||
export enum AvailabilityStatusEnum { | ||
Available = 'Available', | ||
Partial = 'Partial', | ||
Unavailable = 'Unavailable' | ||
} | ||
|
||
/** | ||
* Enum mapping availability statuses to numerical values. | ||
*/ | ||
export enum AvailabilityStatusValue { | ||
Available = 0, | ||
Partial = 1, | ||
Unavailable = 2 | ||
} | ||
|
||
/** | ||
* A mapping object to relate status labels to their respective numerical values. | ||
*/ | ||
export const AvailabilityStatusMap: Record<AvailabilityStatusEnum, AvailabilityStatusValue> = { | ||
[AvailabilityStatusEnum.Available]: AvailabilityStatusValue.Available, | ||
[AvailabilityStatusEnum.Partial]: AvailabilityStatusValue.Partial, | ||
[AvailabilityStatusEnum.Unavailable]: AvailabilityStatusValue.Unavailable | ||
}; | ||
|
||
/** | ||
* Base interface for Employee Availability data. | ||
* Includes common properties shared across different input types. | ||
*/ | ||
interface IBaseEmployeeAvailability extends IBasePerTenantAndOrganizationEntityModel { | ||
employeeId: ID; | ||
startDate: Date; | ||
endDate: Date; | ||
dayOfWeek: number; // 0 = Sunday, 6 = Saturday | ||
availabilityStatus: AvailabilityStatusEnum; | ||
availabilityNotes?: string; | ||
} | ||
|
||
/** | ||
* Represents an Employee Availability record. | ||
*/ | ||
export interface IEmployeeAvailability extends IBaseEmployeeAvailability { | ||
employee: IEmployee; | ||
} | ||
|
||
/** | ||
* Input interface for finding Employee Availability records. | ||
*/ | ||
export interface IEmployeeAvailabilityFindInput extends Partial<IBaseEmployeeAvailability> {} | ||
|
||
/** | ||
* Input interface for creating new Employee Availability records. | ||
*/ | ||
export interface IEmployeeAvailabilityCreateInput extends IBaseEmployeeAvailability {} | ||
|
||
/** | ||
* Input interface for updating Employee Availability records. | ||
*/ | ||
export interface IEmployeeAvailabilityUpdateInput extends Partial<IBaseEmployeeAvailability> {} |
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
8 changes: 8 additions & 0 deletions
8
.../core/src/lib/employee-availability/commands/employee-availability.bulk.create.command.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 { ICommand } from '@nestjs/cqrs'; | ||
import { IEmployeeAvailabilityCreateInput } from '@gauzy/contracts'; | ||
|
||
export class EmployeeAvailabilityBulkCreateCommand implements ICommand { | ||
static readonly type = '[Employee Availability] Bulk Create'; | ||
|
||
constructor(public readonly input: IEmployeeAvailabilityCreateInput[]) {} | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/core/src/lib/employee-availability/commands/employee-availability.create.command.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 { ICommand } from '@nestjs/cqrs'; | ||
import { IEmployeeAvailabilityCreateInput } from '@gauzy/contracts'; | ||
|
||
export class EmployeeAvailabilityCreateCommand implements ICommand { | ||
static readonly type = '[EmployeeAvailability] Create'; | ||
|
||
constructor(public readonly input: IEmployeeAvailabilityCreateInput) {} | ||
} |
36 changes: 36 additions & 0 deletions
36
.../lib/employee-availability/commands/handlers/employee-availability.bulk.create.handler.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,36 @@ | ||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; | ||
import { IEmployeeAvailability } from '@gauzy/contracts'; | ||
import { RequestContext } from '../../../core/context'; | ||
import { EmployeeAvailabilityService } from '../../employee-availability.service'; | ||
import { EmployeeAvailabilityBulkCreateCommand } from '../employee-availability.bulk.create.command'; | ||
import { EmployeeAvailability } from '../../employee-availability.entity'; | ||
|
||
/** | ||
* Handles the bulk creation of employee availability records. | ||
*/ | ||
@CommandHandler(EmployeeAvailabilityBulkCreateCommand) | ||
export class EmployeeAvailabilityBulkCreateHandler implements ICommandHandler<EmployeeAvailabilityBulkCreateCommand> { | ||
constructor(private readonly _availabilityService: EmployeeAvailabilityService) {} | ||
|
||
/** | ||
* Executes the bulk creation command for employee availability. | ||
* | ||
* @param command The command containing the list of availability records to create. | ||
* @returns A promise resolving to the list of created employee availability records. | ||
*/ | ||
public async execute(command: EmployeeAvailabilityBulkCreateCommand): Promise<IEmployeeAvailability[]> { | ||
const { input } = command; | ||
const tenantId = RequestContext.currentTenantId(); | ||
|
||
// Prepare employee availability records with tenantId | ||
const employeeAvailabilities = input.map(item => | ||
new EmployeeAvailability({ | ||
...item, | ||
tenantId | ||
}) | ||
); | ||
|
||
// Perform bulk insert using the availability service | ||
return await this._availabilityService.bulkCreate(employeeAvailabilities); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...e/src/lib/employee-availability/commands/handlers/employee-availability.create.handler.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,28 @@ | ||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; | ||
import { IEmployeeAvailability } from '@gauzy/contracts'; | ||
import { RequestContext } from '../../../core/context'; | ||
import { EmployeeAvailabilityService } from '../../employee-availability.service'; | ||
import { EmployeeAvailability } from '../../employee-availability.entity'; | ||
import { EmployeeAvailabilityCreateCommand } from '../employee-availability.create.command'; | ||
|
||
@CommandHandler(EmployeeAvailabilityCreateCommand) | ||
export class EmployeeAvailabilityCreateHandler implements ICommandHandler<EmployeeAvailabilityCreateCommand> { | ||
constructor(private readonly _availabilityService: EmployeeAvailabilityService) {} | ||
|
||
/** | ||
* Handles the creation of an employee availability record. | ||
* | ||
* @param {EmployeeAvailabilityCreateCommand} command - The command containing employee availability details. | ||
* @returns {Promise<IEmployeeAvailability>} - The newly created employee availability record. | ||
* @throws {BadRequestException} - If any validation fails (e.g., missing fields, invalid dates). | ||
*/ | ||
public async execute(command: EmployeeAvailabilityCreateCommand): Promise<IEmployeeAvailability> { | ||
const { input } = command; | ||
const tenantId = RequestContext.currentTenantId(); | ||
|
||
return await this._availabilityService.create(new EmployeeAvailability({ | ||
...input, | ||
tenantId | ||
})); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/core/src/lib/employee-availability/commands/handlers/index.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,7 @@ | ||
import { EmployeeAvailabilityBulkCreateHandler } from './employee-availability.bulk.create.handler'; | ||
import { EmployeeAvailabilityCreateHandler } from './employee-availability.create.handler'; | ||
|
||
/** | ||
* Exports all command handlers for EmployeeAvailability.` | ||
*/ | ||
export const CommandHandlers = [EmployeeAvailabilityBulkCreateHandler, EmployeeAvailabilityCreateHandler]; |
2 changes: 2 additions & 0 deletions
2
packages/core/src/lib/employee-availability/commands/index.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,2 @@ | ||
export * from './employee-availability.bulk.create.command'; | ||
export * from './employee-availability.create.command'; |
18 changes: 18 additions & 0 deletions
18
packages/core/src/lib/employee-availability/dto/create-employee-availability.dto.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,18 @@ | ||
import { IEmployeeAvailabilityCreateInput } from '@gauzy/contracts'; | ||
import { EmployeeAvailability } from '../employee-availability.entity'; | ||
import { TenantOrganizationBaseDTO } from '../../core'; | ||
import { IntersectionType, PartialType, PickType } from '@nestjs/swagger'; | ||
|
||
export class CreateEmployeeAvailabilityDTO | ||
extends IntersectionType( | ||
PartialType(TenantOrganizationBaseDTO), | ||
PickType(EmployeeAvailability, [ | ||
'dayOfWeek', | ||
'startDate', | ||
'endDate', | ||
'availabilityNotes', | ||
'availabilityStatus', | ||
'employeeId' | ||
]) | ||
) | ||
implements IEmployeeAvailabilityCreateInput {} |
8 changes: 8 additions & 0 deletions
8
packages/core/src/lib/employee-availability/dto/update-employee-availability.dto.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 { PartialType } from '@nestjs/mapped-types'; | ||
import { IEmployeeAvailabilityUpdateInput } from '@gauzy/contracts'; | ||
import { CreateEmployeeAvailabilityDTO } from './create-employee-availability.dto'; | ||
import { IntersectionType } from '@nestjs/swagger'; | ||
|
||
export class UpdateEmployeeAvailabilityDTO | ||
extends IntersectionType(PartialType(CreateEmployeeAvailabilityDTO)) | ||
implements IEmployeeAvailabilityUpdateInput {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve error handling in bulkCreate method.
The method has several issues that need to be addressed:
Apply this diff to fix the issues:
📝 Committable suggestion