rez_core 2.2.8 → 2.2.10

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 (213) hide show
  1. package/dist/constant/global.constant.d.ts +2 -1
  2. package/dist/constant/global.constant.js +3 -2
  3. package/dist/constant/global.constant.js.map +1 -1
  4. package/dist/module/filter/controller/filter.controller.d.ts +1 -1
  5. package/dist/module/filter/controller/filter.controller.js +7 -4
  6. package/dist/module/filter/controller/filter.controller.js.map +1 -1
  7. package/dist/module/filter/dto/filter-request.dto.d.ts +1 -0
  8. package/dist/module/filter/service/filter.service.js +25 -3
  9. package/dist/module/filter/service/filter.service.js.map +1 -1
  10. package/dist/module/layout_preference/controller/layout_preference.controller.js +4 -4
  11. package/dist/module/layout_preference/controller/layout_preference.controller.js.map +1 -1
  12. package/dist/module/layout_preference/entity/layout_preference.entity.d.ts +2 -0
  13. package/dist/module/layout_preference/entity/layout_preference.entity.js +13 -0
  14. package/dist/module/layout_preference/entity/layout_preference.entity.js.map +1 -1
  15. package/dist/module/layout_preference/repository/layout_preference.repository.d.ts +1 -1
  16. package/dist/module/layout_preference/repository/layout_preference.repository.js +4 -2
  17. package/dist/module/layout_preference/repository/layout_preference.repository.js.map +1 -1
  18. package/dist/module/layout_preference/service/layout_preference.service.d.ts +1 -1
  19. package/dist/module/layout_preference/service/layout_preference.service.js +17 -4
  20. package/dist/module/layout_preference/service/layout_preference.service.js.map +1 -1
  21. package/dist/module/listmaster/entity/list-master-items.entity.js +5 -5
  22. package/dist/module/listmaster/entity/list-master-items.entity.js.map +1 -1
  23. package/dist/module/meta/controller/media.controller.d.ts +1 -1
  24. package/dist/module/meta/controller/media.controller.js +1 -1
  25. package/dist/module/meta/controller/media.controller.js.map +1 -1
  26. package/dist/module/meta/entity/base-entity.entity.js.map +1 -1
  27. package/dist/module/module/controller/module-access.controller.d.ts +1 -1
  28. package/dist/module/module/controller/module-access.controller.js +6 -6
  29. package/dist/module/module/controller/module-access.controller.js.map +1 -1
  30. package/dist/module/module/service/module-access.service.d.ts +2 -1
  31. package/dist/module/module/service/module-access.service.js +5 -3
  32. package/dist/module/module/service/module-access.service.js.map +1 -1
  33. package/dist/module/workflow/controller/action-category.controller.d.ts +8 -0
  34. package/dist/module/workflow/controller/action-category.controller.js +45 -0
  35. package/dist/module/workflow/controller/action-category.controller.js.map +1 -0
  36. package/dist/module/workflow/controller/action.controller.d.ts +28 -0
  37. package/dist/module/workflow/controller/action.controller.js +88 -0
  38. package/dist/module/workflow/controller/action.controller.js.map +1 -0
  39. package/dist/module/workflow/controller/comm-template.controller.d.ts +11 -0
  40. package/dist/module/workflow/controller/comm-template.controller.js +44 -0
  41. package/dist/module/workflow/controller/comm-template.controller.js.map +1 -0
  42. package/dist/module/workflow/controller/entity-modification.controller.d.ts +8 -0
  43. package/dist/module/workflow/controller/entity-modification.controller.js +44 -0
  44. package/dist/module/workflow/controller/entity-modification.controller.js.map +1 -0
  45. package/dist/module/workflow/controller/stage-group.controller.d.ts +10 -0
  46. package/dist/module/workflow/controller/stage-group.controller.js +43 -0
  47. package/dist/module/workflow/controller/stage-group.controller.js.map +1 -0
  48. package/dist/module/workflow/controller/stage.controller.d.ts +13 -0
  49. package/dist/module/workflow/controller/stage.controller.js +56 -0
  50. package/dist/module/workflow/controller/stage.controller.js.map +1 -0
  51. package/dist/module/workflow/controller/task.controller.d.ts +21 -0
  52. package/dist/module/workflow/controller/task.controller.js +58 -0
  53. package/dist/module/workflow/controller/task.controller.js.map +1 -0
  54. package/dist/module/workflow/controller/workflow-meta.controller.d.ts +15 -0
  55. package/dist/module/workflow/controller/workflow-meta.controller.js +70 -0
  56. package/dist/module/workflow/controller/workflow-meta.controller.js.map +1 -0
  57. package/dist/module/workflow/controller/workflow.controller.d.ts +25 -10
  58. package/dist/module/workflow/controller/workflow.controller.js +32 -15
  59. package/dist/module/workflow/controller/workflow.controller.js.map +1 -1
  60. package/dist/module/workflow/entity/action-category.entity.d.ts +1 -0
  61. package/dist/module/workflow/entity/action-category.entity.js +4 -0
  62. package/dist/module/workflow/entity/action-category.entity.js.map +1 -1
  63. package/dist/module/workflow/entity/action-data.entity.d.ts +15 -0
  64. package/dist/module/workflow/entity/action-data.entity.js +70 -0
  65. package/dist/module/workflow/entity/action-data.entity.js.map +1 -0
  66. package/dist/module/workflow/entity/action.entity.d.ts +7 -2
  67. package/dist/module/workflow/entity/action.entity.js +30 -10
  68. package/dist/module/workflow/entity/action.entity.js.map +1 -1
  69. package/dist/module/workflow/entity/comm-template.entity.d.ts +5 -0
  70. package/dist/module/workflow/entity/comm-template.entity.js +21 -1
  71. package/dist/module/workflow/entity/comm-template.entity.js.map +1 -1
  72. package/dist/module/workflow/entity/entity-modification.entity.d.ts +13 -0
  73. package/dist/module/workflow/entity/entity-modification.entity.js +63 -0
  74. package/dist/module/workflow/entity/entity-modification.entity.js.map +1 -0
  75. package/dist/module/workflow/entity/stage-group.entity.d.ts +1 -1
  76. package/dist/module/workflow/entity/stage-group.entity.js +1 -1
  77. package/dist/module/workflow/entity/stage-group.entity.js.map +1 -1
  78. package/dist/module/workflow/entity/stage-movement-data.entity.d.ts +4 -0
  79. package/dist/module/workflow/entity/stage-movement-data.entity.js +16 -0
  80. package/dist/module/workflow/entity/stage-movement-data.entity.js.map +1 -1
  81. package/dist/module/workflow/entity/stage.entity.d.ts +2 -2
  82. package/dist/module/workflow/entity/stage.entity.js +5 -5
  83. package/dist/module/workflow/entity/stage.entity.js.map +1 -1
  84. package/dist/module/workflow/entity/task-data.entity.d.ts +25 -0
  85. package/dist/module/workflow/entity/task-data.entity.js +110 -0
  86. package/dist/module/workflow/entity/task-data.entity.js.map +1 -0
  87. package/dist/module/workflow/entity/template-attach-mapper.entity.d.ts +11 -0
  88. package/dist/module/workflow/entity/template-attach-mapper.entity.js +54 -0
  89. package/dist/module/workflow/entity/template-attach-mapper.entity.js.map +1 -0
  90. package/dist/module/workflow/entity/workflow-level-mapping.entity.d.ts +7 -0
  91. package/dist/module/workflow/entity/workflow-level-mapping.entity.js +38 -0
  92. package/dist/module/workflow/entity/workflow-level-mapping.entity.js.map +1 -0
  93. package/dist/module/workflow/entity/workflow.entity.d.ts +2 -0
  94. package/dist/module/workflow/entity/workflow.entity.js +8 -0
  95. package/dist/module/workflow/entity/workflow.entity.js.map +1 -1
  96. package/dist/module/workflow/repository/action-data.repository.d.ts +10 -0
  97. package/dist/module/workflow/repository/action-data.repository.js +85 -0
  98. package/dist/module/workflow/repository/action-data.repository.js.map +1 -0
  99. package/dist/module/workflow/repository/action.repository.d.ts +17 -0
  100. package/dist/module/workflow/repository/action.repository.js +97 -0
  101. package/dist/module/workflow/repository/action.repository.js.map +1 -0
  102. package/dist/module/workflow/repository/comm-template.repository.d.ts +14 -0
  103. package/dist/module/workflow/repository/comm-template.repository.js +87 -0
  104. package/dist/module/workflow/repository/comm-template.repository.js.map +1 -0
  105. package/dist/module/workflow/repository/stage-group.repository.d.ts +7 -0
  106. package/dist/module/workflow/repository/stage-group.repository.js +50 -0
  107. package/dist/module/workflow/repository/stage-group.repository.js.map +1 -0
  108. package/dist/module/workflow/repository/stage-movement.repository.d.ts +23 -0
  109. package/dist/module/workflow/repository/stage-movement.repository.js +142 -0
  110. package/dist/module/workflow/repository/stage-movement.repository.js.map +1 -0
  111. package/dist/module/workflow/repository/stage.repository.d.ts +7 -0
  112. package/dist/module/workflow/repository/stage.repository.js +50 -0
  113. package/dist/module/workflow/repository/stage.repository.js.map +1 -0
  114. package/dist/module/workflow/repository/task.repository.d.ts +10 -0
  115. package/dist/module/workflow/repository/task.repository.js +77 -0
  116. package/dist/module/workflow/repository/task.repository.js.map +1 -0
  117. package/dist/module/workflow/repository/workflow.repository.d.ts +9 -1
  118. package/dist/module/workflow/repository/workflow.repository.js +38 -6
  119. package/dist/module/workflow/repository/workflow.repository.js.map +1 -1
  120. package/dist/module/workflow/service/action-category.service.d.ts +5 -0
  121. package/dist/module/workflow/service/action-category.service.js +23 -1
  122. package/dist/module/workflow/service/action-category.service.js.map +1 -1
  123. package/dist/module/workflow/service/action-data.service.d.ts +11 -0
  124. package/dist/module/workflow/service/action-data.service.js +36 -0
  125. package/dist/module/workflow/service/action-data.service.js.map +1 -0
  126. package/dist/module/workflow/service/action.service.d.ts +19 -1
  127. package/dist/module/workflow/service/action.service.js +159 -10
  128. package/dist/module/workflow/service/action.service.js.map +1 -1
  129. package/dist/module/workflow/service/comm-template.service.d.ts +11 -0
  130. package/dist/module/workflow/service/comm-template.service.js +59 -1
  131. package/dist/module/workflow/service/comm-template.service.js.map +1 -1
  132. package/dist/module/workflow/service/entity-modification.service.d.ts +8 -0
  133. package/dist/module/workflow/service/entity-modification.service.js +52 -0
  134. package/dist/module/workflow/service/entity-modification.service.js.map +1 -0
  135. package/dist/module/workflow/service/populate-workflow.service.d.ts +21 -0
  136. package/dist/module/workflow/service/populate-workflow.service.js +124 -0
  137. package/dist/module/workflow/service/populate-workflow.service.js.map +1 -0
  138. package/dist/module/workflow/service/stage-group.service.d.ts +13 -0
  139. package/dist/module/workflow/service/stage-group.service.js +39 -1
  140. package/dist/module/workflow/service/stage-group.service.js.map +1 -1
  141. package/dist/module/workflow/service/stage.service.d.ts +14 -4
  142. package/dist/module/workflow/service/stage.service.js +57 -13
  143. package/dist/module/workflow/service/stage.service.js.map +1 -1
  144. package/dist/module/workflow/service/task.service.d.ts +18 -0
  145. package/dist/module/workflow/service/task.service.js +63 -0
  146. package/dist/module/workflow/service/task.service.js.map +1 -0
  147. package/dist/module/workflow/service/workflow-list-master.service.js +4 -4
  148. package/dist/module/workflow/service/workflow-meta.service.d.ts +20 -0
  149. package/dist/module/workflow/service/workflow-meta.service.js +137 -0
  150. package/dist/module/workflow/service/workflow-meta.service.js.map +1 -0
  151. package/dist/module/workflow/service/workflow.service.d.ts +28 -5
  152. package/dist/module/workflow/service/workflow.service.js +108 -41
  153. package/dist/module/workflow/service/workflow.service.js.map +1 -1
  154. package/dist/module/workflow/workflow.module.js +82 -15
  155. package/dist/module/workflow/workflow.module.js.map +1 -1
  156. package/dist/tsconfig.build.tsbuildinfo +1 -1
  157. package/package.json +1 -1
  158. package/src/constant/global.constant.ts +3 -1
  159. package/src/module/filter/controller/filter.controller.ts +10 -4
  160. package/src/module/filter/dto/filter-request.dto.ts +1 -0
  161. package/src/module/filter/service/filter.service.ts +38 -4
  162. package/src/module/layout_preference/controller/layout_preference.controller.ts +6 -4
  163. package/src/module/layout_preference/entity/layout_preference.entity.ts +11 -0
  164. package/src/module/layout_preference/repository/layout_preference.repository.ts +6 -2
  165. package/src/module/layout_preference/service/layout_preference.service.ts +31 -6
  166. package/src/module/listmaster/entity/list-master-items.entity.ts +5 -5
  167. package/src/module/meta/controller/media.controller.ts +5 -7
  168. package/src/module/meta/entity/base-entity.entity.ts +1 -1
  169. package/src/module/module/controller/module-access.controller.ts +9 -4
  170. package/src/module/module/service/module-access.service.ts +15 -8
  171. package/src/module/workflow/controller/action-category.controller.ts +35 -0
  172. package/src/module/workflow/controller/action.controller.ts +73 -0
  173. package/src/module/workflow/controller/comm-template.controller.ts +32 -0
  174. package/src/module/workflow/controller/entity-modification.controller.ts +35 -0
  175. package/src/module/workflow/controller/stage-group.controller.ts +33 -0
  176. package/src/module/workflow/controller/stage.controller.ts +50 -0
  177. package/src/module/workflow/controller/task.controller.ts +57 -0
  178. package/src/module/workflow/controller/workflow-meta.controller.ts +76 -0
  179. package/src/module/workflow/controller/workflow.controller.ts +32 -12
  180. package/src/module/workflow/entity/action-category.entity.ts +3 -0
  181. package/src/module/workflow/entity/action-data.entity.ts +43 -0
  182. package/src/module/workflow/entity/action.entity.ts +18 -3
  183. package/src/module/workflow/entity/comm-template.entity.ts +18 -1
  184. package/src/module/workflow/entity/entity-modification.entity.ts +38 -0
  185. package/src/module/workflow/entity/stage-group.entity.ts +1 -1
  186. package/src/module/workflow/entity/stage-movement-data.entity.ts +12 -0
  187. package/src/module/workflow/entity/stage.entity.ts +4 -4
  188. package/src/module/workflow/entity/task-data.entity.ts +73 -0
  189. package/src/module/workflow/entity/template-attach-mapper.entity.ts +30 -0
  190. package/src/module/workflow/entity/workflow-level-mapping.entity.ts +18 -0
  191. package/src/module/workflow/entity/workflow.entity.ts +6 -0
  192. package/src/module/workflow/repository/action-data.repository.ts +93 -0
  193. package/src/module/workflow/repository/action.repository.ts +104 -0
  194. package/src/module/workflow/repository/comm-template.repository.ts +102 -0
  195. package/src/module/workflow/repository/stage-group.repository.ts +46 -0
  196. package/src/module/workflow/repository/stage-movement.repository.ts +219 -0
  197. package/src/module/workflow/repository/stage.repository.ts +47 -0
  198. package/src/module/workflow/repository/task.repository.ts +85 -0
  199. package/src/module/workflow/repository/workflow.repository.ts +40 -2
  200. package/src/module/workflow/service/action-category.service.ts +26 -1
  201. package/src/module/workflow/service/action-data.service.ts +45 -0
  202. package/src/module/workflow/service/action-template-mapping.service.ts +1 -1
  203. package/src/module/workflow/service/action.service.ts +279 -19
  204. package/src/module/workflow/service/comm-template.service.ts +90 -1
  205. package/src/module/workflow/service/entity-modification.service.ts +67 -0
  206. package/src/module/workflow/service/populate-workflow.service.ts +189 -0
  207. package/src/module/workflow/service/stage-group.service.ts +67 -2
  208. package/src/module/workflow/service/stage.service.ts +104 -28
  209. package/src/module/workflow/service/task.service.ts +95 -0
  210. package/src/module/workflow/service/workflow-list-master.service.ts +4 -4
  211. package/src/module/workflow/service/workflow-meta.service.ts +231 -0
  212. package/src/module/workflow/service/workflow.service.ts +181 -50
  213. package/src/module/workflow/workflow.module.ts +82 -15
