rez_core 2.2.52 → 2.2.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.2.52",
3
+ "version": "2.2.53",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -10,11 +10,15 @@ export class ActivityLogRepository {
10
10
 
11
11
  async getAllActivityLog(mapped_entity_type: string, loggedInUser) {
12
12
  const { organization_id } = loggedInUser;
13
- return this.activityLogRepository.find({
14
- where: {
15
- mapped_entity_type: mapped_entity_type,
16
- organization_id: organization_id,
17
- },
18
- });
13
+
14
+ return this.activityLogRepository
15
+ .createQueryBuilder('log')
16
+ .leftJoin('cr_user', 'user', 'log.user_id = user.id')
17
+ .where('log.mapped_entity_type = :mapped_entity_type', {
18
+ mapped_entity_type,
19
+ })
20
+ .andWhere('log.organization_id = :organization_id', { organization_id })
21
+ .addSelect('user.name', 'user_name') // Add only user_name
22
+ .getRawMany();
19
23
  }
20
24
  }
@@ -56,33 +56,85 @@ export class StageGroupRepository {
56
56
 
57
57
  if (!stageGroups.length) return [];
58
58
 
59
- // Step 2: Get all stages where stage_group_id IN (...)
59
+ // Step 2: Get all stages for these stage groups
60
60
  const stageGroupIds = stageGroups.map((sg) => sg.id);
61
61
 
62
62
  const stages = await this.dataSource.query(
63
63
  `
64
- SELECT
65
- cr_wf_stage.*,
66
- cr_user.name AS created_by_name
67
- FROM cr_wf_stage
68
- LEFT JOIN cr_user ON cr_wf_stage.created_by = cr_user.id
69
- WHERE cr_wf_stage.stage_group_id IN (${stageGroupIds.map(() => '?').join(',')})
70
- AND cr_wf_stage.organization_id = ?
71
- ORDER BY cr_wf_stage.sequence ASC
72
- `,
64
+ SELECT
65
+ cr_wf_stage.*,
66
+ cr_user.name AS created_by_name
67
+ FROM cr_wf_stage
68
+ LEFT JOIN cr_user ON cr_wf_stage.created_by = cr_user.id
69
+ WHERE cr_wf_stage.stage_group_id IN (${stageGroupIds.map(() => '?').join(',')})
70
+ AND cr_wf_stage.organization_id = ?
71
+ ORDER BY cr_wf_stage.sequence ASC
72
+ `,
73
73
  [...stageGroupIds, organization_id],
74
74
  );
75
75
 
76
- // Step 3: Group stages by stage_group_id
76
+ // Step 3: Get all counts in bulk
77
+ const stageIds = stages.map((s) => s.id);
78
+
79
+ // Task counts
80
+ const taskCounts = await this.dataSource.query(
81
+ `
82
+ SELECT stage_id, COUNT(*) AS task_count
83
+ FROM cr_wf_task_data
84
+ WHERE stage_id IN (${stageIds.map(() => '?').join(',')})
85
+ GROUP BY stage_id
86
+ `,
87
+ [...stageIds],
88
+ );
89
+
90
+ // Meeting counts
91
+ const meetingCounts = await this.dataSource.query(
92
+ `
93
+ SELECT stage_id, COUNT(*) AS meeting_count
94
+ FROM cr_lead_meeting
95
+ WHERE stage_id IN (${stageIds.map(() => '?').join(',')})
96
+ GROUP BY stage_id
97
+ `,
98
+ [...stageIds],
99
+ );
100
+
101
+ // Send communication counts
102
+ const sendCommCounts = await this.dataSource.query(
103
+ `
104
+ SELECT stage_id, COUNT(*) AS send_comm_count
105
+ FROM cr_lead_communication
106
+ WHERE stage_id IN (${stageIds.map(() => '?').join(',')}) AND type = 'SEND'
107
+ GROUP BY stage_id
108
+ `,
109
+ [...stageIds],
110
+ );
111
+
112
+ // Convert to maps for quick lookup
113
+ const taskCountMap = new Map(
114
+ taskCounts.map((row) => [row.stage_id, row.task_count]),
115
+ );
116
+ const meetingCountMap = new Map(
117
+ meetingCounts.map((row) => [row.stage_id, row.meeting_count]),
118
+ );
119
+ const sendCommCountMap = new Map(
120
+ sendCommCounts.map((row) => [row.stage_id, row.send_comm_count]),
121
+ );
122
+
123
+ // Step 4: Add counts to each stage
77
124
  const stageMap = new Map<number, any[]>();
78
125
  for (const stage of stages) {
126
+ const stageId = Number(stage.id);
127
+ stage.task_count = taskCountMap.get(stageId) || 0;
128
+ stage.meeting_count = meetingCountMap.get(stageId) || 0;
129
+ stage.send_comm_count = sendCommCountMap.get(stageId) || 0;
130
+
79
131
  if (!stageMap.has(stage.stage_group_id)) {
80
132
  stageMap.set(stage.stage_group_id, []);
81
133
  }
82
134
  stageMap.get(stage.stage_group_id)?.push(stage);
83
135
  }
84
136
 
85
- // Step 4: Attach stages to stage groups
137
+ // Step 5: Attach stages with counts to stage groups
86
138
  const result = stageGroups.map((stageGroup) => {
87
139
  return {
88
140
  ...stageGroup,