rez_core 2.2.49 → 2.2.53

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 (81) hide show
  1. package/dist/module/meta/controller/view-master.controller.d.ts +3 -0
  2. package/dist/module/meta/controller/view-master.controller.js +24 -1
  3. package/dist/module/meta/controller/view-master.controller.js.map +1 -1
  4. package/dist/module/meta/repository/view-master.repository.d.ts +4 -0
  5. package/dist/module/meta/repository/view-master.repository.js +12 -0
  6. package/dist/module/meta/repository/view-master.repository.js.map +1 -1
  7. package/dist/module/meta/service/view-master.service.d.ts +4 -0
  8. package/dist/module/meta/service/view-master.service.js +3 -0
  9. package/dist/module/meta/service/view-master.service.js.map +1 -1
  10. package/dist/module/notification/controller/otp.controller.d.ts +4 -0
  11. package/dist/module/notification/controller/otp.controller.js +7 -5
  12. package/dist/module/notification/controller/otp.controller.js.map +1 -1
  13. package/dist/module/notification/notification.module.js +2 -0
  14. package/dist/module/notification/notification.module.js.map +1 -1
  15. package/dist/module/notification/service/otp.service.d.ts +9 -2
  16. package/dist/module/notification/service/otp.service.js +36 -7
  17. package/dist/module/notification/service/otp.service.js.map +1 -1
  18. package/dist/module/workflow/controller/activity-log.controller.d.ts +8 -0
  19. package/dist/module/workflow/controller/activity-log.controller.js +45 -0
  20. package/dist/module/workflow/controller/activity-log.controller.js.map +1 -0
  21. package/dist/module/workflow/controller/form-master.controller.d.ts +3 -0
  22. package/dist/module/workflow/controller/form-master.controller.js +14 -0
  23. package/dist/module/workflow/controller/form-master.controller.js.map +1 -1
  24. package/dist/module/workflow/entity/action-resources-mapping.entity.d.ts +1 -0
  25. package/dist/module/workflow/entity/action-resources-mapping.entity.js +4 -0
  26. package/dist/module/workflow/entity/action-resources-mapping.entity.js.map +1 -1
  27. package/dist/module/workflow/entity/activity-log.entity.d.ts +19 -0
  28. package/dist/module/workflow/entity/activity-log.entity.js +86 -0
  29. package/dist/module/workflow/entity/activity-log.entity.js.map +1 -0
  30. package/dist/module/workflow/entity/form.entity.d.ts +9 -0
  31. package/dist/module/workflow/entity/form.entity.js +46 -0
  32. package/dist/module/workflow/entity/form.entity.js.map +1 -0
  33. package/dist/module/workflow/repository/action-data.repository.d.ts +3 -1
  34. package/dist/module/workflow/repository/action-data.repository.js +17 -2
  35. package/dist/module/workflow/repository/action-data.repository.js.map +1 -1
  36. package/dist/module/workflow/repository/activity-log.repository.d.ts +7 -0
  37. package/dist/module/workflow/repository/activity-log.repository.js +41 -0
  38. package/dist/module/workflow/repository/activity-log.repository.js.map +1 -0
  39. package/dist/module/workflow/repository/form-master.repository.d.ts +4 -1
  40. package/dist/module/workflow/repository/form-master.repository.js +18 -2
  41. package/dist/module/workflow/repository/form-master.repository.js.map +1 -1
  42. package/dist/module/workflow/repository/form.repository.d.ts +0 -0
  43. package/dist/module/workflow/repository/form.repository.js +1 -0
  44. package/dist/module/workflow/repository/form.repository.js.map +1 -0
  45. package/dist/module/workflow/repository/stage-group.repository.js +35 -9
  46. package/dist/module/workflow/repository/stage-group.repository.js.map +1 -1
  47. package/dist/module/workflow/repository/stage-movement.repository.js +3 -1
  48. package/dist/module/workflow/repository/stage-movement.repository.js.map +1 -1
  49. package/dist/module/workflow/service/action.service.js +1 -0
  50. package/dist/module/workflow/service/action.service.js.map +1 -1
  51. package/dist/module/workflow/service/activity-log.service.d.ts +9 -0
  52. package/dist/module/workflow/service/activity-log.service.js +30 -0
  53. package/dist/module/workflow/service/activity-log.service.js.map +1 -0
  54. package/dist/module/workflow/service/form-master.service.d.ts +1 -0
  55. package/dist/module/workflow/service/form-master.service.js +8 -0
  56. package/dist/module/workflow/service/form-master.service.js.map +1 -1
  57. package/dist/module/workflow/workflow.module.js +16 -0
  58. package/dist/module/workflow/workflow.module.js.map +1 -1
  59. package/dist/tsconfig.build.tsbuildinfo +1 -1
  60. package/package.json +1 -1
  61. package/src/module/meta/controller/view-master.controller.ts +69 -41
  62. package/src/module/meta/repository/view-master.repository.ts +15 -1
  63. package/src/module/meta/service/view-master.service.ts +7 -0
  64. package/src/module/notification/controller/otp.controller.ts +7 -6
  65. package/src/module/notification/notification.module.ts +3 -1
  66. package/src/module/notification/service/otp.service.ts +57 -11
  67. package/src/module/workflow/controller/activity-log.controller.ts +35 -0
  68. package/src/module/workflow/controller/form-master.controller.ts +8 -0
  69. package/src/module/workflow/entity/action-resources-mapping.entity.ts +3 -0
  70. package/src/module/workflow/entity/activity-log.entity.ts +55 -0
  71. package/src/module/workflow/entity/form.entity.ts +25 -0
  72. package/src/module/workflow/repository/action-data.repository.ts +18 -1
  73. package/src/module/workflow/repository/activity-log.repository.ts +24 -0
  74. package/src/module/workflow/repository/form-master.repository.ts +19 -0
  75. package/src/module/workflow/repository/form.repository.ts +0 -0
  76. package/src/module/workflow/repository/stage-group.repository.ts +64 -12
  77. package/src/module/workflow/repository/stage-movement.repository.ts +3 -1
  78. package/src/module/workflow/service/action.service.ts +1 -0
  79. package/src/module/workflow/service/activity-log.service.ts +24 -0
  80. package/src/module/workflow/service/form-master.service.ts +10 -0
  81. package/src/module/workflow/workflow.module.ts +17 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.2.49",