@@ -0,0 +1,104 @@
1
+ import {
2
+ BadRequestException,
3
+ Inject,
4
+ Injectable,
5
+ NotFoundException,
6
+ } from '@nestjs/common';
7
+ import { InjectRepository } from '@nestjs/typeorm';
8
+ import { DataSource, Repository } from 'typeorm';
9
+ import { ActionEntity } from '../entity/action.entity';
10
+ import { UserData } from 'src/module/user/entity/user.entity';
11
+
12
+ @Injectable()
13
+ export class ActionRepository {
14
+ constructor(
15
+ @InjectRepository(ActionEntity)
16
+ private readonly actionRepository: Repository<ActionEntity>,
17
+ private readonly dataSource: DataSource,
18
+ ) {}
19
+
20
+ async getAction(
21
+ organization_id: number,
22
+ stage_id: number,
23
+ mapped_entity_id: number,
24
+ mapped_entity_type: string,
25
+ ) {
26
+ // Step 1: Get all action mappings for the stage
27
+ const stageActions = await this.dataSource.query(
28
+ `SELECT id, action_id FROM cr_wf_stage_action_mapping WHERE stage_id = ?`,
29
+ [stage_id],
30
+ );
31
+
32
+ if (!stageActions?.length) return [];
33
+
34
+ const actionIds = stageActions.map((sa) => sa.action_id);
35
+
36
+ // Step 2: Fetch all actions from cr_wf_action
37
+ const actions = await this.dataSource
38
+ .createQueryBuilder()
39
+ .select([
40
+ 'a.id AS action_id',
41
+ 'a.name AS action_name',
42
+ 'ac.modalName AS modalName',
43
+ 'ac.logo AS logo',
44
+ 'ac.name AS action_category_name',
45
+ ])
46
+ .from('cr_wf_action', 'a')
47
+ .leftJoin('cr_wf_action_category', 'ac', 'ac.id = a.action_category')
48
+ .where('a.organization_id = :orgId', { orgId: organization_id })
49
+ .andWhere('a.id IN (:...actionIds)', { actionIds })
50
+ .getRawMany();
51
+
52
+ // Step 3: Fetch action_data for the matched stage and entity
53
+ const actionData = await this.dataSource
54
+ .createQueryBuilder()
55
+ .select([
56
+ 'ad.action_id AS action_id',
57
+ 'ad.is_current AS is_current',
58
+ 'ad.is_mandatory AS is_mandatory',
59
+ 'ad.is_done AS is_done',
60
+ ])
61
+ .from('cr_wf_action_data', 'ad')
62
+ .where('ad.stage_id = :stageId', { stageId: stage_id })
63
+ .andWhere('ad.action_id IN (:...actionIds)', { actionIds })
64
+ .andWhere('ad.mapped_entity_id = :mapped_entity_id', {
65
+ mapped_entity_id,
66
+ })
67
+ .andWhere('ad.mapped_entity_type = :mapped_entity_type', {
68
+ mapped_entity_type,
69
+ })
70
+ .getRawMany();
71
+
72
+ // Step 4: Build map of action_id to data
73
+ const actionIdToData = actionData.reduce((acc, row) => {
74
+ acc[row.action_id] = {
75
+ is_current: row.is_current === 'Y',
76
+ is_mandatory: row.is_mandatory === 1,
77
+ is_done: row.is_done === 1,
78
+ };
79
+ return acc;
80
+ }, {});
81
+
82
+ // Step 5: Enrich actions and set default current = false (N)
83
+ const enrichedResult = actions.map((row) => {
84
+ const data = actionIdToData[row.action_id];
85
+ return {
86
+ value: row.action_id,
87
+ label: row.action_name,
88
+ modalName: row.modalName,
89
+ logo: row.logo,
90
+ name: row.action_category_name,
91
+ is_current: data?.is_current ?? false,
92
+ is_done: data?.is_done ?? false,
93
+ is_mandatory: data?.is_mandatory ?? false,
94
+ };
95
+ });
96
+
97
+ enrichedResult.push({
98
+ value: 0,
99
+ label: 'Generic',
100
+ } as any);
101
+
102
+ return enrichedResult;
103
+ }
104
+ }
@@ -0,0 +1,102 @@
1
+ import { Injectable, NotFoundException } from '@nestjs/common';
2
+ import { InjectRepository } from '@nestjs/typeorm';
3
+ import { Workflow } from '../entity/workflow.entity';
4
+ import { Repository } from 'typeorm';
5
+ import { CommTemplate } from '../entity/comm-template.entity';
6
+ import { TemplateAttach } from '../entity/template-attach-mapper.entity';
7
+ import { MediaDataService } from 'src/module/meta/service/media-data.service';
8
+
9
+ @Injectable()
10
+ export class CommTemplateRepository {
11
+ constructor(
12
+ @InjectRepository(CommTemplate)
13
+ private readonly commTemplateRepository: Repository<CommTemplate>,
14
+ @InjectRepository(TemplateAttach)
15
+ private readonly templateAttachEntity: Repository<TemplateAttach>,
16
+ private readonly mediaDataService: MediaDataService,
17
+ ) {}
18
+
19
+ async getAllCommTemplate(entity_type: string, loggedInUser) {
20
+ const { organization_id } = loggedInUser;
21
+ return this.commTemplateRepository.find({
22
+ select: ['name', 'code'],
23
+ where: {
24
+ mapped_entity_type: entity_type,
25
+ organization_id: organization_id,
26
+ },
27
+ });
28
+ }
29
+
30
+ async save(commTemplate: any): Promise<any> {
31
+ // // delete existing mapper
32
+ // for (const attachment of commTemplate || []) {
33
+ // await this.templateAttachEntity.delete({
34
+ // entity_type: attachment.entity_type,
35
+ // template_id: attachment.template_id,
36
+ // });
37
+ // }
38
+
39
+ return this.templateAttachEntity.save(commTemplate);
40
+ }
41
+
42
+ async delete(id: any): Promise<any> {
43
+ // delete existing mapper
44
+ return await this.templateAttachEntity.delete(id);
45
+ }
46
+
47
+ async getTemplateByCode(
48
+ entity_type: string,
49
+ id: number,
50
+ loggedInUser,
51
+ ): Promise<any | null> {
52
+ const template = await this.commTemplateRepository.findOne({
53
+ where: { entity_type, id },
54
+ });
55
+
56
+ if (!template) {
57
+ throw new NotFoundException(`Template with id ${id} not found`);
58
+ }
59
+
60
+ if (template.format_type === 'markup') {
61
+ const media = await this.mediaDataService.getMediaDownloadUrl(
62
+ template.markup_id,
63
+ loggedInUser,
64
+ );
65
+ template.markup_id = media as any;
66
+ }
67
+
68
+ if (template.format_type === 'richtext') {
69
+ return template;
70
+ }
71
+
72
+ // Get attachments for this template
73
+ const attachments = await this.templateAttachEntity.find({
74
+ select: ['media_id'],
75
+ where: {
76
+ entity_type,
77
+ template_id: template.id,
78
+ },
79
+ });
80
+
81
+ // If there are attachments, return array of media JSONs
82
+ let attachmentsMedia: any[] = [];
83
+ if (attachments.length > 0) {
84
+ attachmentsMedia = await Promise.all(
85
+ attachments.map(async (att) => {
86
+ // Fetch media details for each media_id
87
+ const media = await this.mediaDataService.getMediaDownloadUrl(
88
+ att.media_id,
89
+ loggedInUser,
90
+ );
91
+ return media; // return full media info (e.g., { id, url, ... })
92
+ }),
93
+ );
94
+ }
95
+
96
+ // Return template with attachments array
97
+ return {
98
+ ...template,
99
+ attachments: attachmentsMedia, // [] or array of media JSONs
100
+ };
101
+ }
102
+ }
@@ -0,0 +1,46 @@
1
+ import {
2
+ BadRequestException,
3
+ Inject,
4
+ Injectable,
5
+ NotFoundException,
6
+ } from '@nestjs/common';
7
+ import { StageGroup } from '../entity/stage-group.entity';
8
+ import { InjectRepository } from '@nestjs/typeorm';
9
+ import { Repository } from 'typeorm';
10
+
11
+ @Injectable()
12
+ export class StageGroupRepository {
13
+ constructor(
14
+ @InjectRepository(StageGroup)
15
+ private readonly stageGroupRepository: Repository<StageGroup>,
16
+ ) {}
17
+
18
+ async getAllStageGroup(
19
+ workflow_id: number,
20
+ level_id: string,
21
+ level_type: string,
22
+ ) {
23
+ if (!workflow_id) {
24
+ throw new BadRequestException('workflow_id is required');
25
+ }
26
+
27
+ const result = await this.stageGroupRepository.find({
28
+ where: {
29
+ workflow_id,
30
+ level_id,
31
+ level_type,
32
+ },
33
+ order: {
34
+ sequence: 'ASC',
35
+ },
36
+ });
37
+
38
+ if (!result || result.length === 0) {
39
+ throw new NotFoundException(
40
+ 'No stage groups found for the given workflow ID',
41
+ );
42
+ }
43
+
44
+ return result;
45
+ }
46
+ }
@@ -0,0 +1,219 @@
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
+ const result = await this.dataSource.query(
185
+ `SELECT a.*, m.stage_id
186
+ FROM cr_wf_action a
187
+ INNER JOIN cr_wf_stage_action_mapping m ON a.id = m.action_id
188
+ WHERE m.stage_id = ?`,
189
+ [stageId],
190
+ );
191
+ return result;
192
+ }
193
+
194
+ async saveActionData(action: any, loggedInUser: UserData): Promise<any> {
195
+ // Implement the logic to save action data
196
+
197
+ if (action.length > 0) {
198
+ for (const act of action) {
199
+ await this.dataSource.query(
200
+ `INSERT INTO cr_wf_action_data (stage_id, user_id, action_id) VALUES (?, ?, ?)`,
201
+ [act.stage_id, loggedInUser.id, act.id],
202
+ );
203
+ }
204
+ }
205
+ }
206
+
207
+ async saveTaskData(actionData: any, loggedInUser: UserData): Promise<any> {
208
+ // Implement the logic to save task data
209
+
210
+ if (actionData.length > 0) {
211
+ for (const action of actionData) {
212
+ await this.dataSource.query(
213
+ `INSERT INTO cr_wf_task_data (action_id, user_id) VALUES (?, ?)`,
214
+ [action.id, loggedInUser.id],
215
+ );
216
+ }
217
+ }
218
+ }
219
+ }
@@ -0,0 +1,47 @@
1
+ import {
2
+ BadRequestException,
3
+ Inject,
4
+ Injectable,
5
+ NotFoundException,
6
+ } from '@nestjs/common';
7
+ import { StageGroup } from '../entity/stage-group.entity';
8
+ import { InjectRepository } from '@nestjs/typeorm';
9
+ import { Repository } from 'typeorm';
10
+ import { Stage } from '../entity/stage.entity';
11
+
12
+ @Injectable()
13
+ export class StageRepository {
14
+ constructor(
15
+ @InjectRepository(Stage)
16
+ private readonly stageRepository: Repository<Stage>,
17
+ ) {}
18
+
19
+ async getAllStage(
20
+ stage_group_id: number,
21
+ level_id: string,
22
+ level_type: string,
23
+ ) {
24
+ if (!stage_group_id) {
25
+ throw new BadRequestException('stage_group_id is required');
26
+ }
27
+
28
+ const result = await this.stageRepository.find({
29
+ where: {
30
+ stage_group_id,
31
+ level_id,
32
+ level_type,
33
+ },
34
+ order: {
35
+ sequence: 'ASC',
36
+ },
37
+ });
38
+
39
+ if (!result || result.length === 0) {
40
+ throw new NotFoundException(
41
+ 'No stage found for the given stage group ID',
42
+ );
43
+ }
44
+
45
+ return result;
46
+ }
47
+ }
@@ -0,0 +1,85 @@
1
+ import { BadRequestException, Injectable } from '@nestjs/common';
2
+ import { InjectRepository } from '@nestjs/typeorm';
3
+ import { TaskDataEntity } from '../entity/task-data.entity';
4
+ import { DataSource, Repository } from 'typeorm';
5
+
6
+ @Injectable()
7
+ export class TaskRepository {
8
+ constructor(
9
+ @InjectRepository(TaskDataEntity)
10
+ private readonly TaskRepository: Repository<TaskDataEntity>,
11
+ private readonly dataSource: DataSource,
12
+ ) {}
13
+
14
+ async getAllTaskByUserIdAndStageId(condition) {
15
+ const result = await this.TaskRepository.find({
16
+ where: {
17
+ ...condition,
18
+ },
19
+ });
20
+
21
+ return result;
22
+ }
23
+
24
+ async saveActionDataInTask(
25
+ action: any,
26
+ loggedInUser,
27
+ mapped_entity_id: number,
28
+ mapped_entity_type: string,
29
+ ): Promise<any> {
30
+ if (!action?.length) return;
31
+
32
+ const todoListMasterItemId = await this.dataSource.query(
33
+ `SELECT id FROM cr_list_master_items WHERE code = 'todo' and organization_id = ? and listtype = 'TKST' LIMIT 1;`,
34
+ [loggedInUser.organization_id],
35
+ );
36
+
37
+ // Find the action with the lowest sequence
38
+
39
+ if (action.length > 0) {
40
+ for (const act of action) {
41
+ const taskData = this.TaskRepository.create({
42
+ stage_id: act.stage_id,
43
+ user_id: loggedInUser.id,
44
+ action_id: act.id,
45
+ sequence: act.sequence,
46
+ mapped_entity_id,
47
+ mapped_entity_type,
48
+ is_system: true,
49
+ task_status: todoListMasterItemId[0]?.id,
50
+ } as TaskDataEntity);
51
+ await this.TaskRepository.save(taskData);
52
+ }
53
+ }
54
+ }
55
+
56
+ // update task status
57
+ async updateTaskStatus(
58
+ loggedInUser,
59
+ mapped_entity_type,
60
+ mapped_entity_id,
61
+ stage_id,
62
+ action_id,
63
+ ): Promise<any> {
64
+ const task = await this.TaskRepository.findOneBy({
65
+ action_id,
66
+ mapped_entity_type,
67
+ mapped_entity_id,
68
+ stage_id,
69
+ });
70
+
71
+ if (!task) return;
72
+
73
+ const completedListMasterItemId = await this.dataSource.query(
74
+ `SELECT id FROM cr_list_master_items WHERE code = 'completed' and organization_id = ? and listtype = 'TKST' LIMIT 1;`,
75
+ [loggedInUser.organization_id],
76
+ );
77
+
78
+ task.modified_by = loggedInUser.id;
79
+ task.modified_date = new Date();
80
+ task.is_done = true;
81
+ task.task_status = completedListMasterItemId[0]?.id;
82
+
83
+ await this.TaskRepository.update(task.id, task);
84
+ }
85
+ }
@@ -1,4 +1,42 @@
1
- import { Injectable } from '@nestjs/common';
1
+ import { Injectable, NotFoundException } from '@nestjs/common';
2
+ import { InjectRepository } from '@nestjs/typeorm';
3
+ import { Workflow } from '../entity/workflow.entity';
4
+ import { Repository } from 'typeorm';
2
5
 
