rez_core 2.1.154 → 2.1.157
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/filter/service/filter.service.js +2 -1
- package/dist/module/filter/service/filter.service.js.map +1 -1
- package/dist/module/workflow/controller/action.controller.d.ts +12 -0
- package/dist/module/workflow/controller/action.controller.js +17 -1
- package/dist/module/workflow/controller/action.controller.js.map +1 -1
- package/dist/module/workflow/controller/task.controller.d.ts +9 -0
- package/dist/module/workflow/controller/task.controller.js +14 -1
- package/dist/module/workflow/controller/task.controller.js.map +1 -1
- package/dist/module/workflow/repository/action-data.repository.d.ts +10 -0
- package/dist/module/workflow/repository/action-data.repository.js +85 -0
- package/dist/module/workflow/repository/action-data.repository.js.map +1 -0
- package/dist/module/workflow/repository/action.repository.d.ts +17 -0
- package/dist/module/workflow/repository/action.repository.js +97 -0
- package/dist/module/workflow/repository/action.repository.js.map +1 -0
- package/dist/module/workflow/repository/comm-template.repository.d.ts +1 -1
- package/dist/module/workflow/repository/comm-template.repository.js +16 -11
- package/dist/module/workflow/repository/comm-template.repository.js.map +1 -1
- package/dist/module/workflow/repository/stage-movement.repository.d.ts +1 -1
- package/dist/module/workflow/repository/stage-movement.repository.js +5 -1
- package/dist/module/workflow/repository/stage-movement.repository.js.map +1 -1
- package/dist/module/workflow/repository/task.repository.d.ts +6 -3
- package/dist/module/workflow/repository/task.repository.js +42 -7
- package/dist/module/workflow/repository/task.repository.js.map +1 -1
- package/dist/module/workflow/service/action-data.service.d.ts +11 -0
- package/dist/module/workflow/service/action-data.service.js +36 -0
- package/dist/module/workflow/service/action-data.service.js.map +1 -0
- package/dist/module/workflow/service/action.service.d.ts +13 -1
- package/dist/module/workflow/service/action.service.js +12 -6
- package/dist/module/workflow/service/action.service.js.map +1 -1
- package/dist/module/workflow/service/comm-template.service.js +1 -1
- package/dist/module/workflow/service/comm-template.service.js.map +1 -1
- package/dist/module/workflow/service/task.service.d.ts +11 -1
- package/dist/module/workflow/service/task.service.js +35 -3
- package/dist/module/workflow/service/task.service.js.map +1 -1
- package/dist/module/workflow/service/workflow-meta.service.d.ts +6 -2
- package/dist/module/workflow/service/workflow-meta.service.js +14 -6
- package/dist/module/workflow/service/workflow-meta.service.js.map +1 -1
- package/dist/module/workflow/workflow.module.js +6 -0
- package/dist/module/workflow/workflow.module.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/filter/service/filter.service.ts +4 -2
- package/src/module/workflow/controller/action.controller.ts +19 -1
- package/src/module/workflow/controller/task.controller.ts +20 -3
- package/src/module/workflow/repository/action-data.repository.ts +93 -0
- package/src/module/workflow/repository/action.repository.ts +104 -0
- package/src/module/workflow/repository/comm-template.repository.ts +25 -17
- package/src/module/workflow/repository/stage-movement.repository.ts +7 -3
- package/src/module/workflow/repository/task.repository.ts +66 -11
- package/src/module/workflow/service/action-data.service.ts +45 -0
- package/src/module/workflow/service/action.service.ts +30 -11
- package/src/module/workflow/service/comm-template.service.ts +1 -1
- package/src/module/workflow/service/task.service.ts +77 -7
- package/src/module/workflow/service/workflow-meta.service.ts +40 -34
- package/src/module/workflow/workflow.module.ts +6 -0
package/package.json
CHANGED
|
@@ -196,10 +196,12 @@ export class FilterService {
|
|
|
196
196
|
const layoutPreference = await this.dataSource.query(
|
|
197
197
|
`SELECT layout_json
|
|
198
198
|
FROM cr_layout_preference
|
|
199
|
-
WHERE user_id = ? AND mapped_entity_type = ?`,
|
|
200
|
-
[user_id, entity_type],
|
|
199
|
+
WHERE user_id = ? AND mapped_entity_type = ? AND mapped_level_id = ? AND mapped_level_type = ?`,
|
|
200
|
+
[user_id, entity_type, level_id, level_type],
|
|
201
201
|
);
|
|
202
202
|
|
|
203
|
+
console.log('found layoutPreference', layoutPreference);
|
|
204
|
+
|
|
203
205
|
// Extract layout preference
|
|
204
206
|
const layout = layoutPreference?.[0]?.layout_json?.quick_tab || {};
|
|
205
207
|
|
|
@@ -42,7 +42,7 @@ export class ActionController {
|
|
|
42
42
|
return result;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
@Post('/
|
|
45
|
+
@Post('/getactions')
|
|
46
46
|
@HttpCode(HttpStatus.OK)
|
|
47
47
|
async getActions(
|
|
48
48
|
@Req() req: Request & { user: any },
|
|
@@ -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,15 +19,16 @@ export class TaskController {
|
|
|
19
19
|
private readonly taskService: TaskService,
|
|
20
20
|
) {}
|
|
21
21
|
|
|
22
|
-
@Post('/
|
|
22
|
+
@Post('/by-user-and-stage')
|
|
23
23
|
@HttpCode(HttpStatus.OK)
|
|
24
24
|
async getTasksbyUserAndStage(
|
|
25
25
|
@Req() req: Request & { user: any },
|
|
26
26
|
@Body()
|
|
27
27
|
body: {
|
|
28
|
-
mapped_entity_type: string;
|
|
29
|
-
mapped_entity_id: number;
|
|
30
28
|
stage_id: number;
|
|
29
|
+
mapped_entity_type?: string;
|
|
30
|
+
mapped_entity_id?: number;
|
|
31
|
+
user_id?: number;
|
|
31
32
|
},
|
|
32
33
|
) {
|
|
33
34
|
const loggedInUser = req.user.userData;
|
|
@@ -37,4 +38,20 @@ export class TaskController {
|
|
|
37
38
|
);
|
|
38
39
|
return result;
|
|
39
40
|
}
|
|
41
|
+
|
|
42
|
+
@Post('/move-task')
|
|
43
|
+
async moveTask(
|
|
44
|
+
@Req() req: Request & { user: any },
|
|
45
|
+
@Body()
|
|
46
|
+
body: {
|
|
47
|
+
mapped_entity_type: string;
|
|
48
|
+
mapped_entity_id: number;
|
|
49
|
+
stage_id: number;
|
|
50
|
+
action_id: number;
|
|
51
|
+
},
|
|
52
|
+
) {
|
|
53
|
+
const loggedInUser = req.user.userData;
|
|
54
|
+
const result = this.taskService.moveTask(loggedInUser, body);
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
40
57
|
}
|
|
@@ -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,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
|
+
}
|
|
@@ -46,18 +46,15 @@ export class CommTemplateRepository {
|
|
|
46
46
|
|
|
47
47
|
async getTemplateByCode(
|
|
48
48
|
entity_type: string,
|
|
49
|
-
|
|
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
|
|
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
|
|
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
|
|
76
|
+
entity_type,
|
|
81
77
|
template_id: template.id,
|
|
82
78
|
},
|
|
83
79
|
});
|
|
84
80
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
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
|
-
|
|
185
|
-
`SELECT
|
|
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,30 +1,85 @@
|
|
|
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
|
-
async getAllTaskByUserIdAndStageId(
|
|
14
|
-
userId,
|
|
15
|
-
stageId,
|
|
16
|
-
mapped_entity_type,
|
|
17
|
-
mapped_entity_id,
|
|
18
|
-
) {
|
|
14
|
+
async getAllTaskByUserIdAndStageId(condition) {
|
|
19
15
|
const result = await this.TaskRepository.find({
|
|
20
16
|
where: {
|
|
21
|
-
|
|
22
|
-
stage_id: stageId,
|
|
23
|
-
mapped_entity_type,
|
|
24
|
-
mapped_entity_id,
|
|
17
|
+
...condition,
|
|
25
18
|
},
|
|
26
19
|
});
|
|
27
20
|
|
|
28
21
|
return result;
|
|
29
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
|
+
}
|
|
30
85
|
}
|
|
@@ -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(
|
|
11
|
+
constructor(
|
|
12
|
+
private readonly dataSource: DataSource,
|
|
13
|
+
private readonly actionRepository: ActionRepository,
|
|
14
|
+
) {
|
|
11
15
|
super();
|
|
12
16
|
}
|
|
13
17
|
|
|
@@ -60,6 +64,7 @@ export class ActionService extends EntityServiceImpl {
|
|
|
60
64
|
appcode,
|
|
61
65
|
);
|
|
62
66
|
|
|
67
|
+
// template mapping
|
|
63
68
|
if (Array.isArray(actionData.template) && actionData.template.length > 0) {
|
|
64
69
|
const templates = actionData.template;
|
|
65
70
|
|
|
@@ -98,7 +103,7 @@ export class ActionService extends EntityServiceImpl {
|
|
|
98
103
|
};
|
|
99
104
|
|
|
100
105
|
// Pass only actionData (without template) to super.updateEntity
|
|
101
|
-
let action = await super.updateEntity(actionData, loggedInUser);
|
|
106
|
+
let action = await super.updateEntity({ ...actionData }, loggedInUser);
|
|
102
107
|
|
|
103
108
|
if (!action) {
|
|
104
109
|
throw new Error('Action not found or could not be updated');
|
|
@@ -122,17 +127,17 @@ export class ActionService extends EntityServiceImpl {
|
|
|
122
127
|
loggedInUser,
|
|
123
128
|
);
|
|
124
129
|
|
|
130
|
+
// delete existing template mappings for this action
|
|
131
|
+
await this.dataSource.query(
|
|
132
|
+
`DELETE FROM cr_wf_action_template_mapping WHERE stg_act_mapping_id = ?`,
|
|
133
|
+
[stageActionMappingData.id],
|
|
134
|
+
);
|
|
135
|
+
|
|
125
136
|
// Handle template mapping (using the extracted template)
|
|
126
137
|
if (Array.isArray(template) && template.length > 0) {
|
|
127
138
|
for (let i = 0; i < template.length; i++) {
|
|
128
139
|
const templateCode = template[i];
|
|
129
140
|
|
|
130
|
-
// delete existing template mappings for this action
|
|
131
|
-
await this.dataSource.query(
|
|
132
|
-
`DELETE FROM cr_wf_action_template_mapping WHERE stg_act_mapping_id = ? AND template_code = ?`,
|
|
133
|
-
[stageActionMappingData.id, templateCode],
|
|
134
|
-
);
|
|
135
|
-
|
|
136
141
|
// Create Action-Template Mapping
|
|
137
142
|
const actionTemplateMapping = {
|
|
138
143
|
stg_act_mapping_id: stageActionMappingData.id,
|
|
@@ -287,8 +292,7 @@ export class ActionService extends EntityServiceImpl {
|
|
|
287
292
|
const actionResults = await this.dataSource
|
|
288
293
|
.createQueryBuilder()
|
|
289
294
|
.select([
|
|
290
|
-
'a
|
|
291
|
-
'a.name AS name',
|
|
295
|
+
'a.*',
|
|
292
296
|
'ac.name AS action_category',
|
|
293
297
|
'ar.name AS action_requirement',
|
|
294
298
|
])
|
|
@@ -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
|
}
|