diff --git a/apps/gauzy/src/app/pages/equipment-sharing/equipment-sharing.component.ts b/apps/gauzy/src/app/pages/equipment-sharing/equipment-sharing.component.ts index 870f08c2729..6647e7f3502 100644 --- a/apps/gauzy/src/app/pages/equipment-sharing/equipment-sharing.component.ts +++ b/apps/gauzy/src/app/pages/equipment-sharing/equipment-sharing.component.ts @@ -40,8 +40,7 @@ import { DateViewComponent } from '../../@shared/table-components'; }) export class EquipmentSharingComponent extends PaginationFilterBaseComponent - implements OnInit, OnDestroy -{ + implements OnInit, OnDestroy { loading: boolean = false; disableButton: boolean = true; @@ -110,8 +109,8 @@ export class EquipmentSharingComponent this.selectedEmployeeId = user.employee ? user.employee.id : employee - ? employee.id - : null; + ? employee.id + : null; }), tap(() => this._refresh$.next(true)), tap(() => this.equipmentSharing$.next(true)), @@ -141,7 +140,7 @@ export class EquipmentSharingComponent .subscribe(); } - ngOnDestroy() {} + ngOnDestroy() { } setView() { this.viewComponentName = ComponentEnum.EQUIPMENT_SHARING; @@ -158,6 +157,7 @@ export class EquipmentSharingComponent (componentLayout) => componentLayout === ComponentLayoutStyleEnum.CARDS_GRID ), + tap(() => this.equipments = []), tap(() => this.equipmentSharing$.next(true)), untilDestroyed(this) ) @@ -246,16 +246,16 @@ export class EquipmentSharingComponent /** * Show/Hide Equipment Sharing Approved Button * - * @param equipement + * @param equipment * @returns */ - showApprovedButton(equipementSharing: IEquipmentSharing) { - if (equipementSharing) { + showApprovedButton(equipmentSharing: IEquipmentSharing) { + if (equipmentSharing) { const statues: RequestApprovalStatusTypesEnum[] = [ RequestApprovalStatusTypesEnum.REFUSED, RequestApprovalStatusTypesEnum.REQUESTED ]; - return statues.includes(equipementSharing.status); + return statues.includes(equipmentSharing.status); } return false; } @@ -263,34 +263,34 @@ export class EquipmentSharingComponent /** * Show/Hide Equipment Sharing Refuse Button * - * @param equipement + * @param equipment * @returns */ - showRefuseButton(equipementSharing: IEquipmentSharing) { - if (equipementSharing) { + showRefuseButton(equipmentSharing: IEquipmentSharing) { + if (equipmentSharing) { const statues: RequestApprovalStatusTypesEnum[] = [ RequestApprovalStatusTypesEnum.APPROVED, RequestApprovalStatusTypesEnum.REQUESTED ]; - return statues.includes(equipementSharing.status); + return statues.includes(equipmentSharing.status); } return false; } - async approval(equipementSharing: IEquipmentSharing) { + async approval(equipmentSharing: IEquipmentSharing) { if (!this.organization) { return; } try { - if (this.showApprovedButton(equipementSharing)) { + if (this.showApprovedButton(equipmentSharing)) { const request = await this.equipmentSharingService.approval( - equipementSharing.id + equipmentSharing.id ); if (request) { this.toastrService.success( 'EQUIPMENT_SHARING_PAGE.APPROVAL_SUCCESS', { - name: equipementSharing.name + name: equipmentSharing.name } ); } @@ -302,20 +302,20 @@ export class EquipmentSharingComponent } } - async refuse(equipementSharing: IEquipmentSharing) { + async refuse(equipmentSharing: IEquipmentSharing) { if (!this.organization) { return; } try { - if (this.showRefuseButton(equipementSharing)) { + if (this.showRefuseButton(equipmentSharing)) { const request = await this.equipmentSharingService.refuse( - equipementSharing.id + equipmentSharing.id ); if (request) { this.toastrService.success( 'EQUIPMENT_SHARING_PAGE.APPROVAL_SUCCESS', { - name: equipementSharing.name + name: equipmentSharing.name } ); } diff --git a/packages/core/src/equipment/dto/index.ts b/packages/core/src/equipment/dto/index.ts index 1839c642cd9..505f449d95d 100644 --- a/packages/core/src/equipment/dto/index.ts +++ b/packages/core/src/equipment/dto/index.ts @@ -1,2 +1,2 @@ export { CreateEquipmentDTO } from "./create-equipment.dto" -export { UpdateEquipmentDTO } from "./update-equipement.dto" \ No newline at end of file +export { UpdateEquipmentDTO } from "./update-equipment.dto" diff --git a/packages/core/src/equipment/dto/update-equipement.dto.ts b/packages/core/src/equipment/dto/update-equipment.dto.ts similarity index 100% rename from packages/core/src/equipment/dto/update-equipement.dto.ts rename to packages/core/src/equipment/dto/update-equipment.dto.ts diff --git a/packages/core/src/integration-map/commands/handlers/integration-map.sync-task.handler.ts b/packages/core/src/integration-map/commands/handlers/integration-map.sync-task.handler.ts index a1fbc5814b1..4ee688527a3 100644 --- a/packages/core/src/integration-map/commands/handlers/integration-map.sync-task.handler.ts +++ b/packages/core/src/integration-map/commands/handlers/integration-map.sync-task.handler.ts @@ -1,5 +1,6 @@ import { CommandHandler, ICommandHandler, CommandBus } from '@nestjs/cqrs'; import { IntegrationEntity } from '@gauzy/contracts'; +import { TaskService } from 'tasks/task.service'; import { IntegrationMapSyncEntityCommand } from './../integration-map.sync-entity.command'; import { IntegrationMapSyncTaskCommand } from './../integration-map.sync-task.command'; import { IntegrationMapService } from '../../integration-map.service'; @@ -12,7 +13,8 @@ export class IntegrationMapSyncTaskHandler constructor( private readonly _commandBus: CommandBus, - private readonly _integrationMapService: IntegrationMapService + private readonly _integrationMapService: IntegrationMapService, + private readonly _taskService: TaskService ) { } /** @@ -24,33 +26,56 @@ export class IntegrationMapSyncTaskHandler public async execute( command: IntegrationMapSyncTaskCommand ) { - const { input } = command; + const { triggeredEvent, input } = command; const { sourceId, organizationId, integrationId, entity } = input; const tenantId = RequestContext.currentTenantId() || input.tenantId; try { - const taskMap = await this._integrationMapService.findOneByWhereOptions({ + // Check if an integration map already exists for the issue + const integrationMap = await this._integrationMapService.findOneByWhereOptions({ entity: IntegrationEntity.TASK, sourceId, integrationId, organizationId, tenantId }); - await this._commandBus.execute( - new TaskUpdateCommand(taskMap.gauzyId, entity) - ); - return taskMap; + + // Try to find the corresponding task + try { + await this._taskService.findOneByIdString(integrationMap.gauzyId); + + // Update the corresponding task with the new input data + await this._commandBus.execute( + new TaskUpdateCommand(integrationMap.gauzyId, entity, triggeredEvent) + ); + } catch (error) { + console.log(`${IntegrationEntity.TASK} Not Found for integration GauzyID %s: `, integrationMap.gauzyId); + // Create a corresponding task with the new input data + await this._commandBus.execute( + new TaskCreateCommand({ + ...entity, + id: integrationMap.gauzyId + }) + ); + } + // Return the integration map + return integrationMap; } catch (error) { + // Handle errors and create a new task + // Create a new task with the provided entity data const task = await this._commandBus.execute( - new TaskCreateCommand(entity) + new TaskCreateCommand(entity, triggeredEvent) ); + + // Create a new integration map for the issue return await this._commandBus.execute( new IntegrationMapSyncEntityCommand({ gauzyId: task.id, + entity: IntegrationEntity.TASK, integrationId, sourceId, - entity: IntegrationEntity.TASK, - organizationId + organizationId, + tenantId }) ); } diff --git a/packages/core/src/integration-map/commands/integration-map.sync-task.command.ts b/packages/core/src/integration-map/commands/integration-map.sync-task.command.ts index 09fa6efd553..8b74d292167 100644 --- a/packages/core/src/integration-map/commands/integration-map.sync-task.command.ts +++ b/packages/core/src/integration-map/commands/integration-map.sync-task.command.ts @@ -5,6 +5,7 @@ export class IntegrationMapSyncTaskCommand implements ICommand { static readonly type = '[Integration Map] Sync Task'; constructor( - public readonly input: IIntegrationMapSyncEntity + public readonly input: IIntegrationMapSyncEntity, + public readonly triggeredEvent: boolean = true // Enabled the "2 Way Sync Triggered Event" Synchronization ) { } } diff --git a/packages/core/src/integration/hubstaff/hubstaff.service.ts b/packages/core/src/integration/hubstaff/hubstaff.service.ts index 059d00af1cb..d85ebb4e484 100644 --- a/packages/core/src/integration/hubstaff/hubstaff.service.ts +++ b/packages/core/src/integration/hubstaff/hubstaff.service.ts @@ -504,6 +504,9 @@ export class HubstaffService { if (!due_at) { due_at = new Date(moment().add(2, 'week').format('YYYY-MM-DD HH:mm:ss')); } + + // Step 1: Execute a command to initiate the synchronization process + const triggeredEvent = false; return await this._commandBus.execute( new IntegrationMapSyncTaskCommand({ entity: { @@ -520,7 +523,7 @@ export class HubstaffService { integrationId, organizationId, tenantId - }) + }, triggeredEvent) ); } )