3
+ "version": "2.2.53",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -1,48 +1,76 @@
1
1
  import {
2
- Controller,
3
- Get,
4
- Query,
5
- Res,
6
- HttpStatus,
7
- UseGuards,
8
- Inject,
9
- } from '@nestjs/common';
10
- import { JwtAuthGuard } from '../../auth/guards/jwt.guard';
11
- import { Response } from 'express';
2
+ Controller,
3
+ Get,
4
+ Query,
5
+ Res,
6
+ HttpStatus,
7
+ UseGuards,
8
+ Inject,
9
+ Req,
10
+ } from '@nestjs/common';
11
+ import { JwtAuthGuard } from '../../auth/guards/jwt.guard';
12
+ import { Response } from 'express';
12
13
  import { ViewMasterService } from '../service/view-master.service';
13
-
14
- @Controller('entity')
15
- @UseGuards(JwtAuthGuard)
16
- export class ViewMasterController {
17
- constructor(@Inject("ViewMasterService") private readonly viewMaster: ViewMasterService) {}
18
-
19
- @Get('viewMaster')
20
- async getEntityJsonByType(
21
- @Query('entity_type') entityType: string,
22
- @Query('type') type:string,
23
- @Res() res: Response,
24
- ) {
25
- try {
26
- if (!entityType || !type) {
27
- return res.status(HttpStatus.BAD_REQUEST).json({
28
- success: false,
29
- message: 'Missing entity_type or type query parameter',
30
- });
31
- }
32
-
33
- const result = await this.viewMaster.getEntityJson(entityType, type);
34
-
35
- return res.status(HttpStatus.OK).json({
36
- success: true,
37
- message: 'Entity data fetched successfully',
38
- data: result,
39
- });
40
- } catch (error) {
41
- return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
14
+
15
+ @Controller('entity')
16
+ @UseGuards(JwtAuthGuard)
17
+ export class ViewMasterController {
18
+ constructor(
19
+ @Inject('ViewMasterService') private readonly viewMaster: ViewMasterService,
20
+ ) {}
21
+
22
+ @Get('viewMaster')
23
+ async getEntityJsonByType(
24
+ @Query('entity_type') entityType: string,
25
+ @Query('type') type: string,
26
+ @Res() res: Response,
27
+ ) {
28
+ try {
29
+ if (!entityType || !type) {
30
+ return res.status(HttpStatus.BAD_REQUEST).json({
42
31
  success: false,
43
- message: error.message || 'Error fetching entity data',
32
+ message: 'Missing entity_type or type query parameter',
44
33
  });
45
34
  }
35
+
36
+ const result = await this.viewMaster.getEntityJson(entityType, type);
37
+
38
+ return res.status(HttpStatus.OK).json({
39
+ success: true,
40
+ message: 'Entity data fetched successfully',
41
+ data: result,
42
+ });
43
+ } catch (error) {
44
+ return res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
45
+ success: false,
46
+ message: error.message || 'Error fetching entity data',
47
+ });
48
+ }
49
+ }
50
+
51
+ @Get('view_master/dropdown')
52
+ async getDropdownData(
53
+ @Req() req: Request & { user: any },
54
+ @Query() query: Record<string, string>,
55
+ @Res() res: Response,
56
+ ) {
57
+ const loggedInUser = req.user.userData;
58
+
59
+ const entityType = query.entity_type;
60
+ if (!entityType) {
61
+ return res.status(HttpStatus.BAD_REQUEST).json({
62
+ success: false,
63
+ message: 'Missing entity_type query parameter',
64
+ });
46
65
  }
66
+
67
+ const result = await this.viewMaster.getViewMasterByEntityType(
68
+ entityType,
69
+ loggedInUser,
70
+ );
71
+
72
+ return res.status(HttpStatus.OK).json({
73
+ data: result,
74
+ });
47
75
  }
48
-
76
+ }
@@ -18,7 +18,21 @@ export class ViewMaterRespository {
18
18
  mapped_entity_type: entityType,
19
19
  type: type,
20
20
  });
