rez_core 1.0.47 → 1.0.49

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 (88) hide show
  1. package/data/master.xlsx +0 -0
  2. package/dist/constant/global.constant.d.ts +3 -0
  3. package/dist/constant/global.constant.js +4 -1
  4. package/dist/constant/global.constant.js.map +1 -1
  5. package/dist/module/master/service/master.service.d.ts +7 -1
  6. package/dist/module/master/service/master.service.js +72 -3
  7. package/dist/module/master/service/master.service.js.map +1 -1
  8. package/dist/module/meta/controller/entity.controller.d.ts +6 -2
  9. package/dist/module/meta/controller/entity.controller.js +13 -6
  10. package/dist/module/meta/controller/entity.controller.js.map +1 -1
  11. package/dist/module/meta/controller/media.controller.d.ts +1 -0
  12. package/dist/module/meta/controller/media.controller.js +27 -0
  13. package/dist/module/meta/controller/media.controller.js.map +1 -1
  14. package/dist/module/meta/entity/field-group.entity.d.ts +9 -0
  15. package/dist/module/meta/entity/field-group.entity.js +47 -0
  16. package/dist/module/meta/entity/field-group.entity.js.map +1 -0
  17. package/dist/module/meta/entity/school.entity.d.ts +8 -0
  18. package/dist/module/meta/entity/school.entity.js +44 -0
  19. package/dist/module/meta/entity/school.entity.js.map +1 -0
  20. package/dist/module/meta/entity/schoolAddress.entity.d.ts +9 -0
  21. package/dist/module/meta/entity/schoolAddress.entity.js +48 -0
  22. package/dist/module/meta/entity/schoolAddress.entity.js.map +1 -0
  23. package/dist/module/meta/entity/section-master.entity.d.ts +10 -0
  24. package/dist/module/meta/entity/section-master.entity.js +51 -0
  25. package/dist/module/meta/entity/section-master.entity.js.map +1 -0
  26. package/dist/module/meta/entity.module.js +19 -0
  27. package/dist/module/meta/entity.module.js.map +1 -1
  28. package/dist/module/meta/repository/attribute-master.repository.d.ts +1 -0
  29. package/dist/module/meta/repository/attribute-master.repository.js +7 -0
  30. package/dist/module/meta/repository/attribute-master.repository.js.map +1 -1
  31. package/dist/module/meta/service/attribute-master.service.d.ts +6 -0
  32. package/dist/module/meta/service/attribute-master.service.js +28 -0
  33. package/dist/module/meta/service/attribute-master.service.js.map +1 -0
  34. package/dist/module/meta/service/entity-list.service.js +1 -1
  35. package/dist/module/meta/service/entity-list.service.js.map +1 -1
  36. package/dist/module/meta/service/entity-master.service.d.ts +1 -0
  37. package/dist/module/meta/service/entity-master.service.js +6 -0
  38. package/dist/module/meta/service/entity-master.service.js.map +1 -1
  39. package/dist/module/meta/service/field-group.service.d.ts +26 -0
  40. package/dist/module/meta/service/field-group.service.js +78 -0
  41. package/dist/module/meta/service/field-group.service.js.map +1 -0
  42. package/dist/module/meta/service/media-data.service.d.ts +1 -0
  43. package/dist/module/meta/service/media-data.service.js +15 -0
  44. package/dist/module/meta/service/media-data.service.js.map +1 -1
  45. package/dist/module/meta/service/section-master.service.d.ts +26 -0
  46. package/dist/module/meta/service/section-master.service.js +78 -0
  47. package/dist/module/meta/service/section-master.service.js.map +1 -0
  48. package/dist/module/meta/service/view-master.service.d.ts +5 -1
  49. package/dist/module/meta/service/view-master.service.js +32 -2
  50. package/dist/module/meta/service/view-master.service.js.map +1 -1
  51. package/dist/module/module/controller/module-access.controller.d.ts +7 -1
  52. package/dist/module/module/controller/module-access.controller.js +19 -8
  53. package/dist/module/module/controller/module-access.controller.js.map +1 -1
  54. package/dist/module/module/repository/module-access.repository.d.ts +3 -2
  55. package/dist/module/module/repository/module-access.repository.js +30 -13
  56. package/dist/module/module/repository/module-access.repository.js.map +1 -1
  57. package/dist/module/module/service/module-access.service.d.ts +8 -3
  58. package/dist/module/module/service/module-access.service.js +35 -7
  59. package/dist/module/module/service/module-access.service.js.map +1 -1
  60. package/dist/module/user/entity/user-role-mapping.entity.d.ts +1 -0
  61. package/dist/module/user/entity/user-role-mapping.entity.js +6 -0
  62. package/dist/module/user/entity/user-role-mapping.entity.js.map +1 -1
  63. package/dist/module/user/service/role.service.js.map +1 -1
  64. package/dist/tsconfig.build.tsbuildinfo +1 -1
  65. package/package.json +1 -1
  66. package/src/constant/global.constant.ts +5 -1
  67. package/src/module/master/service/master.service.ts +98 -3
  68. package/src/module/meta/controller/entity.controller.ts +14 -3
  69. package/src/module/meta/controller/media.controller.ts +27 -1
  70. package/src/module/meta/entity/field-group.entity.ts +25 -0
  71. package/src/module/meta/entity/school.entity.ts +23 -0
  72. package/src/module/meta/entity/schoolAddress.entity.ts +25 -0
  73. package/src/module/meta/entity/section-master.entity.ts +28 -0
  74. package/src/module/meta/entity.module.ts +19 -0
  75. package/src/module/meta/repository/attribute-master.repository.ts +11 -1
  76. package/src/module/meta/service/attribute-master.service.ts +17 -0
  77. package/src/module/meta/service/entity-list.service.ts +1 -1
  78. package/src/module/meta/service/entity-master.service.ts +7 -0
  79. package/src/module/meta/service/field-group.service.ts +104 -0
  80. package/src/module/meta/service/media-data.service.ts +22 -9
  81. package/src/module/meta/service/section-master.service.ts +104 -0
  82. package/src/module/meta/service/view-master.service.ts +42 -4
  83. package/src/module/module/controller/module-access.controller.ts +16 -4
  84. package/src/module/module/repository/module-access.repository.ts +81 -47
  85. package/src/module/module/service/module-access.service.ts +60 -21
  86. package/src/module/user/entity/user-role-mapping.entity.ts +26 -21
  87. package/src/module/user/service/role.service.ts +1 -0
  88. package/src/resources/dev.properties.yaml +6 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "1.0.47",