3
6
  @Injectable()
4
- export class WorkflowRepsository {}
7
+ export class WorkflowRepository {
8
+ constructor(
9
+ @InjectRepository(Workflow)
10
+ private readonly workflowRepository: Repository<Workflow>,
11
+ ) {}
12
+
13
+ // async getWorkflowById(id: number) {
14
+ // return this.workflowRepository.findOne(id);
15
+ // }
16
+
17
+ async getAllWorkflowsByFilters(
18
+ entity_type: string,
19
+ level_id: string,
20
+ level_type: string,
21
+ ): Promise<Workflow[]> {
22
+ return this.workflowRepository.find({
23
+ where: {
24
+ mapped_entity_type: entity_type,
25
+ level_id,
26
+ level_type,
27
+ },
28
+ });
29
+ }
30
+
31
+ async deleteWorkflowById(id: number) {
32
+ const result = await this.workflowRepository.delete(id);
33
+
34
+ if (result.affected === 0) {
35
+ throw new NotFoundException(`Workflow with ID ${id} not found`);
36
+ }
37
+
38
+ return {
39
+ message: `Workflow has been successfully deleted.`,
40
+ };
41
+ }
42
+ }
@@ -1,5 +1,30 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
  import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
3
+ import { UserData } from 'src/module/user/entity/user.entity';
4
+ import { DataSource } from 'typeorm';
3
5
 
4
6
  @Injectable()
5
- export class ActionCategoryService extends EntityServiceImpl {}
7
+ export class ActionCategoryService extends EntityServiceImpl {
8
+ constructor(private readonly dataSource: DataSource) {
9
+ super();
10
+ }
11
+
12
+ async getActionsCat(loggedInUser: UserData, entity_type: string) {
13
+ const { organization_id } = loggedInUser;
14
+
15
+ const result = await this.dataSource.query(
16
+ `
17
+ SELECT id, name
18
+ FROM cr_wf_action_category
19
+ WHERE mapped_entity_type = ?
20
+ AND organization_id = ?
21
+ `,
22
+ [entity_type, organization_id],
23
+ );
24
+
25
+ return result.map((row: any) => ({
26
+ label: row.name,
27
+ value: row.id,
28
+ }));
29
+ }
30
+ }