rez_core 2.1.138 → 2.1.139

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 (34) hide show
  1. package/dist/module/filter/controller/filter.controller.d.ts +1 -1
  2. package/dist/module/filter/controller/filter.controller.js +7 -4
  3. package/dist/module/filter/controller/filter.controller.js.map +1 -1
  4. package/dist/module/filter/dto/filter-request.dto.d.ts +1 -0
  5. package/dist/module/filter/service/filter.service.js +23 -2
  6. package/dist/module/filter/service/filter.service.js.map +1 -1
  7. package/dist/module/workflow/controller/stage-group.controller.d.ts +4 -0
  8. package/dist/module/workflow/controller/stage-group.controller.js +31 -0
  9. package/dist/module/workflow/controller/stage-group.controller.js.map +1 -0
  10. package/dist/module/workflow/controller/workflow.controller.d.ts +7 -8
  11. package/dist/module/workflow/controller/workflow.controller.js +13 -14
  12. package/dist/module/workflow/controller/workflow.controller.js.map +1 -1
  13. package/dist/module/workflow/entity/workflow.entity.d.ts +2 -0
  14. package/dist/module/workflow/entity/workflow.entity.js +8 -0
  15. package/dist/module/workflow/entity/workflow.entity.js.map +1 -1
  16. package/dist/module/workflow/repository/workflow.repository.d.ts +9 -1
  17. package/dist/module/workflow/repository/workflow.repository.js +38 -6
  18. package/dist/module/workflow/repository/workflow.repository.js.map +1 -1
  19. package/dist/module/workflow/service/workflow.service.d.ts +13 -3
  20. package/dist/module/workflow/service/workflow.service.js +44 -42
  21. package/dist/module/workflow/service/workflow.service.js.map +1 -1
  22. package/dist/module/workflow/workflow.module.js +5 -0
  23. package/dist/module/workflow/workflow.module.js.map +1 -1
  24. package/dist/tsconfig.build.tsbuildinfo +1 -1
  25. package/package.json +1 -1
  26. package/src/module/filter/controller/filter.controller.ts +10 -4
  27. package/src/module/filter/dto/filter-request.dto.ts +1 -0
  28. package/src/module/filter/service/filter.service.ts +34 -2
  29. package/src/module/workflow/controller/stage-group.controller.ts +10 -0
  30. package/src/module/workflow/controller/workflow.controller.ts +11 -10
  31. package/src/module/workflow/entity/workflow.entity.ts +6 -0
  32. package/src/module/workflow/repository/workflow.repository.ts +40 -2
  33. package/src/module/workflow/service/workflow.service.ts +67 -48
  34. 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.138",
