rez_core 2.1.148 → 2.1.150

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.
Files changed (59) hide show
  1. package/dist/module/meta/entity/base-entity.entity.js.map +1 -1
  2. package/dist/module/workflow/controller/comm-template.controller.d.ts +1 -1
  3. package/dist/module/workflow/controller/task.controller.d.ts +12 -0
  4. package/dist/module/workflow/controller/task.controller.js +45 -0
  5. package/dist/module/workflow/controller/task.controller.js.map +1 -0
  6. package/dist/module/workflow/controller/workflow-meta.controller.d.ts +9 -3
  7. package/dist/module/workflow/controller/workflow-meta.controller.js +17 -10
  8. package/dist/module/workflow/controller/workflow-meta.controller.js.map +1 -1
  9. package/dist/module/workflow/entity/action-data.entity.d.ts +12 -0
  10. package/dist/module/workflow/entity/action-data.entity.js +58 -0
  11. package/dist/module/workflow/entity/action-data.entity.js.map +1 -0
  12. package/dist/module/workflow/entity/action.entity.d.ts +1 -0
  13. package/dist/module/workflow/entity/action.entity.js +4 -0
  14. package/dist/module/workflow/entity/action.entity.js.map +1 -1
  15. package/dist/module/workflow/entity/stage-movement-data.entity.d.ts +2 -0
  16. package/dist/module/workflow/entity/stage-movement-data.entity.js +8 -0
  17. package/dist/module/workflow/entity/stage-movement-data.entity.js.map +1 -1
  18. package/dist/module/workflow/entity/task-data.entity.d.ts +15 -0
  19. package/dist/module/workflow/entity/task-data.entity.js +70 -0
  20. package/dist/module/workflow/entity/task-data.entity.js.map +1 -0
  21. package/dist/module/workflow/entity/workflow-level-mapping.entity.d.ts +7 -0
  22. package/dist/module/workflow/entity/workflow-level-mapping.entity.js +38 -0
  23. package/dist/module/workflow/entity/workflow-level-mapping.entity.js.map +1 -0
  24. package/dist/module/workflow/repository/stage-movement.repository.d.ts +23 -0
  25. package/dist/module/workflow/repository/stage-movement.repository.js +138 -0
  26. package/dist/module/workflow/repository/stage-movement.repository.js.map +1 -0
  27. package/dist/module/workflow/repository/task.repository.d.ts +7 -0
  28. package/dist/module/workflow/repository/task.repository.js +42 -0
  29. package/dist/module/workflow/repository/task.repository.js.map +1 -0
  30. package/dist/module/workflow/service/action.service.js +1 -1
  31. package/dist/module/workflow/service/action.service.js.map +1 -1
  32. package/dist/module/workflow/service/comm-template.service.d.ts +1 -1
  33. package/dist/module/workflow/service/comm-template.service.js +1 -1
  34. package/dist/module/workflow/service/comm-template.service.js.map +1 -1
  35. package/dist/module/workflow/service/task.service.d.ts +8 -0
  36. package/dist/module/workflow/service/task.service.js +31 -0
  37. package/dist/module/workflow/service/task.service.js.map +1 -0
  38. package/dist/module/workflow/service/workflow-meta.service.d.ts +11 -5
  39. package/dist/module/workflow/service/workflow-meta.service.js +57 -22
  40. package/dist/module/workflow/service/workflow-meta.service.js.map +1 -1
  41. package/dist/module/workflow/workflow.module.js +14 -0
  42. package/dist/module/workflow/workflow.module.js.map +1 -1
  43. package/dist/tsconfig.build.tsbuildinfo +1 -1
  44. package/package.json +1 -1
  45. package/src/module/meta/entity/base-entity.entity.ts +1 -1
  46. package/src/module/workflow/controller/task.controller.ts +40 -0
  47. package/src/module/workflow/controller/workflow-meta.controller.ts +29 -5
  48. package/src/module/workflow/entity/action-data.entity.ts +34 -0
  49. package/src/module/workflow/entity/action.entity.ts +3 -0
  50. package/src/module/workflow/entity/stage-movement-data.entity.ts +6 -0
  51. package/src/module/workflow/entity/task-data.entity.ts +43 -0
  52. package/src/module/workflow/entity/workflow-level-mapping.entity.ts +18 -0
  53. package/src/module/workflow/repository/stage-movement.repository.ts +215 -0
  54. package/src/module/workflow/repository/task.repository.ts +30 -0
  55. package/src/module/workflow/service/action.service.ts +1 -1
  56. package/src/module/workflow/service/comm-template.service.ts +1 -1
  57. package/src/module/workflow/service/task.service.ts +25 -0
  58. package/src/module/workflow/service/workflow-meta.service.ts +128 -23
  59. package/src/module/workflow/workflow.module.ts +14 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.1.148",
