rez_core 2.2.112 → 2.2.114

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.2.112",
3
+ "version": "2.2.114",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -1,5 +1,11 @@
1
+ import { level } from 'winston';
1
2
  import { Injectable } from '@nestjs/common';
3
+ import {
4
+ ENTITYTYPE_ENTITYMASTER,
5
+ STATUS_ACTIVE,
6
+ } from 'src/constant/global.constant';
2
7
  import { DataSource } from 'typeorm';
8
+ import { UserData } from 'src/module/user/entity/user.entity';
3
9
 
4
10
  @Injectable()
5
11
  export class EntityDynamicService {
@@ -8,7 +14,7 @@ export class EntityDynamicService {
8
14
  // -----------------------------
9
15
  async createEntity(
10
16
  entityType: string,
11
- data: Record<string, any>,
17
+ entityData: Record<string, any>,
12
18
  loggedInUser: any,
13
19
  ): Promise<any> {
14
20
  const organizationId = loggedInUser.organization_id;
@@ -19,12 +25,59 @@ export class EntityDynamicService {
19
25
  organizationId,
20
26
  );
21
27
 
28
+ const statusList = await this.dataSource.query(
29
+ `SELECT id FROM cr_list_master_items WHERE code = ? AND organization_id = ?`,
30
+ [STATUS_ACTIVE, loggedInUser?.organization_id || 0],
31
+ );
32
+
33
+ entityData.created_date = new Date();
34
+ if (loggedInUser) {
35
+ entityData.created_by = loggedInUser.id;
36
+ if (!entityData.organization_id)
37
+ entityData.organization_id = loggedInUser.organization_id;
38
+ if (!entityData.enterprise_id)
39
+ entityData.enterprise_id = loggedInUser.enterprise_id;
40
+ if (!entityData.level_type)
41
+ entityData.level_type = loggedInUser.level_type;
42
+ if (!entityData.level_id) entityData.level_id = loggedInUser.level_id;
43
+ if (!entityData.status) entityData.status = statusList[0].id;
44
+ }
45
+
46
+ if (!entityData.code && loggedInUser) {
47
+ const result = await this.dataSource.query(
48
+ `SELECT MAX(CAST(SUBSTRING(code, LENGTH(entity_type) + 1) AS UNSIGNED)) AS max_seq_no
49
+ FROM ${tableName}
50
+ WHERE entity_type = ?`,
51
+ [entityData.entity_type],
52
+ );
53
+
54
+ // result will be like [ { max_seq_no: 12 } ]
55
+ let maxSeqNo = result?.[0]?.max_seq_no ? Number(result[0].max_seq_no) : 0;
56
+
57
+ maxSeqNo += 1;
58
+ entityData.code = `${entityData.entity_type}${maxSeqNo}`;
59
+ }
60
+
61
+ const bypassColumn = [
62
+ 'created_date',
63
+ 'created_by',
64
+ 'organization_id',
65
+ 'enterprise_id',
66
+ 'level_type',
67
+ 'level_id',
68
+ 'status',
69
+ 'entity_type',
70
+ 'code',
71
+ ];
72
+
73
+ validAttributes.push(...bypassColumn);
74
+
22
75
  const columns: string[] = [];
23
76
  const values: any[] = [];
24
77
 
25
78
  validAttributes.forEach((attr) => {
26
79
  columns.push(attr);
27
- values.push(attr in data ? data[attr] : null);
80
+ values.push(attr in entityData ? entityData[attr] : null);
28
81
  });
29
82
 
30
83
  const placeholders = columns.map(() => '?').join(', ');
@@ -396,7 +449,7 @@ export class EntityDynamicService {
396
449
  async updateEntity(
397
450
  entityType: string,
398
451
  id: number | string,
399
- data: Record<string, any>,
452
+ entityData: Record<string, any>,
400
453
  loggedInUser: any,
401
454
  ): Promise<any> {
402
455
  const organizationId = loggedInUser.organization_id;
@@ -410,10 +463,35 @@ export class EntityDynamicService {
410
463
  const updates: string[] = [];
411
464
  const values: any[] = [];
412
465
 
413
- for (const key of Object.keys(data)) {
466
+ entityData.modified_date = new Date();
467
+ if (loggedInUser) {
468
+ entityData.modified_by = loggedInUser.id;
469
+ if (!entityData.organization_id && entityData.entity_type !== 'ORG')
470
+ entityData.organization_id = loggedInUser.organization_id;
471
+ if (!entityData.enterprise_id)
472
+ entityData.enterprise_id = loggedInUser.enterprise_id;
473
+ }
474
+
475
+ const bypassColumn = [
476
+ 'created_date',
477
+ 'created_by',
478
+ 'modified_date',
479
+ 'modified_by',
480
+ 'organization_id',
481
+ 'enterprise_id',
482
+ 'level_type',
483
+ 'level_id',
484
+ 'status',
485
+ 'entity_type',
486
+ 'code',
487
+ ];
488
+
489
+ validAttributes.push(...bypassColumn);
490
+
491
+ for (const key of Object.keys(entityData)) {
414
492
  if (validAttributes.includes(key)) {
415
493
  updates.push(`\`${key}\` = ?`);
416
- values.push(data[key]);
494
+ values.push(entityData[key]);
417
495
  }
418
496
  }
419
497