rez_core 2.1.153 → 2.1.156

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 (63) hide show
  1. package/dist/module/workflow/controller/action.controller.d.ts +12 -0
  2. package/dist/module/workflow/controller/action.controller.js +16 -0
  3. package/dist/module/workflow/controller/action.controller.js.map +1 -1
  4. package/dist/module/workflow/controller/task.controller.d.ts +8 -0
  5. package/dist/module/workflow/controller/task.controller.js +14 -1
  6. package/dist/module/workflow/controller/task.controller.js.map +1 -1
  7. package/dist/module/workflow/entity/action-data.entity.d.ts +3 -0
  8. package/dist/module/workflow/entity/action-data.entity.js +12 -0
  9. package/dist/module/workflow/entity/action-data.entity.js.map +1 -1
  10. package/dist/module/workflow/entity/task-data.entity.d.ts +12 -4
  11. package/dist/module/workflow/entity/task-data.entity.js +37 -5
  12. package/dist/module/workflow/entity/task-data.entity.js.map +1 -1
  13. package/dist/module/workflow/repository/action-data.repository.d.ts +10 -0
  14. package/dist/module/workflow/repository/action-data.repository.js +85 -0
  15. package/dist/module/workflow/repository/action-data.repository.js.map +1 -0
  16. package/dist/module/workflow/repository/action.repository.d.ts +17 -0
  17. package/dist/module/workflow/repository/action.repository.js +93 -0
  18. package/dist/module/workflow/repository/action.repository.js.map +1 -0
  19. package/dist/module/workflow/repository/comm-template.repository.d.ts +1 -1
  20. package/dist/module/workflow/repository/comm-template.repository.js +16 -11
  21. package/dist/module/workflow/repository/comm-template.repository.js.map +1 -1
  22. package/dist/module/workflow/repository/stage-movement.repository.d.ts +1 -1
  23. package/dist/module/workflow/repository/stage-movement.repository.js +5 -1
  24. package/dist/module/workflow/repository/stage-movement.repository.js.map +1 -1
  25. package/dist/module/workflow/repository/task.repository.d.ts +6 -3
  26. package/dist/module/workflow/repository/task.repository.js +40 -2
  27. package/dist/module/workflow/repository/task.repository.js.map +1 -1
  28. package/dist/module/workflow/service/action-data.service.d.ts +11 -0
  29. package/dist/module/workflow/service/action-data.service.js +36 -0
  30. package/dist/module/workflow/service/action-data.service.js.map +1 -0
  31. package/dist/module/workflow/service/action.service.d.ts +13 -1
  32. package/dist/module/workflow/service/action.service.js +9 -2
  33. package/dist/module/workflow/service/action.service.js.map +1 -1
  34. package/dist/module/workflow/service/comm-template.service.js +1 -1
  35. package/dist/module/workflow/service/comm-template.service.js.map +1 -1
  36. package/dist/module/workflow/service/task.service.d.ts +11 -1
  37. package/dist/module/workflow/service/task.service.js +29 -2
  38. package/dist/module/workflow/service/task.service.js.map +1 -1
  39. package/dist/module/workflow/service/workflow-meta.service.d.ts +6 -2
  40. package/dist/module/workflow/service/workflow-meta.service.js +14 -6
  41. package/dist/module/workflow/service/workflow-meta.service.js.map +1 -1
  42. package/dist/module/workflow/service/workflow.service.js +19 -6
  43. package/dist/module/workflow/service/workflow.service.js.map +1 -1
  44. package/dist/module/workflow/workflow.module.js +6 -0
  45. package/dist/module/workflow/workflow.module.js.map +1 -1
  46. package/dist/tsconfig.build.tsbuildinfo +1 -1
  47. package/package.json +1 -1
  48. package/src/module/workflow/controller/action.controller.ts +18 -0
  49. package/src/module/workflow/controller/task.controller.ts +17 -1
  50. package/src/module/workflow/entity/action-data.entity.ts +9 -0
  51. package/src/module/workflow/entity/task-data.entity.ts +29 -5
  52. package/src/module/workflow/repository/action-data.repository.ts +93 -0
  53. package/src/module/workflow/repository/action.repository.ts +99 -0
  54. package/src/module/workflow/repository/comm-template.repository.ts +25 -17
  55. package/src/module/workflow/repository/stage-movement.repository.ts +7 -3
  56. package/src/module/workflow/repository/task.repository.ts +68 -5
  57. package/src/module/workflow/service/action-data.service.ts +45 -0
  58. package/src/module/workflow/service/action.service.ts +21 -2
  59. package/src/module/workflow/service/comm-template.service.ts +1 -1
  60. package/src/module/workflow/service/task.service.ts +71 -1
  61. package/src/module/workflow/service/workflow-meta.service.ts +40 -34
  62. package/src/module/workflow/service/workflow.service.ts +33 -7
  63. package/src/module/workflow/workflow.module.ts +6 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.1.153",
