rez_core 2.2.129 → 2.2.131
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/dist/module/master/controller/master.controller.d.ts +0 -4
- package/dist/module/master/service/master.service.d.ts +0 -4
- package/dist/module/master/service/master.service.js +4 -1
- package/dist/module/master/service/master.service.js.map +1 -1
- package/dist/module/workflow/controller/stage.controller.d.ts +3 -22
- package/dist/module/workflow/controller/stage.controller.js +1 -1
- package/dist/module/workflow/controller/stage.controller.js.map +1 -1
- package/dist/module/workflow/repository/stage.repository.d.ts +1 -0
- package/dist/module/workflow/repository/stage.repository.js +24 -0
- package/dist/module/workflow/repository/stage.repository.js.map +1 -1
- package/dist/module/workflow/service/stage.service.d.ts +5 -24
- package/dist/module/workflow/service/stage.service.js +24 -7
- package/dist/module/workflow/service/stage.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/master/service/master.service.ts +5 -2
- package/src/module/workflow/controller/stage.controller.ts +7 -1
- package/src/module/workflow/repository/stage.repository.ts +41 -0
- package/src/module/workflow/service/stage.service.ts +42 -9
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
1
|
+
import { BadRequestException, Injectable } from '@nestjs/common';
|
|
2
2
|
import { Brackets, EntityManager } from 'typeorm';
|
|
3
3
|
import { ExcelUtil } from 'src/utils/service/excelUtil.service';
|
|
4
4
|
import { EntityMasterService } from '../../meta/service/entity-master.service';
|
|
@@ -371,7 +371,10 @@ export class MasterService {
|
|
|
371
371
|
|
|
372
372
|
// ✅ if any row failed, return errors instead of inserting
|
|
373
373
|
if (errors.length > 0) {
|
|
374
|
-
|
|
374
|
+
throw new BadRequestException({
|
|
375
|
+
message: 'Validation errors found',
|
|
376
|
+
errors,
|
|
377
|
+
});
|
|
375
378
|
}
|
|
376
379
|
|
|
377
380
|
// ✅ only upsert if no validation errors
|
|
@@ -23,11 +23,17 @@ export class StageController {
|
|
|
23
23
|
@Post('/getAllStage')
|
|
24
24
|
async getAllStage(
|
|
25
25
|
@Req() req: Request & { user: any },
|
|
26
|
-
@Body()
|
|
26
|
+
@Body()
|
|
27
|
+
body: {
|
|
28
|
+
stage_group_id: number;
|
|
29
|
+
mapped_entity_id: number;
|
|
30
|
+
mapped_entity_type: string;
|
|
31
|
+
},
|
|
27
32
|
) {
|
|
28
33
|
const { organization_id } = req.user.userData;
|
|
29
34
|
return this.stageGroupService.getAllStage(
|
|
30
35
|
body.stage_group_id,
|
|
36
|
+
body.mapped_entity_id,
|
|
31
37
|
organization_id,
|
|
32
38
|
);
|
|
33
39
|
}
|
|
@@ -60,4 +60,45 @@ export class StageRepository {
|
|
|
60
60
|
|
|
61
61
|
return updatedStages;
|
|
62
62
|
}
|
|
63
|
+
|
|
64
|
+
async getStageGroupsWithStagesByWorkflowId(
|
|
65
|
+
stage_group_id: number,
|
|
66
|
+
organization_id: number,
|
|
67
|
+
): Promise<any[]> {
|
|
68
|
+
if (!stage_group_id) {
|
|
69
|
+
throw new BadRequestException('stage_group_id is required');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 1. Find the stage group to get workflow_id
|
|
73
|
+
const stageGroup = (await this.dataSource.manager.findOne(
|
|
74
|
+
'cr_wf_stage_group',
|
|
75
|
+
{
|
|
76
|
+
where: { id: stage_group_id, organization_id },
|
|
77
|
+
},
|
|
78
|
+
)) as StageGroup;
|
|
79
|
+
|
|
80
|
+
if (!stageGroup) {
|
|
81
|
+
throw new NotFoundException('Stage group not found');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 2. Fetch all groups + stages in one query
|
|
85
|
+
const rows = await this.dataSource.query(
|
|
86
|
+
`
|
|
87
|
+
SELECT
|
|
88
|
+
g.id as stage_group_id, g.name as stage_group_name, g.workflow_id,
|
|
89
|
+
s.*
|
|
90
|
+
FROM cr_wf_stage_group g
|
|
91
|
+
LEFT JOIN cr_wf_stage s ON s.stage_group_id = g.id
|
|
92
|
+
WHERE g.workflow_id = ? AND g.organization_id = ?
|
|
93
|
+
ORDER BY g.id, s.id
|
|
94
|
+
`,
|
|
95
|
+
[stageGroup.workflow_id, organization_id],
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
if (!rows || rows.length === 0) {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return rows;
|
|
103
|
+
}
|
|
63
104
|
}
|
|
@@ -9,26 +9,54 @@ import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.s
|
|
|
9
9
|
import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
|
|
10
10
|
import { UserData } from 'src/module/user/entity/user.entity';
|
|
11
11
|
import { StageRepository } from '../repository/stage.repository';
|
|
12
|
-
import { DataSource } from 'typeorm';
|
|
12
|
+
import { DataSource, Repository } from 'typeorm';
|
|
13
13
|
import { StageGroupRepository } from '../repository/stage-group.repository';
|
|
14
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
15
|
+
import { StageMovementData } from '../entity/stage-movement-data.entity';
|
|
14
16
|
|
|
15
17
|
@Injectable()
|
|
16
18
|
export class StageService extends EntityServiceImpl {
|
|
17
19
|
constructor(
|
|
18
20
|
private readonly stageRepository: StageRepository,
|
|
19
21
|
private readonly stageGroupRepository: StageGroupRepository,
|
|
22
|
+
@InjectRepository(StageMovementData)
|
|
23
|
+
private readonly stageMovementRepo: Repository<StageMovementData>,
|
|
20
24
|
private readonly dataSource: DataSource,
|
|
21
25
|
@Inject('ActionService')
|
|
22
26
|
private readonly actionService: ActionService,
|
|
23
27
|
) {
|
|
24
28
|
super();
|
|
25
29
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
|
|
31
|
+
async getAllStage(
|
|
32
|
+
stage_group_id: number,
|
|
33
|
+
mapped_entity_id: number,
|
|
34
|
+
organization_id: number,
|
|
35
|
+
) {
|
|
36
|
+
// 1. Get all stages under the given stage_group_id
|
|
37
|
+
const allStageGrpData =
|
|
38
|
+
await this.stageRepository.getStageGroupsWithStagesByWorkflowId(
|
|
39
|
+
stage_group_id,
|
|
40
|
+
organization_id,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
if (allStageGrpData.length === 0) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const stageMovementData = await this.stageMovementRepo.find({
|
|
48
|
+
where: {
|
|
49
|
+
mapped_entity_type: 'LEAD',
|
|
50
|
+
mapped_entity_id,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Build a lookup: stage_action_mapping_id → movement
|
|
55
|
+
const stageMovementMap = new Map(
|
|
56
|
+
stageMovementData.map((s) => [Number(s.stage_action_mapping_id), s]),
|
|
30
57
|
);
|
|
31
58
|
|
|
59
|
+
// 4. Fetch statuses (id → name map)
|
|
32
60
|
const statusListMaster = await this.dataSource.query(
|
|
33
61
|
`SELECT id, name
|
|
34
62
|
FROM cr_list_master_items
|
|
@@ -36,16 +64,21 @@ export class StageService extends EntityServiceImpl {
|
|
|
36
64
|
[organization_id],
|
|
37
65
|
);
|
|
38
66
|
|
|
39
|
-
// Build a lookup map: id → name
|
|
40
67
|
const statusMap = new Map(
|
|
41
68
|
statusListMaster.map((s) => [String(s.id), s.name]),
|
|
42
69
|
);
|
|
43
70
|
|
|
44
|
-
|
|
45
|
-
|
|
71
|
+
// 5. Enrich result in a single pass
|
|
72
|
+
for (const stage of allStageGrpData) {
|
|
73
|
+
// Attach human-readable status
|
|
74
|
+
stage.status = statusMap.get(String(stage.status)) || stage.status;
|
|
75
|
+
|
|
76
|
+
// Attach is_current flag
|
|
77
|
+
const movement = stageMovementMap.get(Number(stage.id));
|
|
78
|
+
stage.is_current = movement ? movement.is_current === 'Y' : false;
|
|
46
79
|
}
|
|
47
80
|
|
|
48
|
-
return
|
|
81
|
+
return allStageGrpData;
|
|
49
82
|
}
|
|
50
83
|
|
|
51
84
|
async updateEntity(
|