rez_core 1.0.41 → 1.0.43

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 (50) hide show
  1. package/dist/module/listmaster/controller/list-master.controller.js +4 -4
  2. package/dist/module/listmaster/controller/list-master.controller.js.map +1 -1
  3. package/dist/module/listmaster/entity/list-master.entity.d.ts +3 -6
  4. package/dist/module/listmaster/entity/list-master.entity.js +3 -15
  5. package/dist/module/listmaster/entity/list-master.entity.js.map +1 -1
  6. package/dist/module/listmaster/listmaster.module.js +2 -0
  7. package/dist/module/listmaster/listmaster.module.js.map +1 -1
  8. package/dist/module/listmaster/service/list-master.service.js +13 -5
  9. package/dist/module/listmaster/service/list-master.service.js.map +1 -1
  10. package/dist/module/master/controller/master.controller.d.ts +1 -1
  11. package/dist/module/master/controller/master.controller.js +5 -5
  12. package/dist/module/master/controller/master.controller.js.map +1 -1
  13. package/dist/module/master/service/master.service.d.ts +3 -8
  14. package/dist/module/master/service/master.service.js +60 -94
  15. package/dist/module/master/service/master.service.js.map +1 -1
  16. package/dist/module/meta/entity/attribute-master.entity.d.ts +1 -0
  17. package/dist/module/meta/entity/attribute-master.entity.js +5 -1
  18. package/dist/module/meta/entity/attribute-master.entity.js.map +1 -1
  19. package/dist/module/meta/entity/entity-master.entity.d.ts +1 -1
  20. package/dist/module/meta/entity/entity-master.entity.js +1 -1
  21. package/dist/module/meta/entity/entity-master.entity.js.map +1 -1
  22. package/dist/module/meta/service/media-data.service.js +1 -1
  23. package/dist/module/meta/service/media-data.service.js.map +1 -1
  24. package/dist/module/third-party-module/entity/third-party-api-registry.entity.d.ts +15 -0
  25. package/dist/module/third-party-module/entity/third-party-api-registry.entity.js +72 -0
  26. package/dist/module/third-party-module/entity/third-party-api-registry.entity.js.map +1 -0
  27. package/dist/module/third-party-module/repository/third-party-api-registry.repository.d.ts +7 -0
  28. package/dist/module/third-party-module/repository/third-party-api-registry.repository.js +38 -0
  29. package/dist/module/third-party-module/repository/third-party-api-registry.repository.js.map +1 -0
  30. package/dist/module/third-party-module/service/api-registry.service.d.ts +6 -0
  31. package/dist/module/third-party-module/service/api-registry.service.js +28 -0
  32. package/dist/module/third-party-module/service/api-registry.service.js.map +1 -0
  33. package/dist/module/third-party-module/third-party.module.d.ts +2 -0
  34. package/dist/module/third-party-module/third-party.module.js +25 -0
  35. package/dist/module/third-party-module/third-party.module.js.map +1 -0
  36. package/dist/tsconfig.build.tsbuildinfo +1 -1
  37. package/package.json +3 -1
  38. package/src/module/listmaster/controller/list-master.controller.ts +3 -3
  39. package/src/module/listmaster/entity/list-master.entity.ts +3 -12
  40. package/src/module/listmaster/listmaster.module.ts +2 -0
  41. package/src/module/listmaster/service/list-master.service.ts +23 -9
  42. package/src/module/master/controller/master.controller.ts +14 -6
  43. package/src/module/master/service/master.service.ts +75 -120
  44. package/src/module/meta/entity/attribute-master.entity.ts +4 -1
  45. package/src/module/meta/entity/entity-master.entity.ts +3 -1
  46. package/src/module/meta/service/media-data.service.ts +1 -1
  47. package/src/module/third-party-module/entity/third-party-api-registry.entity.ts +43 -0
  48. package/src/module/third-party-module/repository/third-party-api-registry.repository.ts +20 -0
  49. package/src/module/third-party-module/service/api-registry.service.ts +13 -0
  50. package/src/module/third-party-module/third-party.module.ts +12 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "1.0.41",