3
+ "version": "2.1.139",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -26,11 +26,16 @@ export class FilterController {
26
26
  @UseGuards(JwtAuthGuard)
27
27
  async applyFilter(
28
28
  @Body() body: any,
29
- @Query('page', ParseIntPipe) page: number = 1,
30
- @Query('size', ParseIntPipe) size: number = 10,
29
+ @Query('page', ParseIntPipe) page = 1,
30
+ @Query('size', ParseIntPipe) size = 10,
31
31
  @Req() req: Request & { user: any },
32
+ @Query() queryParams: Record<string, string>,
32
33
  ) {
33
- const userData = req.user.userData;
34
+ const loggedInUser = req.user.userData;
35
+
36
+ // Remove page and size from queryParams
37
+ const { page: _p, size: _s, ...otherQueryParams } = queryParams;
38
+
34
39
  const {
35
40
  entity_type,
36
41
  quickFilter,
@@ -49,7 +54,8 @@ export class FilterController {
49
54
  sortby,
50
55
  page,
51
56
  size,
52
- loggedInUser: userData,
57
+ loggedInUser,
58
+ queryParams: otherQueryParams, // only remaining query params
53
59
  });
54
60
  }
55
61
 
@@ -26,4 +26,5 @@ export interface FilterRequestDto {
26
26
  page?: number;
27
27
  size?: number;
28
28
  loggedInUser: UserData;
29
+ queryParams?: Record<string, string>;
29
30
  }
@@ -78,8 +78,10 @@ export class FilterService {
78
78
  tabs,
79
79
  sortby,
80
80
  loggedInUser,
81
+ queryParams,
81
82
  } = dto;
82
83
 
84
+ // abstract user details
83
85
  const {
84
86
  level_type,
85
87
  level_id,
@@ -88,15 +90,18 @@ export class FilterService {
88
90
  organization_id,
89
91
  } = loggedInUser || {};
90
92
 
91
- // Fetch meta
93
+ // Fetch meta from entity table service
92
94
  const entityMeta = await this.entityTableService.getEntityData(
93
95
  entity_type,
94
96
  loggedInUser,
95
97
  );
96
98
  const tableName = entityMeta?.data_source; // data_souce is the table name
97
- if (!tableName)
99
+
100
+ if (!tableName) {
98
101
  throw new BadRequestException(`Invalid entity_type: ${entity_type}`);
102
+ }
99
103
 
104
+ // get table meta from cr_entity_table
100
105
  const getTableMeta =
101
106
  await this.entityTableService.findByEntityTypeAndListTypeAndDisplayType(
102
107
  entity_type,
@@ -110,6 +115,7 @@ export class FilterService {
110
115
  `Table meta not found for entity_type: ${entity_type}`,
111
116
  );
112
117
  }
118
+
113
119
  const getTableColumnMeta =
114
120
  await this.entityTableColumnService.findByParentIdAndParentType(
115
121
  getTableMeta.id,
@@ -153,6 +159,32 @@ export class FilterService {
153
159
  });
154
160
  }
155
161
 
162
+ // andWhere search with attributeName && attributeValue
163
+ if (queryParams) {
164
+ Object.entries(queryParams).forEach(([key, value]) => {
165
+ if (!value) return;
166
+
167
+ // Handle custom attributeName/attributeValue
168
+ if (key === 'attributeName' && queryParams['attributeValue']) {
169
+ const attrName = value;
170
+ const attrValue = queryParams['attributeValue'];
171
+
172
+ baseWhere.push({
173
+ query: `e.${attrName} = :${attrName}`,
174
+ params: { [attrName]: attrValue },
175
+ });
176
+ }
177
+
178
+ // Ignore attributeValue itself from being added again
179
+ else if (key !== 'attributeValue') {
180
+ baseWhere.push({
181
+ query: `e.${key} = :${key}`,
182
+ params: { [key]: value },
183
+ });
184
+ }
185
+ });
186
+ }
187
+
156
188
  // if (!this.skipAppCodeFilterEntities.includes(entity_type)) {
157
189
  // baseWhere.push({
158
190
  // query: 'e.appcode = :appcode',
@@ -0,0 +1,10 @@
1
+ import { Controller, Get, UseGuards } from '@nestjs/common';
2
+ import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
3
+
4
+ @Controller('/stage-group')
5
+ @UseGuards(JwtAuthGuard)
6
+ export class StageGroupController {
7
+ constructor() {}
8
+ @Get('/getAllStageGroup')
9
+ async getAllStageGroup() {}
10
+ }
@@ -10,6 +10,7 @@ import {
10
10
  Param,
11
11
  Put,
12
12
  Inject,
13
+ Delete,
13
14
  } from '@nestjs/common';
14
15
  import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
15
16
  import { WorkflowService } from '../service/workflow.service';
@@ -23,18 +24,18 @@ export class WorkflowController {
23
24
  private readonly workflowService: WorkflowService,
24
25
  ) {}
25
26
 
26
- @Post('/getWorkflow')
27
+ @Post('/getAllWorkflows')
27
28
  @HttpCode(HttpStatus.OK)
28
- async getWorkflow(
29
- @Body() body: { entity_type: string },
29
+ async getAllWorkflows(
30
30
  @Req() req: Request & { user: any },
31
+ @Body() body: { entity_type: string },
31
32
  ) {
32
- const loggedInUser = req.user.userData;
33
- const result = await this.workflowService.getAllWorkflow(
33
+ const { level_id, level_type } = req.user.userData;
34
+ return this.workflowService.getAllWorkflows(
34
35
  body.entity_type,
35
- loggedInUser,
36
+ level_id,
37
+ level_type,
36
38
  );
37
- return result;
38
39
  }
39
40
 
40
41
  @Get('/getWorkflowById/:id')
@@ -43,9 +44,9 @@ export class WorkflowController {
43
44
  return this.workflowService.getWorkflowById(id);
44
45
  }
45
46
 
46
- @Post('/getContactDropdown')
47
+ @Delete('/deleteWorkflow/:id')
47
48
  @HttpCode(HttpStatus.OK)
48
- async getLeadContactDropdown(@Body() body: { leadId: number; mode: string }) {
49
- return this.workflowService.getLeadContactDropdown(body.leadId, body.mode);
49
+ async deleteWorkflow(@Param('id') id: number) {
50
+ return this.workflowService.deleteWorkflowById(id);
50
51
  }
51
52
  }
@@ -11,4 +11,10 @@ export class Workflow extends BaseEntity {
11
11
 
12
12
  @Column({ type: 'varchar', nullable: true })
13
13
  mapped_entity_type: string;
14
+
15
+ @Column({ type: 'boolean', nullable: true })
16
+ is_default: boolean;
17
+
18
+ @Column({ type: 'boolean', nullable: true })
19
+ is_factory: boolean;
14
20
  }
@@ -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,29 +1,34 @@
1
- import { BadRequestException, Injectable } from '@nestjs/common';
1
+ import { BadRequestException, Inject, Injectable } from '@nestjs/common';
2
2
  import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
3
+ import { DataSource, In } from 'typeorm';
4
+ import { WorkflowRepository } from '../repository/workflow.repository';
5
+ import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
3
6
  import { UserData } from 'src/module/user/entity/user.entity';
4
- import { BaseEntity, DataSource, Entity } from 'typeorm';
7
+ import { ListMasterService } from 'src/module/listmaster/service/list-master.service';
8
+ import { STATUS_INACTIVE, WORKFLOW } from 'src/constant/global.constant';
9
+ import { Workflow } from '../entity/workflow.entity';
5
10
 
6
11
  @Injectable()
7
12
  export class WorkflowService extends EntityServiceImpl {
8
- constructor(private readonly dataSource: DataSource) {
13
+ constructor(
14
+ private readonly dataSource: DataSource,
15
+ private readonly workflowRepository: WorkflowRepository,
16
+ @Inject('ListMasterService')
17
+ private readonly listMasterService: ListMasterService,
18
+ ) {
9
19
  super();
10
20
  }
11
21
 
12
- async getAllWorkflow(entity_type: string, loggedInUser: any) {
13
- const { level_id, level_type } = loggedInUser;
14
-
15
- const workflows = await this.dataSource.query(
16
- `
17
- SELECT *
18
- FROM cr_workflow
19
- WHERE mapped_entity_type = ?
20
- AND level_id = ?
21
- AND level_type = ?
22
- `,
23
- [entity_type, level_id, level_type],
22
+ async getAllWorkflows(
23
+ entity_type: string,
24
+ level_id: string,
25
+ level_type: string,
26
+ ) {
27
+ return this.workflowRepository.getAllWorkflowsByFilters(
28
+ entity_type,
29
+ level_id,
30
+ level_type,
24
31
  );
25
-
26
- return workflows; // array of rows (each row is already in JSON format)
27
32
  }
28
33
 
29
34
  async getWorkflowById(id: number) {
@@ -34,45 +39,59 @@ export class WorkflowService extends EntityServiceImpl {
34
39
  return result[0] || null;
35
40
  }
36
41
 
37
- async getLeadContactDropdown(leadId: number, mode: string): Promise<any[]> {
38
- const lead = await this.dataSource.query(
39
- `SELECT phone_number, father_mobile, mother_mobile, email, father_email, mother_email
40
- FROM crm_lead
41
- WHERE id = ?`,
42
- [leadId],
42
+ //update entity
43
+ async updateEntity(
44
+ entityData: BaseEntity,
45
+ loggedInUser: UserData,
46
+ ): Promise<any> {
47
+ const resolveStatus = await this.listMasterService.getResolvedListCode(
48
+ STATUS_INACTIVE,
49
+ loggedInUser?.organization_id || 0,
43
50
  );
44
51
 
45
- if (!lead?.length) {
46
- throw new BadRequestException('Lead not found');
47
- }
52
+ const workflowId = entityData.id;
48
53
 
49
- const data = lead[0];
50
- const response: { label: string; value: any }[] = [];
54
+ // Handle INACTIVE status validation
55
+ if (entityData.status == resolveStatus.id) {
56
+ const existingWorkflow = (await this.getEntityData(
57
+ WORKFLOW,
58
+ workflowId,
59
+ loggedInUser,
60
+ )) as Workflow;
51
61
 
52
- if (mode === 'sms' || mode === 'whatsapp') {
53
- if (data.phone_number) {
54
- response.push({ label: 'Primary', value: data.phone_number });
55
- }
56
- if (data.father_mobile) {
57
- response.push({ label: 'Father', value: data.father_mobile });
58
- }
59
- if (data.mother_mobile) {
60
- response.push({ label: 'Mother', value: data.mother_mobile });
61
- }
62
- } else if (mode === 'email') {
63
- if (data.email) {
64
- response.push({ label: 'Primary', value: data.email });
62
+ if (!existingWorkflow) {
63
+ return { success: false, error: 'Workflow not found' };
65
64
  }
66
- if (data.father_email) {
67
- response.push({ label: 'Father', value: data.father_email });
65
+
66
+ if (existingWorkflow.is_default) {
67
+ return {
68
+ success: false,
69
+ error: 'Cannot inactivate because it is default.',
70
+ };
68
71
  }
69
- if (data.mother_email) {
70
- response.push({ label: 'Mother', value: data.mother_email });
72
+
73
+ if (existingWorkflow.is_factory) {
74
+ return {
75
+ success: false,
76
+ error: 'Cannot inactivate because it is factory.',
77
+ };
71
78
  }
72
- } else {
73
- throw new BadRequestException('Invalid mode');
74
79
  }
75
80
 
76
- return response;
81
+ // Handle is_default uniqueness logic
82
+ if ((entityData as Workflow).is_default == true) {
83
+ await this.dataSource
84
+ .createQueryBuilder()
85
+ .update(Workflow)
86
+ .set({ is_default: 0 })
87
+ .where('is_default = :isDefault', { isDefault: 1 })
88
+ .execute();
89
+ }
90
+ // Final update
91
+ return super.updateEntity(entityData, loggedInUser);
92
+ }
93
+
94
+ async deleteWorkflowById(id: number) {
95
+ return this.workflowRepository.deleteWorkflowById(id);
77
96
  }
78
97
  }
@@ -21,6 +21,9 @@ import { WorkflowListMasterService } from './service/workflow-list-master.servic
21
21
  import { WorkflowListMasterController } from './controller/workflow-list-master.controller';
22
22
  import { ActionTemplateMappingController } from './controller/action-template-mapping.controller';
23
23
  import { WorkflowController } from './controller/workflow.controller';
24
+ import { WorkflowRepository } from './repository/workflow.repository';
25
+ import { ListMasterService } from '../listmaster/service/list-master.service';
26
+ import { ListMasterModule } from '../listmaster/listmaster.module';
24
27
 
25
28
  @Module({
26
29
  imports: [
@@ -35,6 +38,7 @@ import { WorkflowController } from './controller/workflow.controller';
35
38
  StageActionMapping,
36
39
  ]),
37
40
  EntityModule,
41
+ ListMasterModule,
38
42
  ],
39
43
  providers: [
40
44
  { provide: 'ActionCategoryService', useClass: ActionCategoryService },
@@ -49,6 +53,7 @@ import { WorkflowController } from './controller/workflow.controller';
49
53
  { provide: 'WorkflowService', useClass: WorkflowService },
50
54
  WorkflowListMasterService,
51
55
  ActionTemplateMappingService,
56
+ WorkflowRepository,
52
57
  ],
53
58
  exports: [
54
59
  'ActionCategoryService',
@@ -57,6 +62,7 @@ import { WorkflowController } from './controller/workflow.controller';
57
62
  'ActionService',
58
63
  'StageService',
59
64
  'StageGroupService',
65
+ WorkflowRepository,
60
66
  ],
61
67
  controllers: [
62
68
  WorkflowListMasterController,