21
-
21
+
22
22
  return viewMaster;
23
23
  }
24
+
25
+ async findByEntityType(entityType: string, organizationId: number) {
26
+ const viewMasters = await this.viewMasterRepository.find({
27
+ where: {
28
+ mapped_entity_type: entityType,
29
+ organization_id: organizationId,
30
+ },
31
+ });
32
+
33
+ return viewMasters.map((vm) => ({
34
+ label: vm.name,
35
+ value: vm.id,
36
+ }));
37
+ }
24
38
  }
@@ -73,4 +73,11 @@ export class ViewMasterService extends EntityServiceImpl {
73
73
  ) {
74
74
  return await super.getEntityData(entityType, id, loggedInUserData);
75
75
  }
76
+
77
+ async getViewMasterByEntityType(entityType: string, loggedInUser: UserData) {
78
+ return await this.viewMasterRepoService.findByEntityType(
79
+ entityType,
80
+ loggedInUser.organization_id,
81
+ );
82
+ }
76
83
  }
@@ -44,14 +44,15 @@ export class OtpController {
44
44
  @Post('verify')
45
45
  @HttpCode(HttpStatus.OK)
46
46
  async verifyOtp(@Body() request: any) {
47
- let otp = request.otp;
48
- let otpId = request.otp_id;
49
-
50
- let verify = await this.otpService.verifyOtp(otp, otpId);
51
- if (!verify) {
47
+ let verify = await this.otpService.verifyOtp(request);
48
+ if (!verify.isValid) {
52
49
  throw new BadRequestException('Invalid OTP!');
53
50
  }
54
- return { message: 'OTP verified successfully!', success: true };
51
+ return {
52
+ message: 'OTP verified successfully!',
53
+ success: true,
54
+ data: verify,
55
+ };
55
56
  }
56
57
 
57
58
  @Post('send-mail')
@@ -1,4 +1,4 @@
1
- import { Module } from '@nestjs/common';
1
+ import { forwardRef, Module } from '@nestjs/common';
2
2
  import { OtpService } from './service/otp.service';
3
3
  import { OtpRepository } from './repository/otp.repository';
4
4
  import { TypeOrmModule } from '@nestjs/typeorm';
@@ -9,6 +9,7 @@ import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handleba
9
9
  import { EmailService } from './service/email.service';
10
10
  import { join } from 'path';
11
11
  import { ConfigModule, ConfigService } from '@nestjs/config';
12
+ import { AuthModule } from '../auth/auth.module';
12
13
 
13
14
  @Module({
14
15
  imports: [
@@ -38,6 +39,7 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
38
39
  },
39
40
  }),
40
41
  }),
