rez_core 2.2.147 → 2.2.149
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/.vscode/extensions.json +5 -0
- package/dist/module/layout_preference/controller/layout_preference.controller.d.ts +3 -1
- package/dist/module/layout_preference/service/layout_preference.service.d.ts +3 -1
- package/dist/module/layout_preference/service/layout_preference.service.js +6 -1
- package/dist/module/layout_preference/service/layout_preference.service.js.map +1 -1
- package/dist/module/meta/controller/view-master.controller.d.ts +3 -1
- package/dist/module/meta/controller/view-master.controller.js +4 -2
- package/dist/module/meta/controller/view-master.controller.js.map +1 -1
- package/dist/module/workflow/entity/action.entity.d.ts +1 -0
- package/dist/module/workflow/entity/action.entity.js +4 -0
- package/dist/module/workflow/entity/action.entity.js.map +1 -1
- package/dist/module/workflow/repository/stage-movement.repository.js +1 -1
- package/dist/module/workflow/service/workflow-meta.service.d.ts +1 -0
- package/dist/module/workflow/service/workflow-meta.service.js +72 -0
- package/dist/module/workflow/service/workflow-meta.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/layout_preference/service/layout_preference.service.ts +10 -6
- package/src/module/meta/controller/view-master.controller.ts +4 -0
- package/src/module/workflow/entity/action.entity.ts +3 -0
- package/src/module/workflow/repository/stage-movement.repository.ts +1 -1
- package/src/module/workflow/service/workflow-meta.service.ts +113 -0
package/package.json
CHANGED
|
@@ -15,8 +15,7 @@ export class LayoutPreferenceService extends EntityServiceImpl {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
async createEntity(entityData: BaseEntity, loggedInUser: UserData) {
|
|
18
|
-
|
|
19
|
-
const { mapped_entity_type,type } = entityData as any;
|
|
18
|
+
const { mapped_entity_type, type } = entityData as any;
|
|
20
19
|
const userId = loggedInUser?.id;
|
|
21
20
|
|
|
22
21
|
if (userId === undefined) {
|
|
@@ -30,7 +29,7 @@ export class LayoutPreferenceService extends EntityServiceImpl {
|
|
|
30
29
|
loggedInUser.level_id,
|
|
31
30
|
loggedInUser.level_type,
|
|
32
31
|
userId,
|
|
33
|
-
type
|
|
32
|
+
type,
|
|
34
33
|
);
|
|
35
34
|
|
|
36
35
|
console.log(existingLayoutPreference, 'existingLayoutPreference');
|
|
@@ -57,7 +56,7 @@ export class LayoutPreferenceService extends EntityServiceImpl {
|
|
|
57
56
|
mapped_entity_type,
|
|
58
57
|
mapped_level_id,
|
|
59
58
|
mapped_level_type,
|
|
60
|
-
type
|
|
59
|
+
type,
|
|
61
60
|
) {
|
|
62
61
|
const layoutPreference =
|
|
63
62
|
await this.layoutPreferenceRepository.findByEntityUserId(
|
|
@@ -65,10 +64,15 @@ export class LayoutPreferenceService extends EntityServiceImpl {
|
|
|
65
64
|
mapped_level_id,
|
|
66
65
|
mapped_level_type,
|
|
67
66
|
user_id,
|
|
68
|
-
type
|
|
67
|
+
type,
|
|
69
68
|
);
|
|
70
69
|
|
|
71
|
-
|
|
70
|
+
if (layoutPreference) {
|
|
71
|
+
return layoutPreference;
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
mapped_json: {},
|
|
75
|
+
};
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
async getColumnValue(
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { log } from 'console';
|
|
1
2
|
import {
|
|
2
3
|
Controller,
|
|
3
4
|
Get,
|
|
@@ -24,7 +25,10 @@ export class ViewMasterController {
|
|
|
24
25
|
@Query('entity_type') entityType: string,
|
|
25
26
|
@Query('type') type: string,
|
|
26
27
|
@Res() res: Response,
|
|
28
|
+
@Req() req: Request & { user: any },
|
|
27
29
|
) {
|
|
30
|
+
const loggedInUser = req.user.userData;
|
|
31
|
+
|
|
28
32
|
try {
|
|
29
33
|
if (!entityType || !type) {
|
|
30
34
|
return res.status(HttpStatus.BAD_REQUEST).json({
|
|
@@ -189,7 +189,7 @@ export class StageMovementRepository {
|
|
|
189
189
|
ac.code AS action_category_code,
|
|
190
190
|
arm.form_id
|
|
191
191
|
FROM cr_wf_action a
|
|
192
|
-
|
|
192
|
+
LEFT JOIN cr_wf_stage_action_mapping m ON a.id = m.action_id
|
|
193
193
|
LEFT JOIN cr_wf_action_category ac ON a.action_category = ac.id
|
|
194
194
|
LEFT JOIN cr_wf_action_resources_mapping arm ON m.id = arm.stg_act_mapping_id
|
|
195
195
|
WHERE m.stage_id = ?
|
|
@@ -257,6 +257,23 @@ export class WorkflowMetaService extends EntityServiceImpl {
|
|
|
257
257
|
return 'No actions found for this stage.';
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
+
// check whether first action's action_category is owner_assignment and assignment_type is AUTO_ASSIGN
|
|
261
|
+
const firstAction = actions[0];
|
|
262
|
+
let actionCategory = await this.dataSource.query(
|
|
263
|
+
`SELECT code FROM cr_wf_action_category WHERE id = ${Number(firstAction.action_category)}`,
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
let assignmentType = await this.dataSource.query(
|
|
267
|
+
`SELECT value FROM cr_list_master_items WHERE id = ${Number(firstAction.assignment_type)}`,
|
|
268
|
+
);
|
|
269
|
+
if (
|
|
270
|
+
actionCategory[0]?.code === 'OWAS' &&
|
|
271
|
+
assignmentType[0]?.value == 'round_robin'
|
|
272
|
+
) {
|
|
273
|
+
console.log('Auto-assigning owner based on round-robin assignment type');
|
|
274
|
+
await this.assignLead(loggedInUser);
|
|
275
|
+
}
|
|
276
|
+
|
|
260
277
|
// save in action data
|
|
261
278
|
await this.actionDataService.saveActionData(
|
|
262
279
|
actions,
|
|
@@ -272,5 +289,101 @@ export class WorkflowMetaService extends EntityServiceImpl {
|
|
|
272
289
|
mapped_entity_id,
|
|
273
290
|
mapped_entity_type,
|
|
274
291
|
);
|
|
292
|
+
|
|
293
|
+
if (
|
|
294
|
+
actionCategory[0]?.code == 'OWAS' &&
|
|
295
|
+
assignmentType[0]?.value == 'round_robin'
|
|
296
|
+
) {
|
|
297
|
+
console.log('Auto-assigning owner based on round-robin assignment type');
|
|
298
|
+
await this.assignLead(loggedInUser);
|
|
299
|
+
// move task
|
|
300
|
+
await this.taskService.moveTask(loggedInUser, {
|
|
301
|
+
mapped_entity_type,
|
|
302
|
+
mapped_entity_id,
|
|
303
|
+
stage_id,
|
|
304
|
+
action_id: firstAction.id,
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
// if it has only one action then move next stage
|
|
308
|
+
if (actions.length == 1) {
|
|
309
|
+
console.log(
|
|
310
|
+
'Only one action present and it is owner assignment. Moving to next stage.',
|
|
311
|
+
);
|
|
312
|
+
await this.moveToNextStage(
|
|
313
|
+
mapped_entity_type,
|
|
314
|
+
mapped_entity_id,
|
|
315
|
+
loggedInUser,
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
async assignLead(loggedInUser: UserData): Promise<number> {
|
|
322
|
+
const { organization_id, level_id, level_type } = loggedInUser;
|
|
323
|
+
|
|
324
|
+
// 1) Get eligible owners (distinct + stable ordering)
|
|
325
|
+
const owners: Array<{ id: number }> = await this.dataSource.query(
|
|
326
|
+
`
|
|
327
|
+
SELECT DISTINCT u.id
|
|
328
|
+
FROM cr_user u
|
|
329
|
+
JOIN cr_user_role_mapping urm ON u.id = urm.user_id
|
|
330
|
+
JOIN cr_role r ON urm.role_id = r.id
|
|
331
|
+
JOIN cr_module_access ma ON ma.role_code = r.code
|
|
332
|
+
WHERE urm.organization_id = ?
|
|
333
|
+
AND urm.level_id = ?
|
|
334
|
+
AND urm.level_type = ?
|
|
335
|
+
AND urm.appcode = 'CRM'
|
|
336
|
+
AND ma.appcode = 'CRM'
|
|
337
|
+
AND ma.module_code = 'lead_crm_sch'
|
|
338
|
+
AND ma.access_flag = 1
|
|
339
|
+
AND ma.action_type = 'LEAD_OWNER'
|
|
340
|
+
ORDER BY u.id ASC
|
|
341
|
+
`,
|
|
342
|
+
[organization_id, Number(level_id), level_type],
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
if (!owners?.length) throw new Error('No eligible users found');
|
|
346
|
+
const userIds = owners.map((o) => Number(o.id)); // normalize to numbers
|
|
347
|
+
|
|
348
|
+
// 2) Find the last assigned *eligible* owner (use IN (...))
|
|
349
|
+
const placeholders = userIds.map(() => '?').join(',');
|
|
350
|
+
const lastRow: Array<{ lead_owner: number }> = await this.dataSource.query(
|
|
351
|
+
`
|
|
352
|
+
SELECT lead_owner
|
|
353
|
+
FROM crm_lead
|
|
354
|
+
WHERE organization_id = ?
|
|
355
|
+
AND level_id = ?
|
|
356
|
+
AND level_type = ?
|
|
357
|
+
AND lead_owner IN (${placeholders})
|
|
358
|
+
ORDER BY created_date DESC
|
|
359
|
+
LIMIT 1
|
|
360
|
+
`,
|
|
361
|
+
[organization_id, Number(level_id), level_type, ...userIds],
|
|
362
|
+
);
|
|
363
|
+
|
|
364
|
+
const lastAssigned = lastRow.length ? Number(lastRow[0].lead_owner) : null;
|
|
365
|
+
|
|
366
|
+
// 3) Compute next user in round-robin
|
|
367
|
+
const lastIdx = lastAssigned != null ? userIds.indexOf(lastAssigned) : -1;
|
|
368
|
+
const nextIdx = (lastIdx + 1) % userIds.length;
|
|
369
|
+
const nextUser = userIds[nextIdx];
|
|
370
|
+
|
|
371
|
+
//4) Update lead owner in the lead table
|
|
372
|
+
await this.dataSource.query(
|
|
373
|
+
`
|
|
374
|
+
UPDATE crm_lead
|
|
375
|
+
SET lead_owner = ?
|
|
376
|
+
WHERE organization_id = ?
|
|
377
|
+
AND level_id = ?
|
|
378
|
+
AND level_type = ?
|
|
379
|
+
AND lead_owner IS NULL
|
|
380
|
+
ORDER BY created_date ASC
|
|
381
|
+
LIMIT 1
|
|
382
|
+
`,
|
|
383
|
+
[nextUser, organization_id, Number(level_id), level_type],
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
console.log(`Assigning lead to user ID: ${nextUser}`);
|
|
387
|
+
return nextUser;
|
|
275
388
|
}
|
|
276
389
|
}
|