rez_core 2.1.143 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.1.143",
3
+ "version": "2.1.144",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -44,7 +44,7 @@ export class WorkflowController {
44
44
  }
45
45
  SS;
46
46
 
47
- @Put('/updateSequence')
47
+ @Post('/updateSequence')
48
48
  @HttpCode(HttpStatus.OK)
49
49
  async updateSequence(@Body() body: any, @Req() req: Request & { user: any }) {
50
50
  const loggedInUser = req.user?.userData;
@@ -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
  }
@@ -8,6 +8,22 @@ export class CommTemplateService extends EntityServiceImpl {
8
8
  super();
9
9
  }
10
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
+ }
26
+
11
27
  async getAllCommTemplate(entity_type: string, loggedInUser) {
12
28
  const commTemplateData =
13
29
  await this.commTemplateRepository.getAllCommTemplate(
@@ -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
  }