42
+ AuthModule,
41
43
  ],
42
44
  providers: [OtpService, OtpRepository, EmailService],
43
45
  exports: [OtpService, EmailService],
@@ -3,6 +3,8 @@ import { OtpRepository } from '../repository/otp.repository';
3
3
  import { Otp } from '../entity/otp.entity';
4
4
  import { ClockIDGenService } from '../../../utils/service/clockIDGenUtil.service';
5
5
  import { ConfigService } from '@nestjs/config';
6
+ import { DataSource } from 'typeorm';
7
+ import { JwtAuthService } from 'src/module/auth/services/jwt.service';
6
8
 
7
9
  @Injectable()
8
10
  export class OtpService {
@@ -10,19 +12,28 @@ export class OtpService {
10
12
  private readonly otpRepository: OtpRepository,
11
13
  private readonly idGen: ClockIDGenService,
12
14
  private configService: ConfigService,
13
- ) {
14
- }
15
-
15
+ // @Inject('JwtAuthService')
16
+ private readonly jwtAuthService: JwtAuthService,
17
+ private databaseSource: DataSource,
18
+ ) {}
19
+
16
20
  VERIFY_OTP = this.configService.get('VERIFY_OTP') || 'true';
17
21
  DEFAULT_OTP = this.configService.get('DEFAULT_OTP') || '123456';
18
22
 
