Skip to content

Commit 9920bad

Browse files
authored
Merge pull request #8824 from ever-co/fix/created-by-user-field
[Fix] Updated "creator" to "createdByUser" Field
2 parents 8fa3f9b + b3d7cb5 commit 9920bad

39 files changed

+4853
-4844
lines changed

apps/gauzy/src/app/pages/approvals/approvals.component.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
PaginationFilterBaseComponent,
2222
IPaginationBase,
2323
PictureNameTagsComponent,
24-
CreateByComponent,
24+
CreatedByUserComponent,
2525
DateViewComponent,
2626
EmployeeWithLinksComponent,
2727
TaskTeamsComponent,
@@ -167,7 +167,8 @@ export class ApprovalsComponent extends PaginationFilterBaseComponent implements
167167
'employeeApprovals.employee.user',
168168
'teamApprovals',
169169
'teamApprovals.team',
170-
'tags'
170+
'tags',
171+
'createdByUser'
171172
],
172173
{ organizationId, tenantId }
173174
)
@@ -242,9 +243,10 @@ export class ApprovalsComponent extends PaginationFilterBaseComponent implements
242243
title: this.getTranslation('APPROVAL_REQUEST_PAGE.CREATED_BY'),
243244
type: 'custom',
244245
isFilterable: false,
245-
renderComponent: CreateByComponent,
246-
componentInitFunction: (instance: CreateByComponent, cell: Cell) => {
246+
renderComponent: CreatedByUserComponent<IRequestApproval>,
247+
componentInitFunction: (instance: CreatedByUserComponent<IRequestApproval>, cell: Cell) => {
247248
instance.rowData = cell.getRow().getData();
249+
instance.value = cell.getRawValue();
248250
}
249251
},
250252
createdAt: {

apps/gauzy/src/app/pages/pipelines/pipeline-deals/pipeline-deals.component.ts

+17-9
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ import { DealsService, ErrorHandlingService, PipelinesService, Store, ToastrServ
1010
import { debounceTime, filter, tap } from 'rxjs/operators';
1111
import { catchError, combineLatest, firstValueFrom, map, Observable, of, Subject, switchMap } from 'rxjs';
1212
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
13-
import { DeleteConfirmationComponent, IPaginationBase, PaginationFilterBaseComponent } from '@gauzy/ui-core/shared';
14-
import { PipelineDealCreatedByComponent } from '../table-components/pipeline-deal-created-by/pipeline-deal-created-by';
13+
import {
14+
CreatedByUserComponent,
15+
DeleteConfirmationComponent,
16+
IPaginationBase,
17+
PaginationFilterBaseComponent
18+
} from '@gauzy/ui-core/shared';
1519
import { PipelineDealExcerptComponent } from '../table-components/pipeline-deal-excerpt/pipeline-deal-excerpt.component';
1620
import { PipelineDealProbabilityComponent } from '../table-components/pipeline-deal-probability/pipeline-deal-probability.component';
1721

@@ -96,10 +100,14 @@ export class PipelineDealsComponent extends PaginationFilterBaseComponent implem
96100
const { id: pipelineId, organizationId, tenantId } = pipeline;
97101

98102
// Fetch pipeline deals
99-
return this._pipelinesService.getPipelineDeals(pipelineId, {
100-
organizationId,
101-
tenantId
102-
});
103+
return this._pipelinesService.getPipelineDeals(
104+
pipelineId,
105+
{
106+
organizationId,
107+
tenantId
108+
},
109+
['stage', 'createdByUser']
110+
);
103111
}),
104112
// Map the contacts to the clients property
105113
map(({ items }: IPagination<IDeal>) => items),
@@ -240,13 +248,13 @@ export class PipelineDealsComponent extends PaginationFilterBaseComponent implem
240248
instance.value = cell.getValue();
241249
}
242250
},
243-
createdBy: {
251+
createdByUser: {
244252
title: this.getTranslation('SM_TABLE.CREATED_BY'),
245253
type: 'custom',
246254
width: '30%',
247255
isFilterable: false,
248-
renderComponent: PipelineDealCreatedByComponent,
249-
componentInitFunction: (instance: PipelineDealCreatedByComponent, cell: Cell) => {
256+
renderComponent: CreatedByUserComponent<IDeal>,
257+
componentInitFunction: (instance: CreatedByUserComponent<IDeal>, cell: Cell) => {
250258
instance.rowData = cell.getRow().getData();
251259
instance.value = cell.getValue();
252260
}

apps/gauzy/src/app/pages/pipelines/routes/pipeline.resolver.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const PipelineResolver: ResolveFn<Observable<IPipeline>> = (
2929
const { id: organizationId, tenantId } = store.selectedOrganization;
3030

3131
// Get pipeline entity from the service
32-
return pipelinesService.getById(pipelineId, { organizationId, tenantId }, ['stages']).pipe(
32+
return pipelinesService.getById(pipelineId, { organizationId, tenantId }, ['stages', 'createdByUser']).pipe(
3333
map((pipeline: IPipeline) => {
3434
if (pipeline.organizationId !== organizationId) {
3535
router.navigate(['pages/sales/pipelines']);

apps/gauzy/src/app/pages/pipelines/table-components/pipeline-deal-created-by/pipeline-deal-created-by.ts

-11
This file was deleted.

apps/gauzy/src/app/pages/pipelines/table-components/pipeline-deal-probability/pipeline-deal-probability.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{{ probability }} - {{ 'PIPELINE_DEALS_PAGE.MEDIUM' | translate }}
99
</div>
1010
<div *ngSwitchCase="5" class="badge-success">{{ probability }} - {{ 'PIPELINE_DEALS_PAGE.HIGH' | translate }}</div>
11-
<div *ngSwitchDefault class="badge-default">
11+
<div *ngSwitchDefault class="badge-primary">
1212
{{ probability }} - {{ 'PIPELINE_DEALS_PAGE.UNKNOWN' | translate }}
1313
</div>
1414
</div>

apps/gauzy/src/app/pages/pipelines/table-components/pipeline-deal-probability/pipeline-deal-probability.component.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ import { IDeal } from '@gauzy/contracts';
66
templateUrl: './pipeline-deal-probability.component.html'
77
})
88
export class PipelineDealProbabilityComponent implements OnInit {
9-
@Input()
10-
value: string | number;
9+
@Input() value: string | number;
1110

12-
@Input()
13-
rowData: IDeal;
11+
@Input() rowData: IDeal;
1412

1513
probability: number;
1614

apps/gauzy/src/app/pages/tasks/components/task/task.component.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
AddTaskDialogComponent,
2020
ALL_PROJECT_SELECTED,
2121
AssignedToComponent,
22-
CreateByComponent,
22+
CreatedByUserComponent,
2323
CreatedAtComponent,
2424
DateViewComponent,
2525
DeleteConfirmationComponent,
@@ -211,11 +211,11 @@ export class TaskComponent extends PaginationFilterBaseComponent implements OnIn
211211
instance.value = cell.getValue();
212212
}
213213
},
214-
creator: {
214+
createdByUser: {
215215
title: this.getTranslation('TASKS_PAGE.TASKS_CREATOR'),
216216
type: 'custom',
217-
renderComponent: CreateByComponent,
218-
componentInitFunction: (instance: CreateByComponent, cell: Cell) => {
217+
renderComponent: CreatedByUserComponent<ITask>,
218+
componentInitFunction: (instance: CreatedByUserComponent<ITask>, cell: Cell) => {
219219
instance.value = cell.getValue();
220220
instance.rowData = cell.getRow().getData();
221221
},
@@ -225,7 +225,7 @@ export class TaskComponent extends PaginationFilterBaseComponent implements OnIn
225225
},
226226
filterFunction: (value: string) => {
227227
this.setFilter({
228-
field: 'creator.firstName',
228+
field: 'createdByUser.firstName',
229229
search: value
230230
});
231231
}
@@ -427,7 +427,7 @@ export class TaskComponent extends PaginationFilterBaseComponent implements OnIn
427427
'teams.members',
428428
'teams.members.employee',
429429
'teams.members.employee.user',
430-
'creator',
430+
'createdByUser',
431431
'organizationSprint',
432432
'taskStatus',
433433
'taskSize',

apps/gauzy/src/app/pages/tasks/components/task/tasks-layouts/tasks-sprint-view/task/task.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<ngx-project [rowData]="task"></ngx-project>
1313
</span>
1414
<span class="col">
15-
<ngx-create-by [rowData]="task"></ngx-create-by>
15+
<ngx-created-by-user [rowData]="task"></ngx-created-by-user>
1616
</span>
1717
<span class="col">
1818
<ngx-employee-with-links

packages/contracts/src/lib/dashboard.model.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { IBasePerTenantAndOrganizationEntityModel, JsonData, OmitFields } from './base-entity.model';
22
import { IDashboardWidget } from './dashboard-widget.model';
33
import { IEmployeeEntityInput } from './employee.model';
4-
import { ExcludeUserCreatorFields } from './user.model';
4+
import { ExcludeCreatedByUserFields } from './user.model';
55

66
/**
77
* Interface representing a Dashboard entity.
@@ -20,7 +20,7 @@ export interface IDashboard extends IBasePerTenantAndOrganizationEntityModel, IE
2020
*/
2121
export interface IDashboardCreateInput
2222
extends OmitFields<IDashboard, 'isDefault'>,
23-
ExcludeUserCreatorFields<IDashboard> {}
23+
ExcludeCreatedByUserFields<IDashboard> {}
2424

2525
/**
2626
* Input interface for updating a Dashboard entity.

packages/contracts/src/lib/deal.model.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface IDealBase extends IBasePerTenantAndOrganizationEntityModel {
1212
clientId?: ID;
1313
}
1414

15-
// IDeal interface with the additional stage and user creator properties
15+
// IDeal interface with the additional stage and created by user fields
1616
export interface IDeal extends IDealBase {}
1717

1818
// IDealCreateInput interface, omitting user-related fields from IDeal

packages/contracts/src/lib/user.model.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface IFindMeUser extends IBaseRelationsEntityModel {
3030
/**
3131
* Utility type to exclude `createdByUser` and `createdByUserId` fields.
3232
*/
33-
export type ExcludeUserCreatorFields<T, K extends keyof T = never> = Omit<T, 'createdByUser' | 'createdByUserId' | K>;
33+
export type ExcludeCreatedByUserFields<T, K extends keyof T = never> = Omit<T, 'createdByUser' | 'createdByUserId' | K>;
3434

3535
export interface IRelationalUser {
3636
user?: IUser; // User who performed the action (if applicable).

packages/core/src/lib/comment/comment.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class CommentService extends TenantAwareCrudService<Comment> {
8181
)
8282
);
8383

84-
// Subscribe the comment creator to the entity.
84+
// Subscribe the comment created by user to the entity.
8585
this._eventBus.publish(
8686
new CreateEntitySubscriptionEvent({
8787
entity: input.entity,

packages/core/src/lib/mention/mention.service.ts

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export class MentionService extends TenantAwareCrudService<Mention> {
7171
new CreateEntitySubscriptionEvent({
7272
entity: parentEntityType ?? entity,
7373
entityId: parentEntityId ?? entityId,
74+
employeeId: user.employeeId,
7475
type: EntitySubscriptionTypeEnum.MENTION,
7576
organizationId,
7677
tenantId

packages/core/src/lib/pipeline/pipeline.controller.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
UseGuards
1313
} from '@nestjs/common';
1414
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
15-
import { DeleteResult, UpdateResult } from 'typeorm';
15+
import { DeleteResult, FindOptionsWhere, UpdateResult } from 'typeorm';
1616
import { ID, IDeal, IPagination, IPipeline, PermissionsEnum } from '@gauzy/contracts';
1717
import { CrudController, OptionParams, PaginationParams } from './../core/crud';
1818
import { Pipeline } from './pipeline.entity';
@@ -76,9 +76,10 @@ export class PipelineController extends CrudController<Pipeline> {
7676
@Get('/:pipelineId/deals')
7777
async getPipelineDeals(
7878
@Param('pipelineId', UUIDValidationPipe) pipelineId: ID,
79-
@Query() options: OptionParams<Pipeline>
79+
@Query('where') where: FindOptionsWhere<Pipeline>,
80+
@Query('relations') relations: string[]
8081
): Promise<IPagination<IDeal>> {
81-
return await this.pipelineService.getPipelineDeals(pipelineId, options.where);
82+
return await this.pipelineService.getPipelineDeals(pipelineId, where, relations);
8283
}
8384

8485
/**

packages/core/src/lib/pipeline/pipeline.service.ts

+29-27
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ID, IDeal, IPagination, IPipeline, IPipelineStage } from '@gauzy/contra
55
import { isPostgres } from '@gauzy/config';
66
import { ConnectionEntityManager } from '../database/connection-entity-manager';
77
import { Pipeline } from './pipeline.entity';
8-
import { PipelineStage } from './../core/entities/internal';
8+
import { Deal, PipelineStage } from './../core/entities/internal';
99
import { RequestContext } from '../core/context/request-context';
1010
import { TenantAwareCrudService } from './../core/crud/tenant-aware-crud.service';
1111
import { TypeOrmDealRepository } from '../deal/repository/type-orm-deal.repository';
@@ -43,38 +43,40 @@ export class PipelineService extends TenantAwareCrudService<Pipeline> {
4343
* @param where - Additional conditions to filter the deals.
4444
* @returns An object containing an array of deals and the total number of deals.
4545
*/
46-
public async getPipelineDeals(pipelineId: ID, where?: FindOptionsWhere<Pipeline>): Promise<IPagination<IDeal>> {
47-
// Retrieve the current tenant ID from the request context
46+
public async getPipelineDeals(
47+
pipelineId: ID,
48+
where?: FindOptionsWhere<Pipeline>,
49+
relations: string[] = []
50+
): Promise<IPagination<IDeal>> {
51+
// Destructure organizationId and tenantId from where; fallback to current tenant if not provided
52+
const { organizationId } = where ?? {};
4853
const tenantId = RequestContext.currentTenantId() ?? where?.tenantId;
49-
const { organizationId } = where || {};
5054

51-
try {
52-
// Fetch deals related to the specified pipeline
53-
const items: IDeal[] = await this.typeOrmDealRepository.find({
54-
relations: {
55-
stage: true,
56-
createdByUser: true
57-
},
58-
where: {
59-
organizationId,
55+
// Prepare query options with ordering; add relations only if provided
56+
const queryOptions: FindManyOptions<Deal> = {
57+
// Build the where clause for the query
58+
where: {
59+
organizationId,
60+
tenantId,
61+
stage: {
62+
pipelineId,
6063
tenantId,
61-
stage: {
62-
pipelineId,
63-
tenantId,
64-
organizationId
65-
}
66-
},
67-
order: {
68-
stage: {
69-
index: 'ASC'
70-
}
64+
organizationId
7165
}
72-
});
66+
},
67+
order: { stage: { index: 'ASC' } }
68+
};
7369

74-
// Return the deals and their total count
75-
return { items, total: items.length };
70+
if (relations.length) {
71+
queryOptions.relations = relations;
72+
}
73+
74+
try {
75+
// Fetch deals and their total count
76+
const [items, total] = await this.typeOrmDealRepository.findAndCount(queryOptions);
77+
return { items, total };
7678
} catch (error) {
77-
console.error('Error fetching pipeline deals:', error);
79+
console.error(`Error fetching pipeline deals: ${error.message}`, error);
7880
return { items: [], total: 0 };
7981
}
8082
}

packages/core/src/lib/tasks/commands/handlers/automation-task.sync.handler.ts

+4
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ export class AutomationTaskSyncHandler implements ICommandHandler<AutomationTask
131131
entity: ITaskCreateInput | ITaskUpdateInput
132132
): Promise<ITask> {
133133
try {
134+
// Retrieve current user
135+
const user = RequestContext.currentUser();
136+
134137
// Retrieve the maximum task number for the project
135138
const maxNumber = await this._taskService.getMaxTaskNumberByProject(options);
136139

@@ -154,6 +157,7 @@ export class AutomationTaskSyncHandler implements ICommandHandler<AutomationTask
154157
new CreateEntitySubscriptionEvent({
155158
entity: BaseEntityEnum.Task,
156159
entityId: createdTask.id,
160+
employeeId: user.employeeId,
157161
type: EntitySubscriptionTypeEnum.CREATED_ENTITY,
158162
organizationId,
159163
tenantId

packages/core/src/lib/tasks/commands/handlers/task-create.handler.ts

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export class TaskCreateHandler implements ICommandHandler<TaskCreateCommand> {
138138
new CreateEntitySubscriptionEvent({
139139
entity: BaseEntityEnum.Task,
140140
entityId: task.id,
141+
employeeId: user?.employeeId,
141142
type: EntitySubscriptionTypeEnum.CREATED_ENTITY,
142143
organizationId,
143144
tenantId

packages/core/src/lib/tasks/task.subscriber.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ export class TaskSubscriber extends BaseEntityEventSubscriber<Task> {
3939
}
4040

4141
/**
42-
* Called before a Task entity is inserted into the database. This method sets the creator ID
42+
* Called before a Task entity is inserted into the database. This method sets the created by user ID
4343
* of the task based on the current user context.
4444
*
4545
* @param entity The Task entity about to be created.
4646
* @returns {Promise<void>} A promise that resolves when the pre-creation processing is complete.
4747
*/
4848
async beforeEntityCreate(entity: Task): Promise<void> {
4949
try {
50-
// Retrieve the current user's ID from RequestContext and assign it as the creator
50+
// Retrieve the current user's ID from RequestContext and assign it as the created by user
5151
if (entity) {
5252
entity.createdByUserId = RequestContext.currentUserId();
5353
}

packages/ui-core/core/src/lib/services/pipeline/pipelines.service.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ export class PipelinesService extends Service<IPipeline, IPipelineFindInput, IPi
4646
* @param where Filter conditions for fetching the deals
4747
* @returns A promise of paginated deals
4848
*/
49-
getPipelineDeals(pipelineId: ID, where?: IPipelineFindInput): Promise<IPagination<IDeal>> {
49+
getPipelineDeals(
50+
pipelineId: ID,
51+
where?: IPipelineFindInput,
52+
relations: string[] = []
53+
): Promise<IPagination<IDeal>> {
5054
return firstValueFrom(
5155
this.http.get<IPagination<IDeal>>(`${this.basePath}/${pipelineId}/deals`, {
52-
params: toParams({ where })
56+
params: toParams({ where, relations })
5357
})
5458
);
5559
}

packages/ui-core/i18n/assets/i18n/ar.json

+1
Original file line numberDiff line numberDiff line change
@@ -4404,6 +4404,7 @@
44044404
"LOW": "منخفض",
44054405
"MEDIUM": "متوسط",
44064406
"HIGH": "عالي",
4407+
"UNKNOWN": "Unknown",
44074408
"DEAL_DELETED": "تمت إزالة الصفقة '{{ name }}'",
44084409
"DEAL_EDITED": "تم تغيير الصفقة '{{ name }}'",
44094410
"DEAL_ADDED": "تمت إضافة الصفقة '{{ name }}'"

0 commit comments

Comments
 (0)