3
+ "version": "1.0.49",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -9,6 +9,10 @@ export const ENTITYTYPE_VIEWMASTER = 'VMS';
9
9
  export const ENTITYTYPE_MEDIA = 'MDA';
10
10
  export const ENTITYTYPE_LISTMASTER = 'LMS';
11
11
  export const ENTITYTYPE_LISTMASTERITEMS = 'LMI';
12
+ export const ENTITYTYPE_SECTIONMASTER = 'SEC';
13
+ export const ENTITYTYPE_FIELDMASTER = 'FLD';
14
+ export const ENTITYTYPE_USRROLMAP = 'URM';
15
+
12
16
 
13
17
  export const STORAGETYPE_SINGLEJSON = 'singlejson';
14
18
  export const STORAGETYPE_COLUMN = 'column';
@@ -23,4 +27,4 @@ export const STATUS_PENDING = 'PENDING';
23
27
 
24
28
  // Entity Status
25
29
  export const ENTITYSTATUS_TO_BE_PUBLISHED = 'to_be_published';
26
- export const ENTITYSTATUS_PUBLISHED = 'published';
30
+ export const ENTITYSTATUS_PUBLISHED = 'published';
@@ -3,6 +3,9 @@ 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
5
  import { table } from 'console';
6
+ import { AttributeMasterService } from 'src/module/meta/service/attribute-master.service';
7
+ import { EntityMaster } from 'src/module/meta/entity/entity-master.entity';
8
+ import { EntityServiceImpl } from 'src/module/meta/service/entity-service-impl.service';
6
9
 
