rez_core 2.1.142 → 2.1.144

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 (40) hide show
  1. package/dist/constant/global.constant.d.ts +1 -1
  2. package/dist/constant/global.constant.js +1 -1
  3. package/dist/constant/global.constant.js.map +1 -1
  4. package/dist/module/workflow/controller/action.controller.d.ts +13 -0
  5. package/dist/module/workflow/controller/action.controller.js +58 -0
  6. package/dist/module/workflow/controller/action.controller.js.map +1 -0
  7. package/dist/module/workflow/controller/workflow.controller.d.ts +1 -3
  8. package/dist/module/workflow/controller/workflow.controller.js +1 -12
  9. package/dist/module/workflow/controller/workflow.controller.js.map +1 -1
  10. package/dist/module/workflow/entity/stage.entity.d.ts +1 -0
  11. package/dist/module/workflow/entity/stage.entity.js +4 -0
  12. package/dist/module/workflow/entity/stage.entity.js.map +1 -1
  13. package/dist/module/workflow/repository/comm-template.repository.d.ts +1 -0
  14. package/dist/module/workflow/repository/comm-template.repository.js +12 -0
  15. package/dist/module/workflow/repository/comm-template.repository.js.map +1 -1
  16. package/dist/module/workflow/service/action.service.d.ts +2 -0
  17. package/dist/module/workflow/service/action.service.js +28 -0
  18. package/dist/module/workflow/service/action.service.js.map +1 -1
  19. package/dist/module/workflow/service/comm-template.service.d.ts +3 -1
  20. package/dist/module/workflow/service/comm-template.service.js +7 -1
  21. package/dist/module/workflow/service/comm-template.service.js.map +1 -1
  22. package/dist/module/workflow/service/stage-group.service.d.ts +3 -1
  23. package/dist/module/workflow/service/stage-group.service.js +6 -3
  24. package/dist/module/workflow/service/stage-group.service.js.map +1 -1
  25. package/dist/module/workflow/service/workflow.service.js +14 -4
  26. package/dist/module/workflow/service/workflow.service.js.map +1 -1
  27. package/dist/module/workflow/workflow.module.js +2 -0
  28. package/dist/module/workflow/workflow.module.js.map +1 -1
  29. package/dist/tsconfig.build.tsbuildinfo +1 -1
  30. package/package.json +1 -1
  31. package/src/constant/global.constant.ts +1 -1
  32. package/src/module/workflow/controller/action.controller.ts +44 -0
  33. package/src/module/workflow/controller/workflow.controller.ts +2 -7
  34. package/src/module/workflow/entity/stage.entity.ts +3 -0
  35. package/src/module/workflow/repository/comm-template.repository.ts +19 -0
  36. package/src/module/workflow/service/action.service.ts +41 -1
  37. package/src/module/workflow/service/comm-template.service.ts +21 -4
  38. package/src/module/workflow/service/stage-group.service.ts +5 -4
  39. package/src/module/workflow/service/workflow.service.ts +25 -7
  40. package/src/module/workflow/workflow.module.ts +2 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.1.142",
3
+ "version": "2.1.144",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -46,7 +46,7 @@ export const STAGE = 'STG';
46
46
  export const STAGE_GROUP = 'STGP';
47
47
  export const ACTION_CATEGORY = 'ACTC';
48
48
  export const STAGE_ACTION_MAPPING = 'STGM';
49
- export const COMM_TEMPLATE = 'CTPL';
49
+ export const COMM_TEMPLATE = 'TEM';
50
50
  export const ACTION_TEMPLATE_MAPPING = 'ATMP';
51
51
  export const WORKFLOW_DATA = 'WFDT';
52
52
  export const STAGE_MOVEMENT_DATA = 'STMV';
