rez_core 2.1.128 → 2.1.130

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.128",
3
+ "version": "2.1.130",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -248,6 +248,21 @@ export class EntityServiceImpl implements EntityService<BaseEntity> {
248
248
  loggedInUser,
249
249
  );
250
250
 
251
+ const validationErrors =
252
+ await this.entityValidationService.validateEntityData(
253
+ entityData,
254
+ entityMaster,
255
+ loggedInUser,
256
+ );
257
+ console.log('Validation Errors For Update:', validationErrors); // Debug log
258
+ if (validationErrors && validationErrors.length > 0) {
259
+ return {
260
+ success: false,
261
+ message: 'Validation failed',
262
+ errors: validationErrors,
263
+ };
264
+ }
265
+
251
266
  const repoService = this.reflectionHelper.getRepoService(
252
267
  entityMaster.entity_data_class,
253
268
  );
@@ -52,6 +52,7 @@ export class EntityValidationService {
52
52
  loggedInUser: any,
53
53
  ): Promise<ValidationError[]> {
54
54
  const errors: ValidationError[] = [];
55
+ const currentId = entityData.id; // assuming 'id' is the primary key
55
56
 
56
57
  for (const attr of attributeData.filter((a) => a.is_unique)) {
57
58
  const value = entityData[attr.attribute_key];
@@ -63,7 +64,7 @@ export class EntityValidationService {
63
64
  .from(db_table_name, db_table_name)
64
65
  .where(`${db_table_name}.${attr.attribute_key} = :value`, { value });
65
66
 
66
- // Add AND condition for organization_id if present
67
+ // Add AND condition for organization_id/level_type/level_id if present
67
68
  const orgId = loggedInUser.organization_id;
68
69
  const level_type = loggedInUser.level_type;
69
70
  const level_id = loggedInUser.level_id;
@@ -73,12 +74,17 @@ export class EntityValidationService {
73
74
  `${db_table_name}.organization_id = :organization_id AND ${db_table_name}.level_type = :level_type AND ${db_table_name}.level_id = :level_id`,
74
75
  {
75
76
  organization_id: orgId,
76
- level_type: level_type,
77
- level_id: level_id,
77
+ level_type,
78
+ level_id,
78
79
  },
79
80
  );
80
81
  }
81
82
 
83
+ // Skip the current record when checking for uniqueness during update
84
+ if (currentId) {
85
+ qb = qb.andWhere(`${db_table_name}.id != :id`, { id: currentId });
86
+ }
87
+
82
88
  const existing = await qb.limit(1).getRawOne();
83
89
 
84
90
  if (existing) {
@@ -4,6 +4,7 @@ import {
4
4
  HttpCode,
5
5
  HttpStatus,
6
6
  Post,
7
+ Req,
7
8
  UseGuards,
8
9
  } from '@nestjs/common';
9
10
  import { JwtAuthGuard } from 'src/module/auth/guards/jwt.guard';
@@ -20,12 +21,14 @@ export class ActionTemplateMappingController {
20
21
  @HttpCode(HttpStatus.OK)
21
22
  async getTemplate(
22
23
  @Body() body: { stage_id: number; action_id: number; mode: number },
24
+ @Req() req: Request & { user: any },
23
25
  ) {
24
- console.log('Incoming Body:', body);
26
+ const loggedInUser = req.user.userData;
25
27
  const result = this.actionTemplateMappingService.getTemplateByMode(
26
28
  body.stage_id,
27
29
  body.action_id,
28
30
  body.mode,
31
+ loggedInUser,
29
32
  );
30
33
  return result;
31
34
  }
@@ -9,6 +9,6 @@ export class CommTemplate extends BaseEntity {
9
9
  this.entity_type = COMM_TEMPLATE;
10
10
  }
11
11
 
12
- @Column({ type: 'int', nullable: true })
13
- mode: number;
12
+ @Column({ type: 'varchar', nullable: true })
13
+ mode: string;
14
14
  }
@@ -7,7 +7,12 @@ export class ActionTemplateMappingService extends EntityServiceImpl {
7
7
  constructor(private readonly dataSource: DataSource) {
8
8
  super();
9
9
  }
10
- async getTemplateByMode(stage_id: number, action_id: number, mode: number) {
10
+ async getTemplateByMode(
11
+ stage_id: number,
12
+ action_id: number,
13
+ mode: number,
14
+ loggedInUser,
15
+ ) {
11
16
  const stageAction = await this.dataSource.query(
12
17
  `
13
18
  SELECT id FROM cr_wf_stage_action_mapping
@@ -26,6 +31,11 @@ export class ActionTemplateMappingService extends EntityServiceImpl {
26
31
  `,
27
32
  [stgActMappingId],
28
33
  );
34
+ const listMasterItemData = await this.dataSource.query(
35
+ `SELECT code FROM cr_list_master_items WHERE id = ?`,
36
+ [mode],
37
+ );
38
+
29
39
  const templateCodes = templates.map((t) => t.template_code);
30
40
  if (!templateCodes.length) return [];
31
41
 
@@ -33,9 +43,9 @@ export class ActionTemplateMappingService extends EntityServiceImpl {
33
43
  `
34
44
  SELECT id, name
35
45
  FROM cr_wf_comm_template
36
- WHERE code IN (?) AND mode = ?
46
+ WHERE code IN (?) AND mode = ? AND organization_id = ?
37
47
  `,
38
- [templateCodes, mode],
48
+ [templateCodes, listMasterItemData[0].code, loggedInUser.organization_id],
39
49
  );
40
50
  return commTemplates.map((t) => ({ id: t.id, name: t.name }));
41
51
  }