3
+ "version": "2.1.156",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -52,4 +52,22 @@ export class ActionController {
52
52
  const result = this.actionService.getActions(loggedInUser, stage_id);
53
53
  return result;
54
54
  }
55
+
56
+ @Post('/getaction')
57
+ @HttpCode(HttpStatus.OK)
58
+ async getAction(
59
+ @Req() req: Request & { user: any },
60
+ @Body('stage_id') stage_id: number,
61
+ @Body('mapped_entity_id') mapped_entity_id: number,
62
+ @Body('mapped_entity_type') mapped_entity_type: string,
63
+ ) {
64
+ const loggedInUser = req.user.userData;
65
+ const result = this.actionService.getAction(
66
+ loggedInUser,
67
+ stage_id,
68
+ mapped_entity_id,
69
+ mapped_entity_type,
70
+ );
71
+ return result;
72
+ }
55
73
  }
@@ -19,7 +19,7 @@ export class TaskController {
19
19
  private readonly taskService: TaskService,
20
20
  ) {}
21
21
 
22
- @Post('/getTasksbyUserAndStage')
22
+ @Post('/by-user-and-stage')
23
23
  @HttpCode(HttpStatus.OK)
24
24
  async getTasksbyUserAndStage(
25
25
  @Req() req: Request & { user: any },
@@ -37,4 +37,20 @@ export class TaskController {
37
37
  );
38
38
  return result;
39
39
  }
40
+
41
+ @Post('/move-task')
42
+ async moveTask(
43
+ @Req() req: Request & { user: any },
44
+ @Body()
45
+ body: {
46
+ mapped_entity_type: string;
47
+ mapped_entity_id: number;
48
+ stage_id: number;
49
+ action_id: number;
50
+ },
51
+ ) {
52
+ const loggedInUser = req.user.userData;
53
+ const result = this.taskService.moveTask(loggedInUser, body);
54
+ return result;
55
+ }
40
56
  }
@@ -31,4 +31,13 @@ export class ActionDataEntity extends BaseEntity {
31
31
 
32
32
  @Column({ nullable: true })
33
33
  mapped_entity_type: string;
34
+
35
+ @Column({ nullable: true })
36
+ sequence: number;
37
+
38
+ @Column({ default: 0 })
39
+ is_done: boolean;
40
+
41
+ @Column({ type: 'varchar', nullable: true })
42
+ is_current: string;
34
43
  }