19
-
20
- async generate(identifier: string, service: string, expiresIn: number = 5, otpLength: number = 6) {
23
+ async generate(
24
+ identifier: string,
25
+ service: string,
26
+ expiresIn: number = 5,
27
+ otpLength: number = 6,
28
+ ) {
21
29
  let otp = new Otp();
22
30
  otp.created_date = new Date();
23
31
  otp.otp_id = this.idGen.idGenerator();
24
32
  otp.identifier = identifier;
25
- otp.otp = 'true' === this.VERIFY_OTP ? this.generateOtp(otpLength) : this.DEFAULT_OTP;
33
+ otp.otp =
34
+ 'true' === this.VERIFY_OTP
35
+ ? this.generateOtp(otpLength)
36
+ : this.DEFAULT_OTP;
26
37
  otp.service = service;
27
38
  otp.verified = 0;
28
39
  otp.expiration_date = new Date(Date.now() + expiresIn * 60 * 1000);
@@ -30,18 +41,53 @@ export class OtpService {
30
41
  return await this.otpRepository.save(otp);
31
42
  }
32
43
 
33
- async verifyOtp(otp: string, otpId: string) {
44
+ async verifyOtp(request) {
45
+ let verifyOTPResponse = { isValid: false, access_token: '' };
46
+
47
+ let otp = request.otp;
48
+ let otpId = request.otp_id;
49
+
34
50
  let otpEntity = await this.findByOtpId(otpId);
51
+
35
52
  if (otpEntity) {
36
- if (otpEntity.otp === otp && new Date(Date.now()) <= otpEntity.expiration_date && 0 === otpEntity.verified) {
53
+ if (
54
+ otpEntity.otp === otp &&
55
+ new Date(Date.now()) <= otpEntity.expiration_date &&
56
+ 0 === otpEntity.verified
57
+ ) {
37
58
  otpEntity.verified = 1;
38
- const updatedOtp = await this.otpRepository.update(otpEntity.id, otpEntity);
59
+ const updatedOtp = await this.otpRepository.update(
60
+ otpEntity.id,
61
+ otpEntity,
62
+ );
39
63
  if (updatedOtp) {
40
- return true;
64
+ verifyOTPResponse.isValid = true;
41
65
  }
42
66
  }
43
67
  }
44
- return false;
68
+
69
+ if (verifyOTPResponse.isValid && request.entity) {
70
+ const entity_type = request.entity.entity_type;
71
+ const entity_id = request.entity.entity_id;
72
+
73
+ const entityData = await this.databaseSource.query(
74
+ `SELECT level_id, level_type, organization_id FROM ether_core.crm_lead where id = ${entity_id}`,
75
+ );
76
+
77
+ if (entityData.length > 0) {
78
+ const level_id = entityData[0].level_id;
79
+ const level_type = entityData[0].level_type;
80
+ const organization_id = entityData[0].organization_id;
81
+
82
+ verifyOTPResponse.access_token = await this.jwtAuthService.generateJwt({
83
+ level_id: level_id,
84
+ level_type: level_type,
85
+ organization_id: organization_id,
86
+ });
87
+ }
88
+ }
89
+
90
+ return verifyOTPResponse;
45
91
  }
46
92
 
47
93
  async findByOtpId(otpId: string) {
@@ -0,0 +1,35 @@
1
+ import {
2
+ Body,
3
+ Controller,
4
+ HttpCode,
5
+ HttpStatus,
6
+ Inject,
7
+ Post,
8
+ Req,
9
+ UseGuards,
10
+ } from '@nestjs/common';
11
+ import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
12
+ import { ActivityLogService } from '../service/activity-log.service';
13
+ import { Http } from 'winston/lib/winston/transports';
14
+
15
+ @Controller('/activity-log')
16
+ @UseGuards(JwtAuthGuard)
17
+ export class ActivityLogController {
18
+ constructor(
19
+ @Inject('ActivityLogService')
20
+ private readonly activityLogService: ActivityLogService,
21
+ ) {}
22
+ @Post('/get-all-activity-log')
23
+ @HttpCode(HttpStatus.OK)
24
+ async getAllActivityLog(
25
+ @Req() req: Request & { user: any },
26
+ @Body('entity_type') mapped_entity_type: string,
27
+ ) {
28
+ const loggedInUser = req.user.userData;
29
+ const result = this.activityLogService.getAllActivityLog(
30
+ mapped_entity_type,
31
+ loggedInUser,
32
+ );
33
+ return result;
34
+ }
35
+ }
@@ -32,4 +32,12 @@ export class FormMasterController {
32
32
  );
33
33
  return result;
34
34
  }
35
+
36
+ @Post('/submit')
37
+ @HttpCode(HttpStatus.OK)
38
+ async submitForm(@Req() req: Request & { user: any }, @Body() body: any) {
39
+ const loggedInUser = req.user.userData;
40
+ const result = this.formMasterService.submitForm(body);
41
+ return result;
42
+ }
35
43
  }
@@ -23,4 +23,7 @@ export class ActionResourcesMapping extends BaseEntity {
23
23
 
24
24
  @Column({ type: 'int', nullable: true })
25
25
  stg_act_mapping_id: number;
26
+
27
+ @Column({ type: 'varchar', nullable: true })
28
+ form_entity_type: string;
26
29
  }
@@ -0,0 +1,55 @@
1
+ import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
2
+ import { Column, Entity } from 'typeorm';
3
+
4
+ @Entity({ name: 'eth_activity_log' })
5
+ export class ActivityLog extends BaseEntity {
6
+ constructor() {
7
+ super();
8
+ this.entity_type = 'ACLG';
9
+ }
10
+
11
+ @Column({ type: 'varchar', nullable: true })
12
+ running_id: string;
13
+
14
+ @Column({ type: 'varchar', nullable: true })
15
+ mapped_entity_type: string;
16
+
17
+ @Column({ type: 'varchar', nullable: true })
18
+ mapped_entity_id: string;
19
+
20
+ @Column({ type: 'varchar', nullable: true })
21
+ title: string;
22
+
23
+ @Column({ type: 'varchar', nullable: true })
24
+ description: string;
25
+
26
+ @Column({ type: 'varchar', nullable: true })
27
+ user_id: string;
28
+
29
+ @Column({ type: 'varchar', nullable: true })
30
+ level_type: string;
31
+
32
+ @Column({ type: 'varchar', nullable: true })
33
+ level_id: string;
34
+
35
+ @Column({ type: 'varchar', nullable: true })
36
+ category: string;
37
+
38
+ @Column({ type: 'varchar', nullable: true })
39
+ action: string;
40
+
41
+ @Column({ type: 'varchar', nullable: true })
42
+ action_icon: string;
43
+
44
+ @Column({ type: 'varchar', nullable: true })
45
+ action_category_color: string;
46
+
47
+ @Column({ type: 'varchar', nullable: true })
48
+ additional_info_1: string;
49
+
50
+ @Column({ type: 'varchar', nullable: true })
51
+ additional_info_2: string;
52
+
53
+ @Column({ type: 'varchar', nullable: true })
54
+ additional_info_3: string;
55
+ }
@@ -0,0 +1,25 @@
1
+ import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
2
+ import { Column, Entity } from 'typeorm';
3
+
4
+ @Entity({ name: 'cr_wf_form' })
5
+ export class FormDataEntity extends BaseEntity {
6
+ constructor() {
7
+ super();
8
+ this.entity_type = 'FORM';
9
+ }
10
+
11
+ @Column({ nullable: true })
12
+ mapped_entity_id: number;
13
+
14
+ @Column({ nullable: true })
15
+ mapped_entity_type: string;
16
+
17
+ @Column({ nullable: true })
18
+ view_id: number;
19
+
20
+ @Column({ nullable: true })
21
+ entity_id: number;
22
+
23
+ @Column({ nullable: true })
24
+ action_id: number;
25
+ }
@@ -1,8 +1,9 @@
1
- import { BadRequestException, Injectable } from '@nestjs/common';
1
+ import { Injectable } from '@nestjs/common';
2
2
  import { InjectRepository } from '@nestjs/typeorm';
3
3
  import { ActionDataEntity } from '../entity/action-data.entity';
4
4
  import { DataSource, Repository } from 'typeorm';
5
5
  import { UserData } from 'src/module/user/entity/user.entity';
6
+ import { FormDataEntity } from '../entity/form.entity';
6
7
 
7
8
  @Injectable()
8
9
  export class ActionDataRepository {
@@ -10,6 +11,8 @@ export class ActionDataRepository {
10
11
  @InjectRepository(ActionDataEntity)
11
12
  private readonly actionDataRepo: Repository<ActionDataEntity>,
12
13
  private readonly dataSource: DataSource,
14
+ @InjectRepository(FormDataEntity)
15
+ private readonly formRepo: Repository<FormDataEntity>,
13
16
  ) {}
14
17
 
15
18
  async saveActionData(
@@ -43,6 +46,20 @@ export class ActionDataRepository {
43
46
  category: act?.action_category_code,
44
47
  } as ActionDataEntity);
45
48
  await this.actionDataRepo.save(actionData);
49
+
50
+ // SEND FORM related logic
51
+ // if the action_category_code is 'SDFM', create a entry in cr_wf_form table
52
+ if (act?.action_category_code === 'SDFM') {
53
+ this.formRepo.insert({
54
+ mapped_entity_type,
55
+ mapped_entity_id,
56
+ entity_type: mapped_entity_type,
57
+ entity_id: mapped_entity_id,
58
+ view_id: act.form_id,
59
+ status: 'N',
60
+ action_id: act.id,
61
+ });
62
+ }
46
63
  }
47
64
  }
48
65
  }
@@ -0,0 +1,24 @@
1
+ import { InjectRepository } from '@nestjs/typeorm';
2
+ import { ActivityLog } from '../entity/activity-log.entity';
3
+ import { Repository } from 'typeorm';
4
+
5
+ export class ActivityLogRepository {
6
+ constructor(
7
+ @InjectRepository(ActivityLog)
8
+ private readonly activityLogRepository: Repository<ActivityLog>,
9
+ ) {}
10
+
11
+ async getAllActivityLog(mapped_entity_type: string, loggedInUser) {
12
+ const { organization_id } = loggedInUser;
13
+
14
+ return this.activityLogRepository
15
+ .createQueryBuilder('log')
16
+ .leftJoin('cr_user', 'user', 'log.user_id = user.id')
17
+ .where('log.mapped_entity_type = :mapped_entity_type', {
18
+ mapped_entity_type,
19
+ })
20
+ .andWhere('log.organization_id = :organization_id', { organization_id })
21
+ .addSelect('user.name', 'user_name') // Add only user_name
22
+ .getRawMany();
23
+ }
24
+ }
@@ -7,6 +7,7 @@ import {
7
7
  import { InjectRepository } from '@nestjs/typeorm';
8
8
  import { DataSource, Repository } from 'typeorm';
9
9
  import { FormMasterDataEntity } from '../entity/form-master.entity';
10
+ import { FormDataEntity } from '../entity/form.entity';
10
11
 
11
12
  @Injectable()
12
13
  export class FormMasterRepository {
@@ -14,6 +15,8 @@ export class FormMasterRepository {
14
15
  @InjectRepository(FormMasterDataEntity)
15
16
  private readonly formMasterRepository: Repository<FormMasterDataEntity>,
16
17
  private readonly dataSource: DataSource,
18
+ @InjectRepository(FormDataEntity)
19
+ private readonly formRepo: Repository<FormDataEntity>,
17
20
  ) {}
18
21
 
19
22
  async getForms(organization_id: number, source_entity_type: string) {
@@ -34,4 +37,20 @@ export class FormMasterRepository {
34
37
 
35
38
  return formatted;
36
39
  }
40
+
41
+ async submitForm(formData: any) {
42
+ const currentForm = await this.formRepo.findOneBy({
43
+ mapped_entity_id: formData.entity_id,
44
+ mapped_entity_type: formData.entity_type,
45
+ view_id: formData.view_id,
46
+ });
47
+
48
+ if (!currentForm) {
49
+ throw new NotFoundException('Form not found');
50
+ }
51
+
52
+ currentForm.status = 'Y';
53
+
54
+ return this.formRepo.save(currentForm);
55
+ }
37
56
  }
@@ -56,33 +56,85 @@ export class StageGroupRepository {
56
56
 
57
57
  if (!stageGroups.length) return [];
58
58
 
59
- // Step 2: Get all stages where stage_group_id IN (...)
59
+ // Step 2: Get all stages for these stage groups
60
60
  const stageGroupIds = stageGroups.map((sg) => sg.id);
61
61
 
62
62
  const stages = await this.dataSource.query(
63
63
  `
64
- SELECT
65
- cr_wf_stage.*,
66
- cr_user.name AS created_by_name
67
- FROM cr_wf_stage
68
- LEFT JOIN cr_user ON cr_wf_stage.created_by = cr_user.id
69
- WHERE cr_wf_stage.stage_group_id IN (${stageGroupIds.map(() => '?').join(',')})
70
- AND cr_wf_stage.organization_id = ?
71
- ORDER BY cr_wf_stage.sequence ASC
72
- `,
64
+ SELECT
65
+ cr_wf_stage.*,
66
+ cr_user.name AS created_by_name
67
+ FROM cr_wf_stage
68
+ LEFT JOIN cr_user ON cr_wf_stage.created_by = cr_user.id
69
+ WHERE cr_wf_stage.stage_group_id IN (${stageGroupIds.map(() => '?').join(',')})
70
+ AND cr_wf_stage.organization_id = ?
71
+ ORDER BY cr_wf_stage.sequence ASC
72
+ `,
73
73
  [...stageGroupIds, organization_id],
74
74
  );
75
75
 
76
- // Step 3: Group stages by stage_group_id
76
+ // Step 3: Get all counts in bulk
77
+ const stageIds = stages.map((s) => s.id);
78
+
79
+ // Task counts
80
+ const taskCounts = await this.dataSource.query(
81
+ `
82
+ SELECT stage_id, COUNT(*) AS task_count
83
+ FROM cr_wf_task_data
84
+ WHERE stage_id IN (${stageIds.map(() => '?').join(',')})
85
+ GROUP BY stage_id
86
+ `,
87
+ [...stageIds],
88
+ );
89
+
90
+ // Meeting counts
91
+ const meetingCounts = await this.dataSource.query(
92
+ `
93
+ SELECT stage_id, COUNT(*) AS meeting_count
94
+ FROM cr_lead_meeting
95
+ WHERE stage_id IN (${stageIds.map(() => '?').join(',')})
96
+ GROUP BY stage_id
97
+ `,
98
+ [...stageIds],
99
+ );
100
+
101
+ // Send communication counts
102
+ const sendCommCounts = await this.dataSource.query(
103
+ `
104
+ SELECT stage_id, COUNT(*) AS send_comm_count
105
+ FROM cr_lead_communication
106
+ WHERE stage_id IN (${stageIds.map(() => '?').join(',')}) AND type = 'SEND'
107
+ GROUP BY stage_id
108
+ `,
109
+ [...stageIds],
110
+ );
111
+
112
+ // Convert to maps for quick lookup
113
+ const taskCountMap = new Map(
114
+ taskCounts.map((row) => [row.stage_id, row.task_count]),
115
+ );
116
+ const meetingCountMap = new Map(
117
+ meetingCounts.map((row) => [row.stage_id, row.meeting_count]),
118
+ );
119
+ const sendCommCountMap = new Map(
120
+ sendCommCounts.map((row) => [row.stage_id, row.send_comm_count]),
121
+ );
122
+
123
+ // Step 4: Add counts to each stage
77
124
  const stageMap = new Map<number, any[]>();
78
125
  for (const stage of stages) {
126
+ const stageId = Number(stage.id);
127
+ stage.task_count = taskCountMap.get(stageId) || 0;
128
+ stage.meeting_count = meetingCountMap.get(stageId) || 0;
129
+ stage.send_comm_count = sendCommCountMap.get(stageId) || 0;
130
+
79
131
  if (!stageMap.has(stage.stage_group_id)) {
80
132
  stageMap.set(stage.stage_group_id, []);
81
133
  }
82
134
  stageMap.get(stage.stage_group_id)?.push(stage);
83
135
  }
84
136
 
85
- // Step 4: Attach stages to stage groups
137
+ // Step 5: Attach stages with counts to stage groups
86
138
  const result = stageGroups.map((stageGroup) => {
87
139
  return {
88
140
  ...stageGroup,
@@ -186,10 +186,12 @@ export class StageMovementRepository {
186
186
  SELECT
187
187
  a.*,
188
188
  m.stage_id,
189
- ac.code AS action_category_code
189
+ ac.code AS action_category_code,
190
+ arm.form_id
190
191
  FROM cr_wf_action a
191
192
  INNER JOIN cr_wf_stage_action_mapping m ON a.id = m.action_id
192
193
  LEFT JOIN cr_wf_action_category ac ON a.action_category = ac.id
194
+ LEFT JOIN cr_wf_action_resources_mapping arm ON m.id = arm.stg_act_mapping_id
193
195
  WHERE m.stage_id = ?
194
196
  `,
195
197
  [stageId],
@@ -105,6 +105,7 @@ export class ActionService extends EntityServiceImpl {
105
105
  form_id: formId,
106
106
  type: 'form',
107
107
  entity_type: 'ARMS',
108
+ form_entity_type: 'LEAD',
108
109
  } as any;
109
110
 
110
111
  if (entityData?.organization_id) {