@@ -0,0 +1,44 @@
1
+ import {
2
+ Body,
3
+ Controller,
4
+ Get,
5
+ HttpCode,
6
+ HttpStatus,
7
+ Inject,
8
+ Post,
9
+ Req,
10
+ UseGuards,
11
+ } from '@nestjs/common';
12
+ import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
13
+ import { ActionService } from '../service/action.service';
14
+
15
+ @Controller('/action')
16
+ @UseGuards(JwtAuthGuard)
17
+ export class ActionController {
18
+ constructor(
19
+ @Inject('ActionService')
20
+ private readonly actionService: ActionService,
21
+ ) {}
22
+
23
+ @Get('/getReasonCode')
24
+ @HttpCode(HttpStatus.OK)
25
+ async getReasonCode(@Req() req: Request & { user: any }) {
26
+ const loggedInUser = req.user.userData;
27
+ const result = this.actionService.getReasonCode(loggedInUser);
28
+ return result;
29
+ }
30
+
31
+ @Post('/defaultReasonCode')
32
+ @HttpCode(HttpStatus.OK)
33
+ async defaultReasonCode(
34
+ @Req() req: Request & { user: any },
35
+ @Body() body: { list_type: string },
36
+ ) {
37
+ const loggedInUser = req.user.userData;
38
+ const result = this.actionService.defaultReasonCode(
39
+ body.list_type,
40
+ loggedInUser,
41
+ );
42
+ return result;
43
+ }
44
+ }
@@ -42,14 +42,9 @@ export class WorkflowController {
42
42
  async getWorkflowById(@Param('id') id: number) {
43
43
  return this.workflowService.getWorkflowById(id);
44
44
  }
45
+ SS;
45
46
 
46
- @Delete('/deleteWorkflow/:id')
47
- @HttpCode(HttpStatus.OK)
48
- async deleteWorkflow(@Param('id') id: number) {
49
- return this.workflowService.deleteWorkflowById(id);
50
- }
51
-
52
- @Put('/updateSequence')
47
+ @Post('/updateSequence')
53
48
  @HttpCode(HttpStatus.OK)
54
49
  async updateSequence(@Body() body: any, @Req() req: Request & { user: any }) {
55
50
  const loggedInUser = req.user?.userData;
@@ -14,4 +14,7 @@ export class Stage extends BaseEntity {
14
14
 
15
15
  @Column({ type: 'int', nullable: true })
16
16
  sequence: number;
17
+
18
+ @Column({ type: 'varchar', nullable: true })
19
+ description: string;
17
20
  }
@@ -19,4 +19,23 @@ export class CommTemplateRepository {
19
19
  },
20
20
  });
21
21
  }
22
+
23
+ async getTemplateByCode(
24
+ entity_type: string,
25
+ code: string,
26
+ loggedInUser,
27
+ ): Promise<CommTemplate | null> {
28
+ const template = await this.commTemplateRepository.findOne({
29
+ where: {
30
+ entity_type: entity_type,
31
+ code: code,
32
+ },
33
+ });
34
+
35
+ if (!template) {
36
+ throw new NotFoundException(`Template with code ${code} not found`);
37
+ }
38
+
39
+ return template;
40
+ }
22
41
  }
@@ -1,4 +1,4 @@
1
- import { Injectable } from '@nestjs/common';
1
+ 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';
@@ -169,4 +169,44 @@ export class ActionService extends EntityServiceImpl {
169
169
 
170
170
  return deleteAction;
171
171
  }
172
+
173
+ async getReasonCode(loggedInUser: UserData): Promise<any> {
174
+ const { organization_id } = loggedInUser;
175
+ const result = await this.dataSource.query(
176
+ `
177
+ SELECT name, type
178
+ FROM cr_list_master
179
+ WHERE organization_id = ? AND source = 'master'
180
+ `,
181
+ [organization_id],
182
+ );
183
+
184
+ const formatted = result.map((item: any) => ({
185
+ label: item.name,
186
+ value: item.type,
187
+ }));
188
+
189
+ return formatted;
190
+ }
191
+
192
+ async defaultReasonCode(list_type: string, loggedInUser: UserData) {
193
+ const { organization_id } = loggedInUser;
194
+ if (!list_type) {
195
+ throw new BadRequestException('list_type is required');
196
+ }
197
+ const result = await this.dataSource.query(
198
+ `
199
+ SELECT name, value
200
+ FROM cr_list_master_items
201
+ WHERE listtype = ? AND organization_id = ?
202
+ `,
203
+ [list_type, organization_id],
204
+ );
205
+
206
+ // Format as array of key-value pairs
207
+ return result.map((row: any) => ({
208
+ label: row.value,
209
+ value: row.name,
210
+ }));
211
+ }
172
212
  }
@@ -1,11 +1,28 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
  import { CommTemplateRepository } from '../repository/comm-template.repository';
3
+ import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
3
4
 
4
5
  @Injectable()