3
+ "version": "2.1.150",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -49,7 +49,7 @@ export class BaseEntity {
49
49
  @Expose()
50
50
  modified_by: number;
51
51
 
52
- @Column({ name: 'modified_date', nullable: true })
52
+ @Column({ name: 'modified_date', nullable: true })
53
53
  @Expose()
54
54
  modified_date: Date;
55
55
 
@@ -0,0 +1,40 @@
1
+ import {
2
+ Body,
3
+ Controller,
4
+ HttpCode,
5
+ HttpStatus,
6
+ Inject,
7
+ Post,
8
+ Req,
9
+ UseGuards,
10
+ } from '@nestjs/common';
11
+ import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
12
+ import { TaskService } from '../service/task.service';
13
+
14
+ @Controller('/task')
15
+ @UseGuards(JwtAuthGuard)
16
+ export class TaskController {
17
+ constructor(
18
+ @Inject('TaskService')
19
+ private readonly taskService: TaskService,
20
+ ) {}
21
+
22
+ @Post('/getTasksbyUserAndStage')
23
+ @HttpCode(HttpStatus.OK)
24
+ async getTasksbyUserAndStage(
25
+ @Req() req: Request & { user: any },
26
+ @Body()
27
+ body: {
28
+ mapped_entity_type: string;
29
+ mapped_entity_id: number;
30
+ stage_id: number;
31
+ },
32
+ ) {
33
+ const loggedInUser = req.user.userData;
34
+ const result = this.taskService.getAllTaskByUserIdandStageId(
35
+ loggedInUser,
36
+ body,
37
+ );
38
+ return result;
39
+ }
40
+ }
@@ -1,8 +1,18 @@
1
- import { Controller, Get, Query, Post, Body } from '@nestjs/common';
1
+ import {
2
+ Controller,
3
+ Get,
4
+ Query,
5
+ Post,
6
+ Body,
7
+ Req,
8
+ UseGuards,
9
+ } from '@nestjs/common';
2
10
  import { WorkflowMetaService } from '../service/workflow-meta.service';
3
11
  import { StageMovementData } from '../entity/stage-movement-data.entity';
12
+ import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
4
13
 
5
14
  @Controller('workflow-meta')
15
+ @UseGuards(JwtAuthGuard)
6
16
  export class WorkflowMetaController {
7
17
  constructor(private readonly workflowMetaService: WorkflowMetaService) {}
8
18
 
@@ -13,8 +23,15 @@ export class WorkflowMetaController {
13
23
  async getCurrentStage(
14
24
  @Query('entityType') mapped_entity_type: string,
15
25
  @Query('entityId') mapped_entity_id: number,
26
+ @Req() req: Request & { user: any },
16
27
  ): Promise<StageMovementData | null> {
17
- return this.workflowMetaService.getCurrentStage(mapped_entity_type, Number(mapped_entity_id));
28
+ let loggedInUser = req.user.userData;
29
+
30
+ return this.workflowMetaService.getCurrentStage(
31
+ mapped_entity_type,
32
+ Number(mapped_entity_id),
33
+ loggedInUser,
34
+ );
18
35
  }
19
36
 
20
37
  /**
@@ -24,8 +41,14 @@ export class WorkflowMetaController {
24
41
  async getNextStage(
25
42
  @Query('entityType') mapped_entity_type: string,
26
43
  @Query('entityId') mapped_entity_id: number,
44
+ @Req() req: Request & { user: any },
27
45
  ): Promise<number | null> {
28
- const current = await this.workflowMetaService.getCurrentStage(mapped_entity_type, Number(mapped_entity_id));
46
+ const loggedInUser = req.user.userData;
47
+ const current = await this.workflowMetaService.getCurrentStage(
48
+ mapped_entity_type,
49
+ Number(mapped_entity_id),
50
+ loggedInUser,
51
+ );
29
52
  return current ? this.workflowMetaService.getNextStage(current) : null;
30
53
  }
31
54
 
@@ -41,12 +64,13 @@ export class WorkflowMetaController {
41
64
  async moveToNextStage(
42
65
  @Body('entityType') mapped_entity_type: string,
43
66
  @Body('entityId') mapped_entity_id: number,
44
- @Body('currentUserId') current_user_id: number,
67
+ @Req() req: Request & { user: any },
45
68
  ): Promise<string> {
69
+ const loggedInUser = req.user.userData;
46
70
  return this.workflowMetaService.moveToNextStage(
47
71
  mapped_entity_type,
48
72
  Number(mapped_entity_id),
49
- current_user_id,
73
+ loggedInUser,
50
74
  );
51
75
  }
52
76
  }
@@ -0,0 +1,34 @@
1
+ import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
2
+ import { Column, Entity } from 'typeorm';
3
+
4
+ @Entity({ name: 'cr_wf_action_data' })
5
+ export class ActionDataEntity extends BaseEntity {
6
+ constructor() {
7
+ super();
8
+ this.entity_type = 'ACTION_DATA';
9
+ }
10
+
11
+ @Column({ nullable: true })
12
+ action_id: number;
13
+
14
+ @Column({ nullable: true })
15
+ user_id: number;
16
+
17
+ @Column({ nullable: true })
18
+ stage_id: number;
19
+
20
+ @Column({ nullable: true })
21
+ start_time: Date;
22
+
23
+ @Column({ nullable: true })
24
+ end_time: Date;
25
+
26
+ @Column({ nullable: true })
27
+ is_mandatory: boolean;
28
+
29
+ @Column({ nullable: true })
30
+ mapped_entity_id: number;
31
+
32
+ @Column({ nullable: true })
33
+ mapped_entity_type: string;
34
+ }
@@ -29,4 +29,7 @@ export class ActionEntity extends BaseEntity {
29
29
 
30
30
  @Column({ default: 0, type: 'boolean' })
31
31
  default_value: boolean;
32
+
33
+ @Column({ nullable: true })
34
+ user_id: number;
32
35
  }
@@ -15,6 +15,12 @@ export class StageMovementData extends BaseEntity {
15
15
  @Column({ type: 'int', nullable: true })
16
16
  stage_action_mapping_id: number;
17
17
 
18
+ @Column({ type: 'int', nullable: true })
19
+ stage_group_id: number;
20
+
21
+ @Column({ type: 'int', nullable: true })
22
+ stage_id: number;
23
+
18
24
  @Column({ type: 'date', nullable: true })
19
25
  start_date: Date;
20
26
 
@@ -0,0 +1,43 @@
1
+ import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
2
+ import { Column, Entity } from 'typeorm';
3
+
4
+ @Entity({ name: 'cr_wf_task_data' })
5
+ export class TaskDataEntity extends BaseEntity {
6
+ constructor() {
7
+ super();
8
+ this.entity_type = 'TASK_DATA';
9
+ }
10
+
11
+ @Column({ nullable: true })
12
+ task_id: number;
13
+
14
+ @Column({ nullable: true })
15
+ user_id: number;
16
+
17
+ @Column({ nullable: true })
18
+ stage_id: number;
19
+
20
+ @Column({ nullable: true })
21
+ action_id: number;
22
+
23
+ @Column({ nullable: true })
24
+ start_time: Date;
25
+
26
+ @Column({ nullable: true })
27
+ end_time: Date;
28
+
29
+ @Column({ nullable: true })
30
+ is_completed: boolean;
31
+
32
+ @Column({ default: 0 })
33
+ is_system: boolean;
34
+
35
+ @Column({ nullable: true })
36
+ is_mandatory: boolean;
37
+
38
+ @Column({ nullable: true })
39
+ mapped_entity_id: number;
40
+
41
+ @Column({ nullable: true })
42
+ mapped_entity_type: string;
43
+ }
@@ -0,0 +1,18 @@
1
+ import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
2
+
3
+ @Entity({ name: 'cr_workflow_level_mapping' })
4
+ export class WorkflowLevelMappingEntity {
5
+ constructor() {}
6
+
7
+ @PrimaryGeneratedColumn()
8
+ id: number;
9
+
10
+ @Column({ nullable: true })
11
+ workflow_id: number;
12
+
13
+ @Column({ nullable: true })
14
+ mapped_level_id: string;
15
+
16
+ @Column({ nullable: true })
17
+ mapped_level_type: string;
18
+ }
@@ -0,0 +1,215 @@
1
+ import { get } from 'http';
2
+ import { Injectable } from '@nestjs/common';
3
+ import { InjectRepository } from '@nestjs/typeorm';
4
+ import { Repository, DataSource, MoreThan } from 'typeorm';
5
+ import { WorkflowLevelMappingEntity } from '../entity/workflow-level-mapping.entity';
6
+ import { StageGroup } from '../entity/stage-group.entity';
7
+ import { Stage } from '../entity/stage.entity';
8
+ import { log } from 'console';
9
+ import { UserData } from 'src/module/user/entity/user.entity';
10
+
11
+ @Injectable()
12
+ export class StageMovementRepository {
13
+ constructor(
14
+ @InjectRepository(WorkflowLevelMappingEntity)
15
+ private readonly workflowLevelMappingRepo: Repository<WorkflowLevelMappingEntity>,
16
+ @InjectRepository(StageGroup)
17
+ private readonly stageGroupRepo: Repository<StageGroup>,
18
+ @InjectRepository(Stage)
19
+ private readonly stageRepo: Repository<Stage>,
20
+ private readonly dataSource: DataSource,
21
+ ) {}
22
+
23
+ async getFirstStage({
24
+ loggedInUser,
25
+ mapped_entity_type,
26
+ mapped_entity_id,
27
+ }: {
28
+ loggedInUser: any;
29
+ mapped_entity_type: string;
30
+ mapped_entity_id: string | number;
31
+ }): Promise<any | null> {
32
+ // Try finding mapping at user's level
33
+ let workflowLevelMapping = await this.workflowLevelMappingRepo.findOne({
34
+ where: {
35
+ mapped_level_type: loggedInUser.level_type,
36
+ mapped_level_id: loggedInUser.level_id,
37
+ },
38
+ });
39
+
40
+ // If not found, fallback to organization-level mapping
41
+ if (!workflowLevelMapping) {
42
+ workflowLevelMapping = await this.workflowLevelMappingRepo.findOne({
43
+ where: {
44
+ mapped_level_type: 'ORG',
45
+ mapped_level_id: loggedInUser.organization_id,
46
+ },
47
+ });
48
+ }
49
+
50
+ // If still not found, return null
51
+ if (!workflowLevelMapping) return null;
52
+
53
+ // Find the stage group for this workflow
54
+ const stageGroup = await this.stageGroupRepo.findOne({
55
+ where: {
56
+ workflow_id: workflowLevelMapping.workflow_id,
57
+ },
58
+ order: { id: 'ASC' }, // Ensure you get the earliest/first group if needed
59
+ });
60
+
61
+ if (!stageGroup) return null;
62
+
63
+ // Find the first stage within this group
64
+ const firstStage = await this.stageRepo.findOne({
65
+ where: {
66
+ stage_group_id: stageGroup.id,
67
+ },
68
+ order: { id: 'ASC' }, // Change ordering as per your "first" logic
69
+ });
70
+
71
+ if (!firstStage) return null;
72
+
73
+ // Return comprehensive result
74
+ return {
75
+ mappingUsed: workflowLevelMapping,
76
+ stageGroup,
77
+ firstStage,
78
+ };
79
+ }
80
+
81
+ // async getNextStage(
82
+ // stageGroupId: number,
83
+ // currentStageId: number,
84
+ // ): Promise<any | null> {
85
+ // // 1. Get current stage to find its sequence number
86
+ // const currentStage = await this.stageRepo.findOne({
87
+ // where: { id: currentStageId, stage_group_id: stageGroupId },
88
+ // });
89
+ // if (!currentStage) return null;
90
+
91
+ // // 2. Find the next stage with sequence just after the current one
92
+ // const nextStage = await this.stageRepo.findOne({
93
+ // where: {
94
+ // stage_group_id: stageGroupId,
95
+ // sequence: MoreThan(currentStage.sequence),
96
+ // },
97
+ // order: { sequence: 'ASC' },
98
+ // });
99
+
100
+ // return nextStage || null;
101
+ // }
102
+
103
+ // async getNextStageGroup(
104
+ // currentStageGroupId: number,
105
+ // ): Promise<StageGroup | null> {
106
+ // // 1. Get current stage group
107
+ // const currentStageGroup = await this.stageGroupRepo.findOne({
108
+ // where: { id: currentStageGroupId },
109
+ // });
110
+ // if (!currentStageGroup) return null;
111
+ // // 2. Find the next stage group with a higher sequence
112
+ // const nextStageGroup = await this.stageGroupRepo.findOne({
113
+ // where: {
114
+ // sequence: MoreThan(currentStageGroup.sequence),
115
+ // },
116
+ // order: { sequence: 'ASC' }, // Get the immediate next
117
+ // });
118
+ // return nextStageGroup || null;
119
+ // }
120
+
121
+ async getNextStage(
122
+ stageGroupId: number,
123
+ currentStageId: number,
124
+ ): Promise<any | null> {
125
+ const allStages = await this.stageRepo.find({
126
+ where: { stage_group_id: stageGroupId },
127
+ order: { sequence: 'ASC' },
128
+ });
129
+
130
+ if (currentStageId === 0) return allStages.length > 0 ? allStages[0] : null;
131
+
132
+ const currentStage = allStages.find((s) => s.id == currentStageId);
133
+ if (!currentStage) return null;
134
+
135
+ // Filter for stages with a greater sequence, then pick the smallest one
136
+ const higherStages = allStages
137
+ .filter((s) => s.sequence > currentStage.sequence)
138
+ .sort((a, b) => a.sequence - b.sequence);
139
+
140
+ return higherStages.length > 0 ? higherStages[0] : null;
141
+ }
142
+
143
+ async getNextStageGroup(currentStageGroupId: number): Promise<any | null> {
144
+ const currentStageGroup = await this.stageGroupRepo.findOne({
145
+ where: { id: currentStageGroupId },
146
+ });
147
+ if (!currentStageGroup) return null;
148
+
149
+ //get workflow id of current stage group
150
+ const workflowId = currentStageGroup.workflow_id;
151
+
152
+ // Find the next stage group with a higher sequence
153
+ const nextStageGroup = await this.stageGroupRepo.findOne({
154
+ where: {
155
+ workflow_id: workflowId,
156
+ sequence: MoreThan(currentStageGroup.sequence),
157
+ },
158
+ order: { sequence: 'ASC' }, // Get the immediate next
159
+ });
160
+
161
+ return nextStageGroup || null;
162
+ }
163
+
164
+ async getNextStageOrFirstOfNextGroup(
165
+ stageGroupId: number,
166
+ currentStageId: number,
167
+ ): Promise<any | null> {
168
+ // 1. Try to get the next stage in same group
169
+ const nextStage = await this.getNextStage(stageGroupId, currentStageId);
170
+ if (nextStage) return nextStage;
171
+
172
+ // 2. No next stage. Try to get next stage group
173
+ const nextStageGroup = await this.getNextStageGroup(stageGroupId);
174
+ if (!nextStageGroup) return null;
175
+
176
+ const nextStageGroupFirstStage = await this.getNextStage(
177
+ nextStageGroup.id,
178
+ 0,
179
+ );
180
+ return nextStageGroupFirstStage || null;
181
+ }
182
+
183
+ async getAllActionByStageId(stageId: number): Promise<any[]> {
184
+ return this.dataSource.query(
185
+ `SELECT * FROM cr_wf_stage_action_mapping WHERE stage_id = ?`,
186
+ [stageId],
187
+ );
188
+ }
189
+
190
+ async saveActionData(action: any, loggedInUser: UserData): Promise<any> {
191
+ // Implement the logic to save action data
192
+
193
+ if (action.length > 0) {
194
+ for (const act of action) {
195
+ await this.dataSource.query(
196
+ `INSERT INTO cr_wf_action_data (stage_id, user_id, action_id) VALUES (?, ?, ?)`,
197
+ [act.stage_id, loggedInUser.id, act.id],
198
+ );
199
+ }
200
+ }
201
+ }
202
+
203
+ async saveTaskData(actionData: any, loggedInUser: UserData): Promise<any> {
204
+ // Implement the logic to save task data
205
+
206
+ if (actionData.length > 0) {
207
+ for (const action of actionData) {
208
+ await this.dataSource.query(
209
+ `INSERT INTO cr_wf_task_data (action_id, user_id) VALUES (?, ?)`,
210
+ [action.id, loggedInUser.id],
211
+ );
212
+ }
213
+ }
214
+ }
215
+ }
@@ -0,0 +1,30 @@
1
+ import { BadRequestException, Injectable } from '@nestjs/common';
2
+ import { InjectRepository } from '@nestjs/typeorm';
3
+ import { TaskDataEntity } from '../entity/task-data.entity';
4
+ import { Repository } from 'typeorm';
5
+
6
+ @Injectable()
7
+ export class TaskRepository {
8
+ constructor(
9
+ @InjectRepository(TaskDataEntity)
10
+ private readonly TaskRepository: Repository<TaskDataEntity>,
11
+ ) {}
12
+
13
+ async getAllTaskByUserIdAndStageId(
14
+ userId: number,
15
+ stageId: number,
16
+ mapped_entity_type: string,
17
+ mapped_entity_id: number,
18
+ ) {
19
+ const result = await this.TaskRepository.find({
20
+ where: {
21
+ user_id: userId,
22
+ stage_id: stageId,
23
+ mapped_entity_type,
24
+ mapped_entity_id,
25
+ },
26
+ });
27
+
28
+ return result;
29
+ }
30
+ }
@@ -288,7 +288,7 @@ export class ActionService extends EntityServiceImpl {
288
288
  .createQueryBuilder()
289
289
  .select([
290
290
  'a.id AS id',
291
- 'a.name AS action_name',
291
+ 'a.name AS name',
292
292
  'ac.name AS action_category',
293
293
  'ar.name AS action_requirement',
294
294
  ])
@@ -86,7 +86,7 @@ export class CommTemplateService extends EntityServiceImpl {
86
86
 
87
87
  const response = commTemplateData.map((item) => ({
88
88
  value: item.code,
89
- name: item.name,
89
+ label: item.name,
90
90
  }));
91
91
 
92
92
  return response;
@@ -0,0 +1,25 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
3
+ import { UserData } from 'src/module/user/entity/user.entity';
4
+ import { TaskRepository } from '../repository/task.repository';
5
+
6
+ @Injectable()
7
+ export class TaskService extends EntityServiceImpl {
8
+ constructor(private readonly taskRepository: TaskRepository) {
9
+ super();
10
+ }
11
+
12
+ async getAllTaskByUserIdandStageId(
13
+ loggedInUser: UserData,
14
+ data,
15
+ ): Promise<any> {
16
+ const taskData = await this.taskRepository.getAllTaskByUserIdAndStageId(
17
+ loggedInUser.id,
18
+ data.stage_id,
19
+ data.mapped_entity_type,
20
+ data.mapped_entity_id,
21
+ );
22
+
23
+ return taskData;
24
+ }
25
+ }