@@ -5,20 +5,20 @@ import { Column, Entity } from 'typeorm';
5
5
  export class TaskDataEntity extends BaseEntity {
6
6
  constructor() {
7
7
  super();
8
- this.entity_type = 'TASK_DATA';
8
+ this.entity_type = 'TASK';
9
9
  }
10
10
 
11
11
  @Column({ nullable: true })
12
- task_id: number;
12
+ task_id: string;
13
13
 
14
14
  @Column({ nullable: true })
15
- user_id: number;
15
+ user_id: string;
16
16
 
17
17
  @Column({ nullable: true })
18
- stage_id: number;
18
+ stage_id: string;
19
19
 
20
20
  @Column({ nullable: true })
21
- action_id: number;
21
+ action_id: string;
22
22
 
23
23
  @Column({ nullable: true })
24
24
  start_time: Date;
@@ -40,4 +40,28 @@ export class TaskDataEntity extends BaseEntity {
40
40
 
41
41
  @Column({ nullable: true })
42
42
  mapped_entity_type: string;
43
+
44
+ @Column({ nullable: true })
45
+ sequence: number;
46
+
47
+ @Column({ default: 0 })
48
+ is_done: boolean;
49
+
50
+ @Column({ nullable: true })
51
+ task_status: string;
52
+
53
+ @Column({ nullable: true })
54
+ task_name: string;
55
+
56
+ @Column({ nullable: true, type: 'varchar', length: 1000 })
57
+ description: string;
58
+
59
+ @Column({ nullable: true })
60
+ task_owner: string;
61
+
62
+ @Column({ nullable: true, type: 'varchar' })
63
+ due_date: Date;
64
+
65
+ @Column({ nullable: true, type: 'varchar' })
66
+ due_time: string;
43
67
  }
@@ -0,0 +1,93 @@
1
+ import { BadRequestException, Injectable } from '@nestjs/common';
2
+ import { InjectRepository } from '@nestjs/typeorm';
3
+ import { ActionDataEntity } from '../entity/action-data.entity';
4
+ import { DataSource, Repository } from 'typeorm';
5
+ import { UserData } from 'src/module/user/entity/user.entity';
6
+
7
+ @Injectable()
8
+ export class ActionDataRepository {
9
+ constructor(
10
+ @InjectRepository(ActionDataEntity)
11
+ private readonly actionDataRepo: Repository<ActionDataEntity>,
12
+ private readonly dataSource: DataSource,
13
+ ) {}
14
+
15
+ async saveActionData(
16
+ action: any,
17
+ loggedInUser: UserData,
18
+ mapped_entity_id,
19
+ mapped_entity_type,
20
+ ): Promise<any> {
21
+ if (!action?.length) return;
22
+
23
+ // Find the action with the lowest sequence
24
+ const minSequence = Math.min(...action.map((a) => a.sequence));
25
+
26
+ if (action.length > 0) {
27
+ for (const act of action) {
28
+ const isFirst = act.sequence == minSequence;
29
+ const actionData = this.actionDataRepo.create({
30
+ stage_id: act.stage_id,
31
+ user_id: loggedInUser.id,
32
+ action_id: act.id,
33
+ sequence: act.sequence,
34
+ mapped_entity_id,
35
+ mapped_entity_type,
36
+ is_current: isFirst ? 'Y' : null,
37
+ start_time: isFirst ? new Date() : null,
38
+ } as ActionDataEntity);
39
+ await this.actionDataRepo.save(actionData);
40
+ }
41
+ }
42
+ }
43
+
44
+ async updateActionStatus(
45
+ loggedInUser: UserData,
46
+ mapped_entity_type: string,
47
+ mapped_entity_id: number,
48
+ stage_id: number,
49
+ action_id: number,
50
+ ): Promise<any> {
51
+ const actionData = await this.actionDataRepo.findOne({
52
+ where: {
53
+ mapped_entity_type,
54
+ mapped_entity_id,
55
+ stage_id,
56
+ action_id,
57
+ },
58
+ });
59
+
60
+ if (!actionData) return;
61
+
62
+ actionData.end_time = new Date();
63
+ actionData.modified_by = loggedInUser.id;
64
+ actionData.modified_date = new Date();
65
+ actionData.is_done = true;
66
+ actionData.is_current = 'N'; // Mark as not current
67
+
68
+ // Save the updated action
69
+ await this.actionDataRepo.update(actionData.id, actionData);
70
+
71
+ // NOW, ACTIVATE THE NEXT ACTION (moveNextActionData logic here)
72
+ // Find next sequence action for the same entity/stage
73
+ const allActionData = await this.actionDataRepo.find({
74
+ where: { mapped_entity_type, mapped_entity_id, stage_id },
75
+ order: { sequence: 'ASC' },
76
+ });
77
+
78
+ // Find the action with the next higher sequence number
79
+ const nextAction = allActionData.find(
80
+ (a) => a.sequence > actionData.sequence,
81
+ );
82
+ if (nextAction && nextAction.is_current !== 'Y') {
83
+ nextAction.is_current = 'Y';
84
+ nextAction.start_time = new Date();
85
+ nextAction.modified_by = loggedInUser.id;
86
+ nextAction.modified_date = new Date();
87
+ await this.actionDataRepo.update(nextAction.id, nextAction);
88
+ }
89
+
90
+ // Optionally return both for audit
91
+ return { finished: actionData, activated: nextAction ?? null };
92
+ }
93
+ }
@@ -0,0 +1,99 @@
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
+ return enrichedResult;
98
+ }
99
+ }
@@ -46,18 +46,15 @@ export class CommTemplateRepository {
46
46
 
47
47
  async getTemplateByCode(
48
48
  entity_type: string,
49
- code: string,
49
+ id: number,
50
50
  loggedInUser,
51
51
  ): Promise<any | null> {
52
52
  const template = await this.commTemplateRepository.findOne({
53
- where: {
54
- entity_type,
55
- code,
56
- },
53
+ where: { entity_type, id },
57
54
  });
58
55
 
59
56
  if (!template) {
60
- throw new NotFoundException(`Template with code ${code} not found`);
57
+ throw new NotFoundException(`Template with id ${id} not found`);
61
58
  }
62
59
 
63
60
  if (template.format_type === 'markup') {
@@ -65,30 +62,41 @@ export class CommTemplateRepository {
65
62
  template.markup_id,
66
63
  loggedInUser,
67
64
  );
68
-
69
- console.log(media);
65
+ template.markup_id = media as any;
70
66
  }
71
67
 
72
68
  if (template.format_type === 'richtext') {
73
69
  return template;
74
70
  }
75
71
 
76
- // Get only attachment IDs
72
+ // Get attachments for this template
77
73
  const attachments = await this.templateAttachEntity.find({
78
74
  select: ['media_id'],
79
75
  where: {
80
- entity_type: entity_type,
76
+ entity_type,
81
77
  template_id: template.id,
82
78
  },
83
79
  });
84
80
 
85
- const media = await this.mediaDataService.getMediaDownloadUrl(
86
- 1,
87
- loggedInUser,
88
- );
89
-
90
- console.log(media);
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
+ }
91
95
 
92
- return { ...template, attachments: attachments.map((att) => att.media_id) };
96
+ // Return template with attachments array
97
+ return {
98
+ ...template,
99
+ attachments: attachmentsMedia, // [] or array of media JSONs
100
+ };
93
101
  }