5
- export class CommTemplateService {
6
- constructor(
7
- private readonly commTemplateRepository: CommTemplateRepository,
8
- ) {}
6
+ export class CommTemplateService extends EntityServiceImpl {
7
+ constructor(private readonly commTemplateRepository: CommTemplateRepository) {
8
+ super();
9
+ }
10
+
11
+ async getEntityData(
12
+ entityType: string,
13
+ id: number,
14
+ loggedInUser,
15
+ ): Promise<any> {
16
+ //TODO: check if current level_id and levl_type has that code if not go to parent level
17
+
18
+ const getTemplate = await this.commTemplateRepository.getTemplateByCode(
19
+ entityType,
20
+ id.toString(),
21
+ loggedInUser,
22
+ );
23
+
24
+ return getTemplate;
25
+ }
9
26
 
10
27
  async getAllCommTemplate(entity_type: string, loggedInUser) {
11
28
  const commTemplateData =
@@ -4,6 +4,7 @@ import { StageGroupRepository } from '../repository/stage-group.repository';
4
4
  import { BaseEntity } from 'src/module/meta/entity/base-entity.entity';
5
5
  import { UserData } from 'src/module/user/entity/user.entity';
6
6
  import { StageService } from './stage.service';
7
+ import { DataSource } from 'typeorm';
7
8
 
8
9
  @Injectable()
9
10
  export class StageGroupService extends EntityServiceImpl {
@@ -11,6 +12,7 @@ export class StageGroupService extends EntityServiceImpl {
11
12
  private readonly stageGroupRepository: StageGroupRepository,
12
13
  @Inject('StageService')
13
14
  private readonly stageService: StageService,
15
+ private readonly dataSource: DataSource,
14
16
  ) {
15
17
  super();
16
18
  }
@@ -46,10 +48,9 @@ export class StageGroupService extends EntityServiceImpl {
46
48
  id: number,
47
49
  loggedInUser: UserData,
48
50
  ): Promise<any> {
49
- const getAllStage = await this.stageService.getAllStage(
50
- id,
51
- loggedInUser.level_id,
52
- loggedInUser.level_type,
51
+ const getAllStage = await this.dataSource.query(
52
+ `SELECT id FROM cr_wf_stage WHERE stage_group_id = ? AND level_id =? AND level_type = ?`,
53
+ [id, loggedInUser.level_id, loggedInUser.level_type],
53
54
  );
54
55
 
55
56
  if (getAllStage.length > 0) {
@@ -1,3 +1,4 @@
1
+ import { get } from 'http';
1
2
  import { BadRequestException, Inject, Injectable } from '@nestjs/common';
2
3
  import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
3
4
  import { DataSource, In } from 'typeorm';
@@ -106,17 +107,34 @@ export class WorkflowService extends EntityServiceImpl {
106
107
  id: number,
107
108
  loggedInUser: UserData,
108
109
  ): Promise<any> {
109
- const getAllStage = await this.stageGroupRepository.getAllStageGroup(
110
- id,
111
- loggedInUser.level_id,
112
- loggedInUser.level_type,
110
+ const getWorkflow = await this.getEntityData(entityType, id, loggedInUser);
111
+
112
+ if (!getWorkflow) {
113
+ throw new BadRequestException('Workflow not found');
114
+ }
115
+
116
+ if ((getWorkflow as Workflow).is_default) {
117
+ throw new BadRequestException(
118
+ 'Cannot delete workflow because it is default.',
119
+ );
120
+ }
121
+
122
+ if ((getWorkflow as Workflow).is_factory) {
123
+ throw new BadRequestException(
124
+ 'Cannot delete workflow because it is factory.',
125
+ );
126
+ }
127
+
128
+ const getAllStageGroup = await this.dataSource.query(
129
+ `SELECT id FROM cr_wf_stage_group WHERE workflow_id = ? AND level_id = ? AND level_type = ?`,
130
+ [id, loggedInUser.level_id, loggedInUser.level_type],
113
131
  );
114
132
 
115
- if (getAllStage.length > 0) {
116
- for (const stage of getAllStage) {
133
+ if (getAllStageGroup.length > 0) {
134
+ for (const stageGroup of getAllStageGroup) {
117
135
  await this.stateGroupService.deleteEntity(
118
136
  'STGP',
119
- stage.id,
137
+ stageGroup.id,
120
138
  loggedInUser,
121
139
  );
122
140
  }
@@ -21,7 +21,6 @@ import { WorkflowListMasterController } from './controller/workflow-list-master.
21
21
  import { ActionTemplateMappingController } from './controller/action-template-mapping.controller';
22
22
  import { WorkflowController } from './controller/workflow.controller';
23
23
  import { WorkflowRepository } from './repository/workflow.repository';
24
- import { ListMasterService } from '../listmaster/service/list-master.service';
25
24
  import { ListMasterModule } from '../listmaster/listmaster.module';
26
25
  import { CommTemplateController } from './controller/comm-template.controller';
27
26
  import { CommTemplateRepository } from './repository/comm-template.repository';
@@ -30,6 +29,7 @@ import { StageGroupRepository } from './repository/stage-group.repository';
30
29
  import { StageGroupController } from './controller/stage-group.controller';
31
30
  import { StageController } from './controller/stage.controller';
32
31
  import { StageRepository } from './repository/stage.repository';
32
+ import { ActionController } from './controller/action.controller';
33
33
 
34
34
  @Module({
35
35
  imports: [
@@ -83,6 +83,7 @@ import { StageRepository } from './repository/stage.repository';
83
83
  CommTemplateController,
84
84
  StageGroupController,
85
85
  StageController,
86
+ ActionController,
86
87
  ],
87
88
  })
88
89
  export class WorkflowModule {}