3
+ "version": "1.0.43",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -21,6 +21,7 @@
21
21
  "prepare": "husky"
22
22
  },
23
23
  "dependencies": {
24
+ "@nestjs/axios": "^4.0.0",
24
25
  "@nestjs/common": "^11.0.1",
25
26
  "@nestjs/config": "^4.0.1",
26
27
  "@nestjs/core": "^11.0.1",
@@ -31,6 +32,7 @@
31
32
  "@nestjs/typeorm": "^11.0.0",
32
33
  "250218_nodejs_core": "file:",
33
34
  "aws-sdk": "^2.1692.0",
35
+ "axios": "^1.9.0",
34
36
  "bcrypt": "^5.1.1",
35
37
  "class-transformer": "^0.5.1",
36
38
  "class-validator": "^0.14.1",
@@ -6,9 +6,9 @@ export class ListMasterController {
6
6
 
7
7
  constructor(private readonly service: ListMasterService) {}
8
8
 
9
- @Get(':type')
10
- getDropdownData(@Param('type') type: string) {
11
- return this.service.getDropdownOptions(type);
9
+ @Get('/getDropdownData/:type')
10
+ async getDropdownData(@Param('type') type: string) {
11
+ return await this.service.getDropdownOptions(type);
12
12
  }
13
13
 
14
14
  }
@@ -9,27 +9,18 @@ export class ListMasterData extends BaseEntity {
9
9
  this.entity_type = ENTITYTYPE_LISTMASTER;
10
10
  }
11
11
 
12
- @PrimaryGeneratedColumn()
13
- id: number;
14
-
15
12
  @Column()
16
13
  type: string;
17
14
 
18
15
  @Column()
19
- name: string;
20
-
21
- @Column()
22
- status: string;
23
-
24
- @Column()
25
- sortby: string;
16
+ sort_by: string;
26
17
 
27
18
  @Column()
28
- isfactory: number;
19
+ is_factory: number;
29
20
 
30
21
  @Column()
31
22
  source: string;
32
23
 
33
24
  @Column({ nullable: true })
34
- sourcelist: string;
25
+ source_list: string;
35
26
  }
@@ -6,9 +6,11 @@ import { ListMasterRepository } from './repository/list-master.repository';
6
6
  import { ListMasterItemsRepository } from './repository/list-master-items.repository';
7
7
  import { ListMasterService } from './service/list-master.service';
8
8
  import { EntityModule } from '../meta/entity.module';
9
+ import { ListMasterController } from './controller/list-master.controller';
9
10
 
10
11
  @Module({
11
12
  imports: [TypeOrmModule.forFeature([ListMasterData, ListMasterItems]),EntityModule],
12
13
  providers: [ListMasterRepository, ListMasterItemsRepository, ListMasterService],
14
+ controllers: [ListMasterController]
13
15
  })
14
16
  export class ListMasterModule {}
@@ -1,5 +1,9 @@
1
1
  import { EntityServiceImpl } from '../../meta/service/entity-service-impl.service';
2
- import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
2
+ import {
3
+ BadRequestException,
4
+ Injectable,
5
+ NotFoundException,
6
+ } from '@nestjs/common';
3
7
  import { ListMasterItemsRepository } from '../repository/list-master-items.repository';
4
8
  import { ListMasterRepository } from '../repository/list-master.repository';
5
9
 
@@ -19,7 +23,7 @@ export class ListMasterService extends EntityServiceImpl {
19
23
 
20
24
  switch (config.source) {
21
25
  case 'entity':
22
- return this.fetchFromEntity(config.sourcelist);
26
+ return this.fetchFromEntity(type);
23
27
 
24
28
  case 'master':
25
29
  return this.listItemsRepo.findItemsByType(type);
@@ -33,12 +37,22 @@ export class ListMasterService extends EntityServiceImpl {
33
37
  }
34
38
  }
35
39
 
36
- private async fetchFromEntity(sourcelist: string) {
37
- if (sourcelist === 'USR') {
38
- // Example: hardcoded until dynamic entity registry is done
39
- return [{ label: 'User A', value: 1 }, { label: 'User B', value: 2 }];
40
+ private async fetchFromEntity(sourceList: string) {
41
+ let result: { label: string; value: number }[] = [];
42
+ if (sourceList) {
43
+ const entityMaster =
44
+ await this.entityMasterService.getEntityData(sourceList);
45
+
46
+ let baseEntities = await super.getEntityList(
47
+ entityMaster.mapped_entity_type,
48
+ );
49
+ baseEntities.forEach((entity) => {
50
+ result.push({
51
+ label: entity.name,
52
+ value: parseInt(String(entity.id)),
53
+ });
54
+ });
40
55
  }
41
-
42
- throw new NotFoundException(`Entity source ${sourcelist} not handled yet`);
56
+ return result;
43
57
  }
44
- }
58
+ }
@@ -13,14 +13,22 @@ import { Express } from 'express';
13
13
  export class MasterController {
14
14
  constructor(private readonly masterService: MasterService) {}
15
15
 
16
- @Post('upload')
16
+ // @Post('upload')
17
+ // @UseInterceptors(FileInterceptor('file'))
18
+ // async uploadFile(@UploadedFile() file) {
19
+ // if (!file) {
20
+ // throw new Error('File is required');
21
+ // }
22
+ // return this.masterService.processExcel(file);
23
+ // }
24
+
25
+ @Post('uploadMasterData')
17
26
  @UseInterceptors(FileInterceptor('file'))
18
- async uploadFile(@UploadedFile() file) {
27
+
28
+ async uploadMasterDataXls(@UploadedFile() file: Express.Multer.File) {
19
29
  if (!file) {
20
- throw new Error('File is required');
30
+ throw new BadRequestException('File is required');
21
31
  }
22
- return this.masterService.processExcel(file);
32
+ return await this.masterService.uploadMasterData(file.buffer);
23
33
  }
24
-
25
-
26
34
  }
@@ -1,11 +1,12 @@
1
1
  import { Injectable } from '@nestjs/common';
2
- import { EntityManager } from 'typeorm';
2
+ import { EntityManager, Unique } from 'typeorm';
3
3
  import { ExcelUtil } from 'src/utils/service/excelUtil.service';
4
4
  import { EntityMasterService } from '../../meta/service/entity-master.service';
5
+ import { table } from 'console';
5
6
 
6
7
  interface ParentEntity {
7
8
  id: number;
8
- code: string;
9
+ code: string;
9
10
  }
10
11
 
11
12
  @Injectable()
@@ -17,145 +18,99 @@ export class MasterService {
17
18
  ) {}
18
19
 
19
20
  private readonly metaSheets = [
20
- 'entity_master',
21
- 'attribute_master',
22
- 'list_master',
23
- 'list_master_items',
21
+ 'cr_entity_master',
22
+ 'cr_attribute_master',
23
+ 'cr_list_master',
24
+ 'cr_list_master_items',
25
+ ];
26
+ private readonly sequence = [
27
+ {
28
+ table: 'cr_entity_master',
29
+ unique_fields: ['mapped_entity_type'],
30
+ },
31
+ {
32
+ table: 'cr_attribute_master',
33
+ unique_fields: ['mapped_entity_type', 'attribute_key'],
34
+ },
35
+ {
36
+ table: 'cr_list_master',
37
+ unique_fields: ['type'],
38
+ },
39
+ {
40
+ table: 'cr_list_master_items',
41
+ unique_fields: ['listtype', 'code'],
42
+ },
24
43
  ];
25
44
 
26
45
  private isMetaSheet(sheetName: string): boolean {
27
46
  return this.metaSheets.includes(sheetName.toLowerCase());
28
47
  }
29
48
 
30
- async processExcel(file): Promise<{ message: string }> {
31
- console.log('📥 Reading Excel file...');
32
- const data = ExcelUtil.readExcel(file.buffer) as Record<string, Record<string, any>[]>;
33
-
34
- for (const [sheetName, records] of Object.entries(data)) {
35
- if (!records.length) continue;
36
-
37
- const isMeta = this.isMetaSheet(sheetName);
38
- console.log(`📄 Processing sheet: ${sheetName} | Meta: ${isMeta}`);
39
-
40
- if (isMeta) {
41
- await this.upsertData(sheetName, records);
42
- } else {
43
- await this.processEntityData(records);
44
- }
45
- }
49
+ async uploadMasterData(file) {
50
+ const data = ExcelUtil.readExcel(file.buffer);
46
51
 
47
- return { message: '✅ Data processed successfully' };
48
- }
52
+ for (let i = 0; i < this.sequence.length; i++) {
53
+ const { table, unique_fields } = this.sequence[i];
54
+ const sheetData = data[table];
49
55
 
50
- private async processEntityData(records: Record<string, any>[]): Promise<void> {
51
- for (const row of records) {
52
- const entityType = row['entity_type'];
53
- if (!entityType) {
54
- console.warn('⚠️ Skipping row without entity_type:', row);
56
+ if (!sheetData) {
57
+ console.log(`Sheet ${table} not found in the Excel file.`);
55
58
  continue;
56
59
  }
57
-
58
- const { tableName } = await this.getEntityMeta(entityType);
59
- const attrMap = await this.getAttributeMap(entityType);
60
- const transformed = this.transformRow(row, attrMap);
61
-
62
- // Resolve parent_id if parent_type and parent_id are present
63
- if (row['parent_id'] && row['parent_type']) {
64
- transformed['parent_id'] = await this.resolveParentId(row['parent_type'], row['parent_id']);
65
- transformed['parent_type'] = row['parent_type'];
60
+ if (this.isMetaSheet(table)) {
61
+ console.log(`Processing sheet: ${table}`);
62
+ await this.upsertData(table, unique_fields, sheetData);
66
63
  }
64
+ else{
67
65
 
68
- await this.insertEntityRow(tableName, transformed);
69
- }
70
- }
71
-
72
- private async getEntityMeta(entityType: string): Promise<{ tableName: string; mappedEntityType: string }> {
73
- const result = await this.entityManager.query(
74
- `SELECT db_table_name, mapped_entity_type FROM entity_master WHERE mapped_entity_type = ? LIMIT 1`,
75
- [entityType],
76
- );
77
-
78
- if (!result.length || !result[0].db_table_name) {
79
- throw new Error(`❌ Entity metadata not found for entity_type: ${entityType}`);
66
+ }
67
+
80
68
  }
81
-
82
69
  return {
83
- tableName: result[0].db_table_name,
84
- mappedEntityType: result[0].mapped_entity_type,
70
+ message: 'Data uploaded successfully',
85
71
  };
86
72
  }
87
73
 
88
- private async getAttributeMap(mappedEntityType: string): Promise<Record<string, string>> {
89
- const attributes = await this.entityManager.query(
90
- 'SELECT attribute_key FROM attribute_master WHERE mapped_entity_type = ? AND status = "ACTIVE"',
91
- [mappedEntityType],
92
- );
93
-
94
- return attributes.reduce((acc, attr) => {
95
- acc[attr.attribute_key] = attr.attribute_key;
96
- return acc;
97
- }, {} as Record<string, string>);
98
- }
99
-
100
- private transformRow(row: Record<string, any>, attrMap: Record<string, string>): Record<string, any> {
101
- const transformed: Record<string, any> = {};
102
- for (const key of Object.keys(row)) {
103
- if (attrMap[key]) {
104
- transformed[attrMap[key]] = row[key];
105
- }
106
- }
107
- return transformed;
108
- }
109
-
110
- private async resolveParentId(parentType: string, parentCode: string): Promise<number> {
111
- const { tableName } = await this.getEntityMeta(parentType);
112
- const parent = await this.entityManager.findOne<ParentEntity>(tableName, {
113
- where: { code: parentCode },
114
- });
115
-
116
- if (!parent) {
117
- throw new Error(`❌ Parent with code "${parentCode}" not found in "${tableName}"`);
118
- }
119
-
120
- return parent.id;
121
- }
122
-
123
- private async insertEntityRow(tableName: string, data: Record<string, any>): Promise<void> {
124
- const keys = Object.keys(data);
125
- if (!keys.length) {
126
- console.warn('⚠️ Empty data, skipping insert');
127
- return;
128
- }
129
-
130
- await this.entityManager
131
- .createQueryBuilder()
132
- .insert()
133
- .into(tableName)
134
- .values(data)
135
- .orUpdate({
136
- overwrite: keys,
137
- conflict_target: ['code'],
138
- })
139
- .execute();
140
- }
141
-
142
- private async upsertData(tableName: string, records: Record<string, any>[]): Promise<void> {
143
- if (!records.length) return;
144
-
145
- const keys = Object.keys(records[0]);
146
- await this.entityManager.transaction(async (manager) => {
147
- for (const record of records) {
148
- await manager
74
+ async upsertData(
75
+ tableName: string,
76
+ uniqueFields: string[],
77
+ data: any[],
78
+ ): Promise<void> {
79
+ for (const row of data) {
80
+ const whereClause = uniqueFields
81
+ .map((field) => `${field} = :${field}`)
82
+ .join(' AND ');
83
+
84
+ const whereParams = uniqueFields.reduce((acc, field) => {
85
+ acc[field] = row[field];
86
+ return acc;
87
+ }, {});
88
+
89
+ const existing = await this.entityManager
90
+ .createQueryBuilder()
91
+ .select('*')
92
+ .from(tableName, tableName)
93
+ .where(whereClause, whereParams)
94
+ .limit(1)
95
+ .getRawMany();
96
+
97
+ if (existing.length > 0) {
98
+ // Update
99
+ await this.entityManager
100
+ .createQueryBuilder()
101
+ .update(tableName)
102
+ .set(row)
103
+ .where(whereClause, whereParams)
104
+ .execute();
105
+ } else {
106
+ // Insert
107
+ await this.entityManager
149
108
  .createQueryBuilder()
150
109
  .insert()
151
110
  .into(tableName)
152
- .values(record)
153
- .orUpdate({
154
- overwrite: keys,
155
- conflict_target: ['id'],
156
- })
111
+ .values(row)
157
112
  .execute();
158
113
  }
159
- });
114
+ }
160
115
  }
161
116
  }
@@ -6,7 +6,7 @@ export class AttributeMaster extends BaseEntity {
6
6
  @Column({ name: 'mapped_entity_type', type: 'varchar', nullable: true })
7
7
  mapped_entity_type: string;
8
8
 
9
- @Column({ name: 'mapped_entity_id' })
9
+ @Column({ name: 'mapped_entity_id' ,nullable: true })
10
10
  mapped_entity_id: number;
11
11
 
12
12
  @Column({ name: 'element_type', type: 'varchar', nullable: true, length: 50 })
@@ -64,4 +64,7 @@ export class AttributeMaster extends BaseEntity {
64
64
 
65
65
  @Column({ name: 'can_export', nullable: true })
66
66
  can_export: number;
67
+
68
+ @Column({ name: 'appcode', nullable: true })
69
+ appcode:string;
67
70
  }
@@ -18,7 +18,7 @@ export class EntityMaster extends BaseEntity {
18
18
  mapped_entity_type: string;
19
19
 
20
20
  @Column({ name: 'appcode', type: 'varchar', length: 50, nullable: true })
21
- appCode: string;
21
+ appcode: string;
22
22
 
23
23
  @Column({ name: 'category', type: 'varchar', length: 50, nullable: true })
24
24
  category: string;
@@ -60,4 +60,6 @@ export class EntityMaster extends BaseEntity {
60
60
 
61
61
  @Column({ name: 'storage_type', nullable: true, length: 20 })
62
62
  storage_type: string;
63
+
64
+
63
65
  }
@@ -44,7 +44,7 @@ export class MediaDataService extends EntityServiceImpl {
44
44
  const ext = fileName.split('.').pop()?.toLowerCase() ?? '';
45
45
 
46
46
  const id = uuidv4();
47
- const s3Key = `uploads/${mappedAttributeKey}/${id}.${ext}`;
47
+ const s3Key = `uploads/${id}.${ext}`;
48
48
  console.log(s3Key)
49
49
 
50
50
  const uploadUrl = await this.s3.getSignedUrlPromise('putObject', {
@@ -0,0 +1,43 @@
1
+ import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
2
+
3
+ @Entity({ name: 'third_party_api_registry' })
4
+ export class ThirdPartyApiRegistry {
5
+ @PrimaryGeneratedColumn()
6
+ id: number;
7
+
8
+ @Column({nullable: true})
9
+ api_name: string;
10
+
11
+ @Column({nullable: true})
12
+ provider_name: string;
13
+
14
+ @Column({nullable: true})
15
+ base_url: string;
16
+
17
+ @Column({nullable: true})
18
+ endpoint: string;
19
+
20
+ @Column({nullable: true})
21
+ http_method: string;
22
+
23
+ @Column({type: 'json', nullable: true})
24
+ headers: string;
25
+
26
+ @Column({nullable: true})
27
+ request_payload_schema: string;
28
+
29
+ @Column({nullable: true})
30
+ auth_type: string;
31
+
32
+ @Column({nullable: true, type: 'json'})
33
+ auth_config: string;
34
+
35
+ @Column({nullable: true})
36
+ is_active: number;
37
+
38
+ @Column({nullable: true, type: 'datetime'})
39
+ created_date: Date;
40
+
41
+ @Column({nullable: true, type: 'datetime'})
42
+ modified_date: Date;
43
+ }
@@ -0,0 +1,20 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { InjectRepository } from '@nestjs/typeorm';
3
+ import { ThirdPartyApiRegistry } from '../entity/third-party-api-registry.entity';
4
+ import { Repository } from 'typeorm';
5
+
6
+ @Injectable()
7
+ export class ThirdPartyApiRegistryRepository {
8
+ constructor(
9
+ @InjectRepository(ThirdPartyApiRegistry)
10
+ private thirdPartyApiRegistryRepository: Repository<ThirdPartyApiRegistry>,
11
+ ) {}
12
+
13
+ async findById(id: number) {
14
+ return await this.thirdPartyApiRegistryRepository.findOne({
15
+ where: {
16
+ id: id,
17
+ },
18
+ });
19
+ }
20
+ }
@@ -0,0 +1,13 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { ThirdPartyApiRegistryRepository } from '../repository/third-party-api-registry.repository';
3
+
4
+ @Injectable()
5
+ export class ApiRegistryService {
6
+ constructor(
7
+ private readonly thirdPartyApiRegistryRepository: ThirdPartyApiRegistryRepository,
8
+ ) {}
9
+
10
+ async findById(id: number) {
11
+ return await this.thirdPartyApiRegistryRepository.findById(id);
12
+ }
13
+ }
@@ -0,0 +1,12 @@
1
+ import { Module } from '@nestjs/common';
2
+ import { TypeOrmModule } from '@nestjs/typeorm';
3
+ import { ThirdPartyApiRegistry } from './entity/third-party-api-registry.entity';
4
+ import { ThirdPartyApiRegistryRepository } from './repository/third-party-api-registry.repository';
5
+ import { ApiRegistryService } from './service/api-registry.service';
6
+
7
+ @Module({
8
+ imports: [TypeOrmModule.forFeature([ThirdPartyApiRegistry])],
9
+ providers: [ThirdPartyApiRegistryRepository, ApiRegistryService],
10
+ exports: [ApiRegistryService],
11
+ })
12
+ export class ThirdPartyModule {}