rez_core 3.1.126 → 3.1.127

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": "3.1.126",
3
+ "version": "3.1.127",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -24,7 +24,7 @@ export class StageController {
24
24
  @Post('/getAllStage')
25
25
  async getAllStage(
26
26
  @Req() req: Request & { user: any },
27
- @Body() body: { stage_group_id: number },
27
+ @Body() body: { stage_group_id: number; mapped_entity_id: number },
28
28
  @Query() query: { show_previous: boolean },
29
29
  ) {
30
30
  const { organization_id } = req.user.userData;
@@ -34,6 +34,7 @@ export class StageService extends EntityServiceImpl {
34
34
  async getAllStage(
35
35
  payload: {
36
36
  stage_group_id: number;
37
+ mapped_entity_id: number;
37
38
  },
38
39
  organization_id: number,
39
40
  show_previous: boolean,
@@ -63,15 +64,52 @@ export class StageService extends EntityServiceImpl {
63
64
  return allStages;
64
65
  }
65
66
 
67
+ // 1. Get all stages up to the current stage group
66
68
  const allStageWithStageGroup =
67
69
  await this.stageRepository.getAllStageGroupAndStageByStageMovement(
68
70
  payload.stage_group_id,
69
71
  organization_id,
70
72
  );
71
73
 
72
- this.logger.debug('allStageWithStageGroup', allStageWithStageGroup);
74
+ // 2. Get stage movement history for this entity
75
+ const allStageMovementData = await this.dataSource.manager.find<{
76
+ id: number;
77
+ stage_group_id: number;
78
+ stage_id: number;
79
+ mapped_entity_id: number;
80
+ mapped_entity_type: string;
81
+ is_current: string;
82
+ }>('cr_wf_stage_movement_data', {
83
+ where: {
84
+ mapped_entity_id: payload.mapped_entity_id,
85
+ mapped_entity_type: 'LEAD',
86
+ },
87
+ order: { id: 'ASC' },
88
+ });
89
+
90
+ if (!allStageMovementData || allStageMovementData.length === 0) {
91
+ return allStageWithStageGroup;
92
+ }
93
+
94
+ // 3. Find the current stage movement (is_current === 'Y')
95
+ const currentMovement = allStageMovementData.find(
96
+ (m) => m.is_current === 'Y',
97
+ );
98
+
99
+ if (!currentMovement) {
100
+ return allStageWithStageGroup;
101
+ }
102
+
103
+ // 4. Filter stages up to and including the current stage_id
104
+ const filteredStages: any[] = [];
105
+ for (const stage of allStageWithStageGroup) {
106
+ filteredStages.push(stage);
107
+ if (stage.id === currentMovement.stage_id) {
108
+ break; // stop once we reach the current stage
109
+ }
110
+ }
73
111
 
74
- return allStageWithStageGroup;
112
+ return filteredStages;
75
113
  }
76
114
 
77
115
  async updateEntity(