7
10
  interface ParentEntity {
8
11
  id: number;
@@ -14,7 +17,9 @@ export class MasterService {
14
17
  constructor(
15
18
  private readonly entityManager: EntityManager,
16
19
  private readonly entityMasterService: EntityMasterService,
20
+ private readonly attributeMasterService: AttributeMasterService,
17
21
  private readonly excelUtil: ExcelUtil,
22
+ private readonly entityServiceImpl: EntityServiceImpl,
18
23
  ) {}
19
24
 
20
25
  private readonly metaSheets = [
@@ -42,10 +47,65 @@ export class MasterService {
42
47
  },
43
48
  ];
44
49
 
50
+ private readonly dataSequence = [
51
+ {
52
+ table: 'cr_user',
53
+ unique_fields: ['code'],
54
+ },
55
+ {
56
+ table: 'cr_role',
57
+ unique_fields: ['code'],
58
+ },
59
+ {
60
+ table: 'cr_user_role_mapping',
61
+ unique_fields: ['user_id', 'role_id'],
62
+ },
63
+ {
64
+ table: 'eth_school',
65
+ unique_fields: ['code'],
66
+ },
67
+ {
68
+ table: 'eth_school_address',
69
+ unique_fields: ['code'],
70
+ },
71
+ ];
72
+
45
73
  private isMetaSheet(sheetName: string): boolean {
46
74
  return this.metaSheets.includes(sheetName.toLowerCase());
47
75
  }
48
76
 
77
+ private async resolveParent(row: any): Promise<void> {
78
+ const parentType = row.parent_type; // (Future use maybe)
79
+ const code = row.parent_id;
80
+
81
+ if (!code) {
82
+ throw new Error('Parent code is missing in the row');
83
+ }
84
+
85
+ const parentEntity: EntityMaster | null =
86
+ await this.entityMasterService.findByMappedEntityType(parentType);
87
+
88
+ const tableName: any = parentEntity?.db_table_name;
89
+ if (!tableName) {
90
+ throw new Error(`Table name not found for parent type ${parentType}`);
91
+ }
92
+
93
+ // Using RAW SQL Query
94
+ const entityData = await this.entityManager.query(
95
+ `SELECT * FROM ${tableName} WHERE code = ? LIMIT 1`,
96
+ [code],
97
+ );
98
+
99
+ if (!entityData || entityData.length === 0) {
100
+ throw new Error(
101
+ `Parent entity with code ${code} not found in table ${tableName}`,
102
+ );
103
+ }
104
+
105
+ // entityData is an array when using .query()
106
+ row.parent_id = entityData[0].id;
107
+ }
108
+
49
109
  async uploadMasterData(file) {
50
110
  const data = ExcelUtil.readExcel(file.buffer);
51
111
 
@@ -61,12 +121,47 @@ export class MasterService {
61
121
  console.log(`Processing sheet: ${table}`);
62
122
  await this.upsertData(table, unique_fields, sheetData);
63
123
  }
64
- else{
124
+ }
125
+ for (let i = 0; i < this.dataSequence.length; i++) {
126
+ const { table, unique_fields } = this.dataSequence[i];
127
+ const sheetData = data[table];
128
+
129
+ if (!sheetData) {
130
+ console.log(`Sheet ${table} not found in the Excel file.`);
131
+ continue;
132
+ }
133
+
134
+ const entityMasterData =
135
+ await this.entityMasterService.getEntityByTableName(table);
65
136
 
66
-
137
+ const attributes =
138
+ await this.attributeMasterService.findAttributesByMappedEntityType(
139
+ entityMasterData?.mapped_entity_type,
140
+ );
67
141
 
142
+ console.log(attributes,"((((((((((((((((((((((((((")
143
+ for (const row of sheetData) {
144
+ if (row.parent_type !== undefined && row.parent_id !== undefined) {
145
+ this.resolveParent(row);
146
+ }
147
+
148
+ for (const attribute of attributes) {
149
+ if (attribute.data_source_type === 'entity') {
150
+ console.log(attribute.data_source_type)
151
+ let entityMaster = await this.entityMasterService.getEntityData(
152
+ attribute.datasource_list,
153
+ );
154
+ const entityData = await this.entityManager.query(
155
+ `SELECT * FROM ${entityMaster.db_table_name} WHERE code = ? LIMIT 1`,
156
+ [row[attribute.attribute_key]],
157
+ );
158
+ row[attribute.attribute_key] = entityData[0].id;
159
+ }
160
+ }
68
161
  }
69
-
162
+
163
+ console.log(`Processing sheet: ${table}`);
164
+ await this.upsertData(table, unique_fields, sheetData);
70
165
  }
71
166
  return {
72
167
  message: 'Data uploaded successfully',
@@ -8,7 +8,8 @@ import {
8
8
  Post,
9
9
  Query,
10
10
  Res,
11
- UseGuards,
11
+ Req,
12
+ UseGuards, Inject,
12
13
  } from '@nestjs/common';
13
14
  import { EntityServiceImpl } from '../service/entity-service-impl.service';
14
15
  import { ReflectionHelper } from '../../../utils/service/reflection-helper.service';
@@ -18,6 +19,9 @@ import { BaseEntity } from '../entity/base-entity.entity';
18
19
  import { JwtAuthGuard } from '../../auth/guards/jwt.guard';
19
20
  import * as fs from 'fs';
20
21
  import * as path from 'path';
22
+ import { UserService } from '../../user/service/user.service';
23
+ import { ENTITYTYPE_USER } from '../../../constant/global.constant';
24
+ import { UserData } from '../../user/entity/user.entity';
21
25
 
22
26
  @UseGuards(JwtAuthGuard)
23
27
  @Controller('entity')
@@ -58,7 +62,11 @@ export class EntityController {
58
62
  @Body() entityData: BaseEntity,
59
63
  @Query('entity_type') entityType: string,
60
64
  @Res() res: Response,
65
+ @Req() req: Request & {user: any}
61
66
  ) {
67
+ let requestedUser = req.user;
68
+ let loggedInUser = await this.entityService.getEntityData(ENTITYTYPE_USER,requestedUser.id);
69
+
62
70
  if (!entityType) {
63
71
  throw new BadRequestException(
64
72
  'Query parameter "entity_type" is required',
@@ -75,7 +83,7 @@ export class EntityController {
75
83
  if (entityService) {
76
84
  return res
77
85
  .status(HttpStatus.OK)
78
- .json(await entityService.createEntity(entityData, null));
86
+ .json(await entityService.createEntity(entityData, loggedInUser as UserData));
79
87
  }
80
88
  }
81
89
 
@@ -85,7 +93,10 @@ export class EntityController {
85
93
  @Body() entityData: BaseEntity,
86
94
  @Query('entity_type') entityType: string,
87
95
  @Res() response: Response,
96
+ @Req() req: Request & {user: any}
88
97
  ) {
98
+ let requestedUser = req.user;
99
+ let loggedInUser = await this.entityService.getEntityData(ENTITYTYPE_USER,requestedUser.id);
89
100
  if (!entityType) {
90
101
  throw new BadRequestException(
91
102
  'Query parameter "entity_type" is required',
@@ -106,7 +117,7 @@ export class EntityController {
106
117
  }
107
118
  // let mergeEntity = JsonUtil.merge(existingEntity, entityData);
108
119
 
109
- entityData = await entityService.updateEntity(entityData, null);
120
+ entityData = await entityService.updateEntity(entityData, loggedInUser as UserData);
110
121
  return response.status(HttpStatus.OK).json(entityData);
111
122
  }
112
123
  }
@@ -4,17 +4,22 @@ import {
4
4
  HttpStatus,
5
5
  Post,
6
6
  Res,
7
+ Get,
8
+ Param,
7
9
  UseGuards,
8
10
  } from '@nestjs/common';
9
11
  import { MediaDataService } from '../service/media-data.service';
10
12
  import { JwtAuthGuard } from '../../auth/guards/jwt.guard';
11
- import { Response } from 'express';
13
+ import e, { Response } from 'express';
14
+ import { ENTITYTYPE_MEDIA } from 'src/constant/global.constant';
15
+ import { MediaData } from '../entity/media-data.entity';
12
16
 
13
17
  @Controller('media')
14
18
  // @UseGuards(JwtAuthGuard)
15
19
  export class MediaController {
16
20
  constructor(private readonly mediaDataService: MediaDataService) {}
17
21
 
22
+ // Method for initiating an upload
18
23
  @Post('initiate-upload')
19
24
  async initiateUpload(
20
25
  @Body()
@@ -42,4 +47,25 @@ export class MediaController {
42
47
  throw new Error('Something went wrong!');
43
48
  }
44
49
  }
50
+
51
+ // Method to fetch the download URL for a media file
52
+ @Get('download/:id')
53
+ async getDownloadUrl(@Param('id') id: number, @Res() res: Response) {
54
+ try {
55
+
56
+ const entityData = await this.mediaDataService.getEntityData(ENTITYTYPE_MEDIA, id);
57
+ let mediaData = entityData as MediaData;
58
+ const downloadUrl = await this.mediaDataService.getMediaDownloadUrl(mediaData.media_url);
59
+ res.status(HttpStatus.OK).json({
60
+ message: 'Download URL fetched successfully',
61
+ success: true,
62
+ data: { downloadUrl },
63
+ });
64
+ } catch (error) {
65
+ res.status(HttpStatus.INTERNAL_SERVER_ERROR).json({
66
+ message: error.message || 'Error fetching download URL',
67
+ success: false,
68
+ });
69
+ }
70
+ }
45
71
  }
@@ -0,0 +1,25 @@
1
+ import { ENTITYTYPE_FIELDMASTER } from 'src/constant/global.constant';
2
+ import { BaseEntity } from './base-entity.entity';
3
+ import { Column, Entity } from 'typeorm';
4
+
5
+ @Entity({ name: 'cr_field_group' })
6
+ export class FieldGroup extends BaseEntity {
7
+ constructor() {
8
+ super();
9
+ this.entity_type = ENTITYTYPE_FIELDMASTER;
10
+ }
11
+ @Column({ length: 50, nullable: true })
12
+ mapped_entity_type: string;
13
+
14
+ @Column({ length: 50, nullable: true })
15
+ field_type: string;
16
+
17
+ @Column({ nullable: true })
18
+ description: string;
19
+
20
+ @Column({ type: 'varchar', nullable: true })
21
+ label: string;
22
+
23
+ @Column({ type: 'int', nullable: true })
24
+ view_id: number;
25
+ }
@@ -0,0 +1,23 @@
1
+ import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
2
+
3
+ @Entity({ name: 'eth_school_temp' })
4
+ export class SchoolEntity {
5
+
6
+ @PrimaryGeneratedColumn()
7
+ id: number;
8
+
9
+ @Column({})
10
+ code: string;
11
+
12
+ @Column({})
13
+ name:string;
14
+
15
+ @Column({})
16
+ logo:string;
17
+
18
+ @Column({nullable:true})
19
+ parent_id:number;
20
+
21
+ @Column({nullable:true})
22
+ parent_type:string;
23
+ }
@@ -0,0 +1,25 @@
1
+ import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
2
+
3
+ @Entity({ name: 'eth_school_address_temp' })
4
+ export class SchoolAddressEntity {
5
+ @PrimaryGeneratedColumn()
6
+ id: number;
7
+
8
+ @Column({})
9
+ code: string;
10
+
11
+ @Column({})
12
+ city: string;
13
+
14
+ @Column({})
15
+ state: string;
16
+
17
+ @Column({})
18
+ school_id: number;
19
+
20
+ @Column({})
21
+ parent_type: string;
22
+
23
+ @Column({})
24
+ parent_id: number;
25
+ }
@@ -0,0 +1,28 @@
1
+ import { ENTITYTYPE_SECTIONMASTER } from 'src/constant/global.constant';
2
+ import { BaseEntity } from './base-entity.entity';
3
+ import { Column, Entity } from 'typeorm';
4
+
5
+ @Entity({ name: 'cr_section_master' })
6
+ export class SectionMaster extends BaseEntity {
7
+ constructor() {
8
+ super();
9
+ this.entity_type = ENTITYTYPE_SECTIONMASTER;
10
+ }
11
+ @Column({ length: 50, nullable: true })
12
+ mapped_entity_type: string;
13
+
14
+ @Column({ length: 50, nullable: true })
15
+ section_type: string;
16
+
17
+ @Column({ nullable: true })
18
+ description: string;
19
+
20
+ @Column({ type: 'varchar', nullable: true })
21
+ tooltip: string;
22
+
23
+ @Column({ type: 'int', nullable: true })
24
+ visible_in_add: number;
25
+
26
+ @Column({ type: 'int', nullable: true })
27
+ position: number;
28
+ }
@@ -24,6 +24,14 @@ import { MediaDataService } from './service/media-data.service';
24
24
  import { MediaDataRepository } from './repository/media-data.repository';
25
25
  import { MediaController } from './controller/media.controller';
26
26
  import { ViewMaster } from './entity/view-master.entity';
27
+ import { SchoolEntity } from './entity/school.entity';
28
+ import { SchoolAddressEntity } from './entity/schoolAddress.entity';
29
+ import { AttributeMasterService } from './service/attribute-master.service';
30
+ import { SectionMasterService } from './service/section-master.service';
31
+ import { SectionMaster } from './entity/section-master.entity';
32
+ import { FieldGroup } from './entity/field-group.entity';
33
+ import { FieldGroupService } from './service/field-group.service';
34
+ import { ViewMasterService } from './service/view-master.service';
27
35
 
28
36
  @Module({
29
37
  imports: [
@@ -35,6 +43,10 @@ import { ViewMaster } from './entity/view-master.entity';
35
43
  EntityTableColumn,
36
44
  MediaData,
37
45
  ViewMaster,
46
+ SchoolEntity,
47
+ SchoolAddressEntity,
48
+ SectionMaster,
49
+ FieldGroup,
38
50
  ]),
39
51
  UtilsModule,
40
52
  ],
@@ -52,6 +64,10 @@ import { ViewMaster } from './entity/view-master.entity';
52
64
  EntityListService,
53
65
  MediaDataRepository,
54
66
  MediaDataService,
67
+ AttributeMasterService,
68
+ SectionMasterService,
69
+ FieldGroupService,
70
+ { provide: 'ViewMasterService', useClass: ViewMasterService },
55
71
  ],
56
72
  exports: [
57
73
  EntityMasterService,
@@ -61,6 +77,9 @@ import { ViewMaster } from './entity/view-master.entity';
61
77
  EntityTableService,
62
78
  EntityTableColumnService,
63
79
  MediaDataService,
80
+ SectionMasterService,
81
+ FieldGroupService,
82
+ 'ViewMasterService',
64
83
  ],
65
84
  controllers: [EntityController, MasterController, MediaController],
66
85
  })
@@ -1,7 +1,7 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
  import { InjectRepository } from '@nestjs/typeorm';
3
3
  import { AttributeMaster } from '../entity/attribute-master.entity';
4
- import { Repository } from 'typeorm';
4
+ import { In, Repository } from 'typeorm';
5
5
 
6
6
  @Injectable()
7
7
  export class AttributeMasterRepository {
@@ -25,4 +25,14 @@ export class AttributeMasterRepository {
25
25
  },
26
26
  });
27
27
  }
28
+
29
+
30
+ async findAttributesByMappedEntityType(entityType: string): Promise<AttributeMaster[]> {
31
+ return await this.attributeMasterRepository.find({
32
+ where: {
33
+ mapped_entity_type: In([entityType, 'DEF']),
34
+ },
35
+ });
36
+ }
37
+
28
38
  }
@@ -0,0 +1,17 @@
1
+ import { Injectable } from "@nestjs/common";
2
+ import { InjectRepository } from "@nestjs/typeorm";
3
+ import { In } from "typeorm";
4
+ import { AttributeMasterRepository } from "../repository/attribute-master.repository";
5
+
6
+
7
+ @Injectable()
8
+ export class AttributeMasterService {
9
+ constructor(
10
+ private readonly attributeMasterRepository: AttributeMasterRepository,
11
+ ) {}
12
+
13
+ async findAttributesByMappedEntityType(entity_type){
14
+ return await this.attributeMasterRepository.findAttributesByMappedEntityType(entity_type);
15
+ }
16
+
17
+ }
@@ -155,7 +155,7 @@ export class EntityListService {
155
155
  FROM ${tableName} WHERE 1=1 `;
156
156
  const argsObjectList: any[] = [];
157
157
  if (parentId) {
158
- query += `AND parent_id = ? AND parent_type = ? `;
158
+ query += ` AND parent_id = ? AND parent_type = ? `;
159
159
  argsObjectList.push(parentId);
160
160
  argsObjectList.push(parentType);
161
161
  }
@@ -24,6 +24,13 @@ export class EntityMasterService {
24
24
  return entityMaster;
25
25
  }
26
26
 
27
+ async getEntityByTableName(tableName: string) {
28
+ const entityMaster = await this.entityMasterRepository.findOne({
29
+ where: { db_table_name: tableName },
30
+ });
31
+ return entityMaster;
32
+ }
33
+
27
34
  async save(entityMaster: EntityMaster) {
28
35
  return await this.entityMasterRepository.save(entityMaster);
29
36
  }
@@ -0,0 +1,104 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { EntityServiceImpl } from './entity-service-impl.service';
3
+ import { BaseEntity } from '../entity/base-entity.entity';
4
+ import { UserData } from '../../user/entity/user.entity';
5
+ import { EntityManager } from 'typeorm';
6
+ import { ViewMaster } from '../entity/view-master.entity';
7
+
8
+ @Injectable()
9
+ export class FieldGroupService extends EntityServiceImpl {
10
+ constructor() {
11
+ super();
12
+ }
13
+
14
+ async createEntity(
15
+ entityData: BaseEntity,
16
+ loggedInUser: UserData | null,
17
+ manager?: EntityManager,
18
+ ): Promise<BaseEntity> {
19
+ const entityMaster = await this.entityMasterService.getEntityData(
20
+ entityData.entity_type,
21
+ );
22
+ entityData.parent_id = entityMaster.id;
23
+ entityData.parent_type = entityMaster.entity_type;
24
+
25
+ const savedEntity = await super.createEntity(
26
+ entityData,
27
+ loggedInUser,
28
+ manager,
29
+ );
30
+ return savedEntity;
31
+ }
32
+
33
+ async updateEntity(
34
+ entityData: ViewMaster,
35
+ loggedInUserData: UserData | null,
36
+ ): Promise<BaseEntity> {
37
+ return entityData;
38
+ }
39
+
40
+ parseLayout(layoutJson: any) {
41
+ const stepsData: {
42
+ stepType: string;
43
+ stepId: string;
44
+ stepLabel: string;
45
+ stepPosition: number;
46
+ fields: {
47
+ type: string;
48
+ label: string;
49
+ id: string;
50
+ }[];
51
+ }[] = [];
52
+
53
+ if (layoutJson?.form?.children && Array.isArray(layoutJson.form.children)) {
54
+ const firstChild = layoutJson.form.children[0];
55
+ console.log('First Child:', firstChild);
56
+
57
+ if (firstChild.type === 'wizard' && Array.isArray(firstChild.steps)) {
58
+ console.log('Wizard Steps:', firstChild.steps);
59
+ let i = 0;
60
+ for (const step of firstChild.steps) {
61
+ if (step.type === 'step') {
62
+ const fields = this.extractFields(step.fields);
63
+
64
+ stepsData.push({
65
+ stepType: step.type,
66
+ stepId: step.id,
67
+ stepLabel: step.label,
68
+ stepPosition: ++i,
69
+ fields: fields,
70
+ });
71
+ }
72
+ }
73
+ }
74
+ }
75
+ return stepsData;
76
+ }
77
+
78
+ extractFields(fieldsArray: any[]): {
79
+ type: string;
80
+ label: string;
81
+ id: string;
82
+ }[] {
83
+ const extractedFields: { type: string; label: string; id: string }[] = [];
84
+
85
+ function traverse(fields: any[]) {
86
+ for (const field of fields) {
87
+ if (field.type === 'field-set') {
88
+ extractedFields.push({
89
+ type: field.type,
90
+ label: field.label || 'No Label',
91
+ id: field.id || 'No ID',
92
+ });
93
+ }
94
+ if (Array.isArray(field.fields)) {
95
+ traverse(field.fields); // 📢 Recursive call
96
+ }
97
+ }
98
+ }
99
+
100
+ traverse(fieldsArray);
101
+
102
+ return extractedFields;
103
+ }
104
+ }
@@ -10,17 +10,16 @@ import { v4 as uuidv4 } from 'uuid';
10
10
  @Injectable()
11
11
  export class MediaDataService extends EntityServiceImpl {
12
12
 
13
-
14
13
  constructor(
15
14
  private readonly configService: ConfigService,
16
15
  private readonly mediaRepository: MediaDataRepository,
17
16
  ) {
18
17
  super();
19
18
  }
20
-
21
- s3AccessKeyID=this.configService.get('AWS.S3.AWS_ACCESS_KEY_ID')
22
- s3AccessKeySecret=this.configService.get('AWS.S3.AWS_SECRET_KEY')
23
- s3Region=this.configService.get('AWS.S3.AWS_REGION')
19
+
20
+ s3AccessKeyID = this.configService.get('AWS.S3.AWS_ACCESS_KEY_ID');
21
+ s3AccessKeySecret = this.configService.get('AWS.S3.AWS_SECRET_KEY');
22
+ s3Region = this.configService.get('AWS.S3.AWS_REGION');
24
23
  bucketName = this.configService.get<string>('AWS.S3.BUCKET_NAME');
25
24
 
26
25
  s3 = new S3({
@@ -29,15 +28,13 @@ export class MediaDataService extends EntityServiceImpl {
29
28
  region: this.s3Region,
30
29
  signatureVersion: 'v4',
31
30
  });
32
-
33
-
31
+
34
32
  async generateMediaUploadDetails(
35
33
  fileName: string,
36
34
  mappedAttributeKey: string,
37
35
  mappedEntityType?: string,
38
36
  mappedEntityId?: number,
39
37
  ) {
40
-
41
38
  if (!fileName || !mappedAttributeKey) {
42
39
  return null;
43
40
  }
@@ -45,7 +42,7 @@ export class MediaDataService extends EntityServiceImpl {
45
42
 
46
43
  const id = uuidv4();
47
44
  const s3Key = `uploads/${id}.${ext}`;
48
- console.log(s3Key)
45
+ console.log(s3Key);
49
46
 
50
47
  const uploadUrl = await this.s3.getSignedUrlPromise('putObject', {
51
48
  Bucket: this.bucketName,
@@ -63,6 +60,7 @@ export class MediaDataService extends EntityServiceImpl {
63
60
  if (mappedEntityId) {
64
61
  mediaData.mapped_entity_id = mappedEntityId;
65
62
  }
63
+ mediaData.media_url = s3Key;
66
64
 
67
65
  let savedEntity = await super.createEntity(mediaData, null);
68
66
 
@@ -115,4 +113,19 @@ export class MediaDataService extends EntityServiceImpl {
115
113
  };
116
114
  return map[ext] || 'application/octet-stream';
117
115
  }
116
+
117
+ // New method to get the signed URL for the media (download link)
118
+ async getMediaDownloadUrl(s3Key: string): Promise<string> {
119
+ try {
120
+ const signedUrl = await this.s3.getSignedUrlPromise('getObject', {
121
+ Bucket: this.bucketName,
122
+ Key: s3Key,
123
+ Expires: 60 * 5, // URL valid for 5 mins
124
+ });
125
+ return signedUrl;
126
+ } catch (error) {
127
+ console.error('Error generating signed URL for media:', error);
128
+ throw new Error('Failed to generate signed URL');
129
+ }
130
+ }
118
131
  }