94
102
  }
@@ -180,11 +180,15 @@ export class StageMovementRepository {
180
180
  return nextStageGroupFirstStage || null;
181
181
  }
182
182
 
183
- async getAllActionByStageId(stageId: number): Promise<any[]> {
184
- return this.dataSource.query(
185
- `SELECT * FROM cr_wf_stage_action_mapping WHERE stage_id = ?`,
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 = ?`,
186
189
  [stageId],
187
190
  );
191
+ return result;
188
192
  }
189
193
 
190
194
  async saveActionData(action: any, loggedInUser: UserData): Promise<any> {
@@ -1,20 +1,21 @@
1
1
  import { BadRequestException, Injectable } from '@nestjs/common';
2
2
  import { InjectRepository } from '@nestjs/typeorm';
3
3
  import { TaskDataEntity } from '../entity/task-data.entity';
4
- import { Repository } from 'typeorm';
4
+ import { DataSource, Repository } from 'typeorm';
5
5
 
6
6
  @Injectable()
7
7
  export class TaskRepository {
8
8
  constructor(
9
9
  @InjectRepository(TaskDataEntity)
10
10
  private readonly TaskRepository: Repository<TaskDataEntity>,
11
+ private readonly dataSource: DataSource,
11
12
  ) {}
12
13
 
13
14
  async getAllTaskByUserIdAndStageId(
14
- userId: number,
15
- stageId: number,
16
- mapped_entity_type: string,
17
- mapped_entity_id: number,
15
+ userId,
16
+ stageId,
17
+ mapped_entity_type,
18
+ mapped_entity_id,
18
19
  ) {
19
20
  const result = await this.TaskRepository.find({
20
21
  where: {
@@ -27,4 +28,66 @@ export class TaskRepository {
27
28
 
28
29
  return result;
29
30
  }
31
+
32
+ async saveActionDataInTask(
33
+ action: any,
34
+ loggedInUser,
35
+ mapped_entity_id: number,
36
+ mapped_entity_type: string,
37
+ ): Promise<any> {
38
+ if (!action?.length) return;
39
+
40
+ const todoListMasterItemId = await this.dataSource.query(
41
+ `SELECT id FROM cr_list_master_items WHERE code = 'todo' and organization_id = ? and listtype = 'TKST' LIMIT 1;`,
42
+ [loggedInUser.organization_id],
43
+ );
44
+
45
+ // Find the action with the lowest sequence
46
+
47
+ if (action.length > 0) {
48
+ for (const act of action) {
49
+ const taskData = this.TaskRepository.create({
50
+ stage_id: act.stage_id,
51
+ user_id: loggedInUser.id,
52
+ action_id: act.id,
53
+ sequence: act.sequence,
54
+ mapped_entity_id,
55
+ mapped_entity_type,
56
+ is_system: true,
57
+ task_status: todoListMasterItemId[0]?.id,
58
+ } as TaskDataEntity);
59
+ await this.TaskRepository.save(taskData);
60
+ }
61
+ }
62
+ }
63
+
64
+ // update task status
65
+ async updateTaskStatus(
66
+ loggedInUser,
67
+ mapped_entity_type,
68
+ mapped_entity_id,
69
+ stage_id,
70
+ action_id,
71
+ ): Promise<any> {
72
+ const task = await this.TaskRepository.findOneBy({
73
+ action_id,
74
+ mapped_entity_type,
75
+ mapped_entity_id,
76
+ stage_id,
77
+ });
78
+
79
+ if (!task) return;
80
+
81
+ const completedListMasterItemId = await this.dataSource.query(
82
+ `SELECT id FROM cr_list_master_items WHERE code = 'completed' and organization_id = ? and listtype = 'TKST' LIMIT 1;`,
83
+ [loggedInUser.organization_id],
84
+ );
85
+
86
+ task.modified_by = loggedInUser.id;
87
+ task.modified_date = new Date();
88
+ task.is_done = true;
89
+ task.task_status = completedListMasterItemId[0]?.id;
90
+
91
+ await this.TaskRepository.update(task.id, task);
92
+ }
30
93
  }
@@ -0,0 +1,45 @@
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 { DataSource } from 'typeorm';
5
+ import { ActionDataRepository } from '../repository/action-data.repository';
6
+
7
+ @Injectable()
8
+ export class ActionDataService extends EntityServiceImpl {
9
+ constructor(
10
+ private readonly dataSource: DataSource,
11
+ private readonly actionDataRepo: ActionDataRepository,
12
+ ) {
13
+ super();
14
+ }
15
+
16
+ async saveActionData(
17
+ action: any,
18
+ loggedInUser: UserData,
19
+ mapped_entity_id,
20
+ mapped_entity_type,
21
+ ): Promise<any> {
22
+ return this.actionDataRepo.saveActionData(
23
+ action,
24
+ loggedInUser,
25
+ mapped_entity_id,
26
+ mapped_entity_type,
27
+ );
28
+ }
29
+
30
+ async updateActionStatus(
31
+ loggedInUser: UserData,
32
+ mapped_entity_type: string,
33
+ mapped_entity_id: number,
34
+ stage_id: number,
35
+ action_id: number,
36
+ ): Promise<any> {
37
+ return this.actionDataRepo.updateActionStatus(
38
+ loggedInUser,
39
+ mapped_entity_type,
40
+ mapped_entity_id,
41
+ stage_id,
42
+ action_id,
43
+ );
44
+ }
45
+ }
@@ -2,12 +2,16 @@ import { BadRequestException, Injectable } from '@nestjs/common';
2
2
  import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
3
3
  import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
4
4
  import { UserData } from 'src/module/user/entity/user.entity';
5
- import { DataSource, EntityManager } from 'typeorm';
5
+ import { DataSource, EntityManager, Repository } from 'typeorm';
6
+ import { ActionRepository } from '../repository/action.repository';
6
7
  import { ActionEntity } from '../entity/action.entity';
7
8
 
8
9
  @Injectable()
9
10
  export class ActionService extends EntityServiceImpl {
10
- constructor(private readonly dataSource: DataSource) {
11
+ constructor(
12
+ private readonly dataSource: DataSource,
13
+ private readonly actionRepository: ActionRepository,
14
+ ) {
11
15
  super();
12
16
  }
13
17
 
@@ -318,4 +322,19 @@ export class ActionService extends EntityServiceImpl {
318
322
 
319
323
  return enrichedResult;
320
324
  }
325
+
326
+ async getAction(
327
+ loggedInUser: UserData,
328
+ stage_id: number,
329
+ mapped_entity_id: number,
330
+ mapped_entity_type: string,
331
+ ) {
332
+ const { organization_id } = loggedInUser;
333
+ return this.actionRepository.getAction(
334
+ organization_id,
335
+ stage_id,
336
+ mapped_entity_id,
337
+ mapped_entity_type,
338
+ );
339
+ }
321
340
  }
@@ -70,7 +70,7 @@ export class CommTemplateService extends EntityServiceImpl {
70
70
 
71
71
  const getTemplate = await this.commTemplateRepository.getTemplateByCode(
72
72
  entityType,
73
- id.toString(),
73
+ id,
74
74
  loggedInUser,
75
75
  );
76
76
 
@@ -2,10 +2,14 @@ import { Injectable } from '@nestjs/common';
2
2
  import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
3
3
  import { UserData } from 'src/module/user/entity/user.entity';
4
4
  import { TaskRepository } from '../repository/task.repository';
5
+ import { ActionDataService } from './action-data.service';
5
6
 
6
7
  @Injectable()
7
8
  export class TaskService extends EntityServiceImpl {
8
- constructor(private readonly taskRepository: TaskRepository) {
9
+ constructor(
10
+ private readonly taskRepository: TaskRepository,
11
+ private readonly actionDataService: ActionDataService,
12
+ ) {
9
13
  super();
10
14
  }
11
15
 
@@ -20,6 +24,72 @@ export class TaskService extends EntityServiceImpl {
20
24
  data.mapped_entity_id,
21
25
  );
22
26
 
27
+ const grouped: { mandatory: any[]; non_mandatory: any[] } = {
28
+ mandatory: [],
29
+ non_mandatory: [],
30
+ };
31
+
32
+ for (const task of taskData) {
33
+ if (task && task.is_mandatory) {
34
+ grouped.mandatory.push(task);
35
+ } else {
36
+ grouped.non_mandatory.push(task);
37
+ }
38
+ }
39
+
40
+ return grouped;
41
+ }
42
+
43
+ async getEntityData(entityType: string, id: number, loggedInUser: any) {
44
+ const taskData = await super.getEntityData(entityType, id, loggedInUser);
45
+
23
46
  return taskData;
24
47
  }
48
+
49
+ async saveActionData(
50
+ action: any,
51
+ loggedInUser: UserData,
52
+ mapped_entity_id: number,
53
+ mapped_entity_type: string,
54
+ ): Promise<any> {
55
+ await this.taskRepository.saveActionDataInTask(
56
+ action,
57
+ loggedInUser,
58
+ mapped_entity_id,
59
+ mapped_entity_type,
60
+ );
61
+ }
62
+
63
+ async moveTask(
64
+ loggedInUser: UserData,
65
+ body: {
66
+ mapped_entity_type: string;
67
+ mapped_entity_id: number;
68
+ stage_id: number;
69
+ action_id: number;
70
+ },
71
+ ): Promise<any> {
72
+ // Logic to move task based on the provided body parameters
73
+ // This could involve updating the task's stage, action, etc.
74
+
75
+ // update task status
76
+ this.taskRepository.updateTaskStatus(
77
+ loggedInUser,
78
+ body.mapped_entity_type,
79
+ body.mapped_entity_id,
80
+ body.stage_id,
81
+ body.action_id,
82
+ );
83
+
84
+ // update action status
85
+ await this.actionDataService.updateActionStatus(
86
+ loggedInUser,
87
+ body.mapped_entity_type,
88
+ body.mapped_entity_id,
89
+ body.stage_id,
90
+ body.action_id,
91
+ );
92
+
93
+ return 'Task moved successfully';
94
+ }
25
95
  }