@solidstarters/solid-core 1.2.154 → 1.2.156

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 (44) hide show
  1. package/dist/dtos/create-list-of-values.dto.d.ts +2 -0
  2. package/dist/dtos/create-list-of-values.dto.d.ts.map +1 -1
  3. package/dist/dtos/create-list-of-values.dto.js +12 -1
  4. package/dist/dtos/create-list-of-values.dto.js.map +1 -1
  5. package/dist/dtos/update-list-of-values.dto.d.ts +2 -0
  6. package/dist/dtos/update-list-of-values.dto.d.ts.map +1 -1
  7. package/dist/dtos/update-list-of-values.dto.js +12 -1
  8. package/dist/dtos/update-list-of-values.dto.js.map +1 -1
  9. package/dist/entities/list-of-values.entity.d.ts +2 -0
  10. package/dist/entities/list-of-values.entity.d.ts.map +1 -1
  11. package/dist/entities/list-of-values.entity.js +7 -1
  12. package/dist/entities/list-of-values.entity.js.map +1 -1
  13. package/dist/helpers/cors.helper.js +1 -1
  14. package/dist/helpers/cors.helper.js.map +1 -1
  15. package/dist/mappers/list-of-values-mapper.d.ts +5 -0
  16. package/dist/mappers/list-of-values-mapper.d.ts.map +1 -0
  17. package/dist/mappers/list-of-values-mapper.js +28 -0
  18. package/dist/mappers/list-of-values-mapper.js.map +1 -0
  19. package/dist/seeders/module-metadata-seeder.service.js +1 -1
  20. package/dist/seeders/module-metadata-seeder.service.js.map +1 -1
  21. package/dist/seeders/seed-data/solid-core-metadata.json +27 -137
  22. package/dist/services/list-of-values-metadata.service.d.ts +34 -0
  23. package/dist/services/list-of-values-metadata.service.d.ts.map +1 -0
  24. package/dist/services/list-of-values-metadata.service.js +213 -0
  25. package/dist/services/list-of-values-metadata.service.js.map +1 -0
  26. package/dist/solid-core.module.d.ts.map +1 -1
  27. package/dist/solid-core.module.js +6 -0
  28. package/dist/solid-core.module.js.map +1 -1
  29. package/dist/subscribers/list-of-values-metadata.subscriber.d.ts +18 -0
  30. package/dist/subscribers/list-of-values-metadata.subscriber.d.ts.map +1 -0
  31. package/dist/subscribers/list-of-values-metadata.subscriber.js +101 -0
  32. package/dist/subscribers/list-of-values-metadata.subscriber.js.map +1 -0
  33. package/dist/tsconfig.tsbuildinfo +1 -1
  34. package/package.json +1 -1
  35. package/src/dtos/create-list-of-values.dto.ts +7 -0
  36. package/src/dtos/update-list-of-values.dto.ts +8 -1
  37. package/src/entities/list-of-values.entity.ts +5 -1
  38. package/src/helpers/cors.helper.ts +1 -1
  39. package/src/mappers/list-of-values-mapper.ts +17 -0
  40. package/src/seeders/module-metadata-seeder.service.ts +1 -1
  41. package/src/seeders/seed-data/solid-core-metadata.json +27 -137
  42. package/src/services/list-of-values-metadata.service.ts +219 -0
  43. package/src/solid-core.module.ts +6 -0
  44. package/src/subscribers/list-of-values-metadata.subscriber.ts +115 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidstarters/solid-core",
3
- "version": "1.2.154",
3
+ "version": "1.2.156",
4
4
  "description": "This module is a NestJS module containing all the required core providers required by a Solid application",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,4 +27,11 @@ export class CreateListOfValuesDto {
27
27
  @IsInt()
28
28
  @ApiProperty()
29
29
  sequence: number;
30
+ @IsOptional()
31
+ @IsInt()
32
+ @ApiProperty()
33
+ moduleId: number;
34
+ @IsString()
35
+ @IsOptional()
36
+ moduleUserKey: string;
30
37
  }
@@ -1,4 +1,4 @@
1
- import { IsInt,IsOptional, IsString, IsNotEmpty, IsBoolean } from 'class-validator';
1
+ import { IsInt, IsOptional, IsString, IsNotEmpty, IsBoolean } from 'class-validator';
2
2
  import { ApiProperty } from '@nestjs/swagger';
3
3
 
4
4
  export class UpdateListOfValuesDto {
@@ -33,4 +33,11 @@ export class UpdateListOfValuesDto {
33
33
  @IsInt()
34
34
  @ApiProperty()
35
35
  sequence: number;
36
+ @IsOptional()
37
+ @IsInt()
38
+ @ApiProperty()
39
+ moduleId: number;
40
+ @IsString()
41
+ @IsOptional()
42
+ moduleUserKey: string;
36
43
  }
@@ -1,5 +1,6 @@
1
1
  import { CommonEntity } from 'src/entities/common.entity'
2
- import {Entity, Column} from 'typeorm'
2
+ import { Entity, Column, ManyToOne, JoinColumn } from 'typeorm'
3
+ import { ModuleMetadata } from 'src/entities/module-metadata.entity'
3
4
 
4
5
  @Entity("ss_list_of_values")
5
6
  export class ListOfValues extends CommonEntity {
@@ -15,4 +16,7 @@ export class ListOfValues extends CommonEntity {
15
16
  default: boolean = false;
16
17
  @Column({ type: "int", nullable: true })
17
18
  sequence: number;
19
+ @ManyToOne(() => ModuleMetadata, { onDelete: "CASCADE", nullable: true })
20
+ @JoinColumn()
21
+ module: ModuleMetadata;
18
22
  }
@@ -3,7 +3,7 @@ import { ConfigService } from '@nestjs/config';
3
3
 
4
4
  /** Build CorsOptions from env; supports wildcards like https://*.example.com */
5
5
  export function buildDefaultCorsOptions(configService: ConfigService): CorsOptions {
6
- const rawOrigins = configService.get<string>('CORS_ORIGINS') ?? '';
6
+ const rawOrigins = configService.get<string>('SECURITY_CORS_ORIGINS') ?? '*';
7
7
  const allowed = rawOrigins.split(',').map(s => s.trim()).filter(Boolean);
8
8
 
9
9
  const escapeRx = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
@@ -0,0 +1,17 @@
1
+ import { Injectable } from "@nestjs/common";
2
+ import { ListOfValues } from "src/entities/list-of-values.entity";
3
+
4
+ @Injectable()
5
+ export class ListOfValuesMapper {
6
+ toDto(listOfValue: ListOfValues): any {
7
+ return {
8
+ type: listOfValue.type,
9
+ value: listOfValue.value,
10
+ display: listOfValue.display,
11
+ description: listOfValue.description,
12
+ default: listOfValue.default,
13
+ sequence: listOfValue.sequence,
14
+ module: listOfValue.module ? listOfValue.module.id : null
15
+ };
16
+ }
17
+ }
@@ -584,7 +584,7 @@ export class ModuleMetadataSeederService {
584
584
  return;
585
585
  }
586
586
  for (let j = 0; j < listOfValuesDto.length; j++) {
587
- await this.listOfValuesService.upsert(listOfValuesDto);
587
+ await this.listOfValuesService.upsert(listOfValuesDto[j]);
588
588
  }
589
589
  }
590
590
 
@@ -3642,6 +3642,23 @@
3642
3642
  "private": false,
3643
3643
  "encrypt": false,
3644
3644
  "isSystem": false
3645
+ },
3646
+ {
3647
+ "name": "module",
3648
+ "displayName": "Module",
3649
+ "type": "relation",
3650
+ "ormType": "integer",
3651
+ "required": false,
3652
+ "unique": false,
3653
+ "index": false,
3654
+ "private": false,
3655
+ "encrypt": false,
3656
+ "relationType": "many-to-one",
3657
+ "relationCreateInverse": false,
3658
+ "relationCoModelSingularName": "moduleMetadata",
3659
+ "relationModelModuleName": "solid-core",
3660
+ "relationCascade": "cascade",
3661
+ "isSystem": true
3645
3662
  }
3646
3663
  ]
3647
3664
  },
@@ -6459,73 +6476,6 @@
6459
6476
  ]
6460
6477
  }
6461
6478
  },
6462
- {
6463
- "name": "listOfValues-list-view",
6464
- "displayName": "List of Values list view",
6465
- "type": "list",
6466
- "context": "{}",
6467
- "moduleUserKey": "solid-core",
6468
- "modelUserKey": "listOfValues",
6469
- "layout": {
6470
- "type": "list",
6471
- "attrs": {
6472
- "pagination": true,
6473
- "pageSizeOptions": [
6474
- 10,
6475
- 25,
6476
- 50
6477
- ],
6478
- "enableGlobalSearch": true,
6479
- "create": true,
6480
- "edit": true,
6481
- "delete": true
6482
- },
6483
- "children": [
6484
- {
6485
- "type": "field",
6486
- "attrs": {
6487
- "name": "type",
6488
- "isSearchable": true
6489
- }
6490
- },
6491
- {
6492
- "type": "field",
6493
- "attrs": {
6494
- "name": "value",
6495
- "isSearchable": true
6496
- }
6497
- },
6498
- {
6499
- "type": "field",
6500
- "attrs": {
6501
- "name": "display",
6502
- "isSearchable": true
6503
- }
6504
- },
6505
- {
6506
- "type": "field",
6507
- "attrs": {
6508
- "name": "description",
6509
- "isSearchable": true
6510
- }
6511
- },
6512
- {
6513
- "type": "field",
6514
- "attrs": {
6515
- "name": "default",
6516
- "isSearchable": true
6517
- }
6518
- },
6519
- {
6520
- "type": "field",
6521
- "attrs": {
6522
- "name": "sequence",
6523
- "isSearchable": true
6524
- }
6525
- }
6526
- ]
6527
- }
6528
- },
6529
6479
  {
6530
6480
  "name": "listOfValues-form-view",
6531
6481
  "displayName": "List of Values form view",
@@ -6590,6 +6540,12 @@
6590
6540
  "attrs": {
6591
6541
  "name": "sequence"
6592
6542
  }
6543
+ },
6544
+ {
6545
+ "type": "field",
6546
+ "attrs": {
6547
+ "name": "module"
6548
+ }
6593
6549
  }
6594
6550
  ]
6595
6551
  }
@@ -6899,78 +6855,12 @@
6899
6855
  "name": "sequence",
6900
6856
  "isSearchable": true
6901
6857
  }
6902
- }
6903
- ]
6904
- }
6905
- },
6906
- {
6907
- "name": "listOfValues-form-view",
6908
- "displayName": "List of Values form view",
6909
- "type": "form",
6910
- "context": "{}",
6911
- "moduleUserKey": "solid-core",
6912
- "modelUserKey": "listOfValues",
6913
- "layout": {
6914
- "type": "form",
6915
- "attrs": {
6916
- "name": "form-1",
6917
- "label": "Solid List of Values Model",
6918
- "className": "grid"
6919
- },
6920
- "children": [
6858
+ },
6921
6859
  {
6922
- "type": "sheet",
6860
+ "type": "field",
6923
6861
  "attrs": {
6924
- "name": "sheet-1"
6925
- },
6926
- "children": [
6927
- {
6928
- "type": "group",
6929
- "attrs": {
6930
- "name": "group-1",
6931
- "label": "",
6932
- "className": "col-6"
6933
- },
6934
- "children": [
6935
- {
6936
- "type": "field",
6937
- "attrs": {
6938
- "name": "type"
6939
- }
6940
- },
6941
- {
6942
- "type": "field",
6943
- "attrs": {
6944
- "name": "value"
6945
- }
6946
- },
6947
- {
6948
- "type": "field",
6949
- "attrs": {
6950
- "name": "display"
6951
- }
6952
- },
6953
- {
6954
- "type": "field",
6955
- "attrs": {
6956
- "name": "description"
6957
- }
6958
- },
6959
- {
6960
- "type": "field",
6961
- "attrs": {
6962
- "name": "default"
6963
- }
6964
- },
6965
- {
6966
- "type": "field",
6967
- "attrs": {
6968
- "name": "sequence"
6969
- }
6970
- }
6971
- ]
6972
- }
6973
- ]
6862
+ "name": "module"
6863
+ }
6974
6864
  }
6975
6865
  ]
6976
6866
  }
@@ -0,0 +1,219 @@
1
+ import { Injectable, Logger } from '@nestjs/common';
2
+ import { DiscoveryService, ModuleRef } from "@nestjs/core";
3
+ import { InjectEntityManager, InjectRepository } from '@nestjs/typeorm';
4
+ import { EntityManager, Repository } from 'typeorm';
5
+
6
+ import { ConfigService } from '@nestjs/config';
7
+ import { CrudHelperService } from 'src/services/crud-helper.service';
8
+ import { CRUDService } from 'src/services/crud.service';
9
+ import { FileService } from 'src/services/file.service';
10
+ import { ModelMetadataService } from 'src/services/model-metadata.service';
11
+ import { ModuleMetadataService } from 'src/services/module-metadata.service';
12
+
13
+
14
+ import * as fs from 'fs/promises'; // Use the Promise-based version of fs for async/await
15
+ import { ModuleMetadataHelperService } from 'src/helpers/module-metadata-helper.service';
16
+
17
+ import { ListOfValues } from 'src/entities/list-of-values.entity';
18
+ import { ListOfValuesMapper } from 'src/mappers/list-of-values-mapper';
19
+
20
+
21
+
22
+ @Injectable()
23
+ export class ListOfValuesMetadataService extends CRUDService<ListOfValues> {
24
+ private readonly logger = new Logger(this.constructor.name);
25
+ constructor(
26
+ readonly modelMetadataService: ModelMetadataService,
27
+ readonly moduleMetadataService: ModuleMetadataService,
28
+ readonly configService: ConfigService,
29
+ readonly fileService: FileService,
30
+ readonly discoveryService: DiscoveryService,
31
+ readonly crudHelperService: CrudHelperService,
32
+ readonly listOfValuesMapper: ListOfValuesMapper,
33
+ @InjectEntityManager()
34
+ readonly entityManager: EntityManager,
35
+ @InjectRepository(ListOfValues, 'default')
36
+ readonly repo: Repository<ListOfValues>,
37
+ readonly moduleRef: ModuleRef,
38
+ readonly moduleMetadataHelperService: ModuleMetadataHelperService,
39
+
40
+ ) {
41
+ super(modelMetadataService, moduleMetadataService, configService, fileService, discoveryService, crudHelperService, entityManager, repo, 'listOfValues', 'solid-core', moduleRef);
42
+ }
43
+
44
+ async saveListofValuesToConfig(entity: ListOfValues) {
45
+ if (!entity) {
46
+ this.logger.debug('No entity found in the ListofValuesSubscriber saveListofvalueToConfig method');
47
+ return;
48
+ }
49
+
50
+ // Validate list of value details
51
+ const listofvalue = entity as ListOfValues;
52
+ const moduleMetadata = entity.module;
53
+ if (!moduleMetadata) {
54
+ throw new Error(`Module metadata not found for listofvalue id ${entity.id}`);
55
+ }
56
+
57
+ // Get config file details
58
+ const { filePath, metaData } = await this.getConfigFileDetails(moduleMetadata.name); // sting expected module name
59
+ if (!filePath || !metaData) {
60
+ throw new Error(`Configuration details not found for module: ${moduleMetadata.name}`);
61
+ }
62
+
63
+ // Write the listofvalue to the config file
64
+ await this.writeToConfig(metaData, listofvalue, filePath);
65
+ }
66
+
67
+ async updateListofValuesToConfig(oldentity: ListOfValues, entity: ListOfValues) {
68
+ if (!entity) {
69
+ this.logger.debug('No entity found in the ListofValuesSubscriber saveListofvalueToConfig method');
70
+ return;
71
+ }
72
+
73
+ // Validate list of value details
74
+ const oldlistofvalue = oldentity as ListOfValues;
75
+ const listofvalue = entity as ListOfValues;
76
+ const moduleMetadata = entity.module;
77
+ if (!moduleMetadata) {
78
+ throw new Error(`Module metadata not found for listofvalue id ${entity.id}`);
79
+ }
80
+
81
+ // Get config file details
82
+ const { filePath, metaData } = await this.getConfigFileDetails(moduleMetadata.name); // sting expected module name
83
+ if (!filePath || !metaData) {
84
+ throw new Error(`Configuration details not found for module: ${moduleMetadata.name}`);
85
+ }
86
+
87
+ // Write the listofvalue to the config file
88
+ await this.updateToConfig(metaData, oldlistofvalue, listofvalue, filePath);
89
+ }
90
+
91
+ async deleteListOfValuesFromConfig(entity: ListOfValues) {
92
+ if (!entity) {
93
+ this.logger.debug('No entity found in the ListofValuesSubscriber saveListofvalueToConfig method');
94
+ return;
95
+ }
96
+
97
+ // Validate list of value details
98
+ const listofvalue = entity as ListOfValues;
99
+ const moduleMetadata = entity.module;
100
+ if (!moduleMetadata) {
101
+ throw new Error(`Module metadata not found for listofvalue id ${entity.id}`);
102
+ }
103
+
104
+ // Get config file details
105
+ const { filePath, metaData } = await this.getConfigFileDetails(moduleMetadata.name); // sting expected module name
106
+ if (!filePath || !metaData) {
107
+ throw new Error(`Configuration details not found for module: ${moduleMetadata.name}`);
108
+ }
109
+
110
+ // delete the listofvalue to the config file
111
+ await this.deleteFromConfig(metaData, listofvalue, filePath);
112
+ }
113
+
114
+
115
+
116
+ private async getConfigFileDetails(moduleName: string): Promise<{ filePath: string; metaData: any }> {
117
+ const filePath = await this.moduleMetadataHelperService.getModuleMetadataFilePath(moduleName);
118
+ try {
119
+ await fs.access(filePath);
120
+ } catch (error) {
121
+ throw new Error(`Configuration file not found for module: ${moduleName}`);
122
+ }
123
+ const metaData = await this.moduleMetadataHelperService.getModuleMetadataConfiguration(filePath);
124
+ return { filePath, metaData };
125
+ }
126
+
127
+ private async writeToConfig(metaData: any, listofvalues: ListOfValues, filePath: string) {
128
+ const dto = await this.listOfValuesMapper.toDto(listofvalues);
129
+
130
+ if (!Array.isArray(metaData.listOfValues)) {
131
+ metaData.listOfValues = [];
132
+ }
133
+
134
+ // Match by type + value + module
135
+ const existingIndex = metaData.listOfValues.findIndex(
136
+ (item: { type: string; value: string; module: number }) =>
137
+ item.type === dto.type &&
138
+ item.value === dto.value &&
139
+ item.module === dto.module
140
+ );
141
+
142
+ if (existingIndex !== -1) {
143
+ // Replace existing entry
144
+ metaData.listOfValues[existingIndex] = dto;
145
+ } else {
146
+ // Insert new entry
147
+ // metaData.listOfValues.unshift(dto);
148
+
149
+ if (metaData.listOfValues.length === 0) {
150
+ // Case 1: Empty array → add first item
151
+ metaData.listOfValues.push(dto);
152
+ } else {
153
+ // Case 2: Insert new item right after index 0
154
+ metaData.listOfValues.unshift(dto);
155
+ }
156
+
157
+ }
158
+
159
+ const updatedContent = JSON.stringify(metaData, null, 2);
160
+ await fs.writeFile(filePath, updatedContent);
161
+ }
162
+
163
+ private async updateToConfig(metaData: any, oldlistofvalues: ListOfValues, listofvalues: ListOfValues, filePath: string) {
164
+ const newvalue = await this.listOfValuesMapper.toDto(listofvalues);
165
+ const oldvalue = await this.listOfValuesMapper.toDto(oldlistofvalues);
166
+
167
+ if (!Array.isArray(metaData.listOfValues)) {
168
+ metaData.listOfValues = [];
169
+ }
170
+
171
+ const searchType = oldvalue.type || newvalue.type;
172
+ const searchValue = oldvalue.value || newvalue.value;
173
+ const searchModule = oldvalue.module || newvalue.module;
174
+
175
+ const existingIndex = metaData.listOfValues.findIndex(
176
+ (item: { type: string; value: string; module: number }) =>
177
+ item.type === searchType && item.value === searchValue && item.module === searchModule
178
+ );
179
+ if (existingIndex !== -1) {
180
+ // Replace existing match
181
+ metaData.listOfValues[existingIndex] = newvalue;
182
+ }
183
+
184
+ const updatedContent = JSON.stringify(metaData, null, 2);
185
+ await fs.writeFile(filePath, updatedContent);
186
+ }
187
+
188
+
189
+ private async deleteFromConfig(metaData: any, listofvalues: ListOfValues, filePath: string) {
190
+ const dto = await this.listOfValuesMapper.toDto(listofvalues);
191
+
192
+ if (!Array.isArray(metaData.listOfValues)) {
193
+ metaData.listOfValues = [];
194
+ }
195
+
196
+ // Match by type + value + module
197
+ const existingIndex = metaData.listOfValues.findIndex(
198
+ (item: { type: string; value: string; module: number }) =>
199
+ item.type === dto.type &&
200
+ item.value === dto.value &&
201
+ item.module === dto.module
202
+ );
203
+
204
+ if (existingIndex !== -1) {
205
+ // Remove the item
206
+ metaData.listOfValues.splice(existingIndex, 1);
207
+ this.logger.debug(`Deleted LOV ${dto.type}:${dto.value} (module ${dto.module}) from config`);
208
+ } else {
209
+ this.logger.warn(
210
+ `LOV ${dto.type}:${dto.value} (module ${dto.module}) not found in config during delete`
211
+ );
212
+ }
213
+ const updatedContent = JSON.stringify(metaData, null, 2);
214
+ await fs.writeFile(filePath, updatedContent);
215
+
216
+ }
217
+
218
+
219
+ }
@@ -266,6 +266,9 @@ import { NoopsEntityComputedFieldProviderService } from './services/computed-fie
266
266
  import { ScheduledJobRepository } from './repository/scheduled-job.repository';
267
267
  import { ScheduledJobSubscriber } from './subscribers/scheduled-job.subscriber';
268
268
  import { AlphaNumExternalIdComputationProvider } from './services/computed-fields/entity/alpha-num-external-id-computed-field-provider';
269
+ import { ListOfValuesMapper } from './mappers/list-of-values-mapper';
270
+ import { ListOfValuesMetadataSubscriber } from './subscribers/list-of-values-metadata.subscriber';
271
+ import { ListOfValuesMetadataService } from './services/list-of-values-metadata.service';
269
272
  import { MailFactory } from './factories/mail.factory';
270
273
  import { TwilioSMSService } from './services/sms/TwilioSMSService';
271
274
  import { PollerService } from './services/poller.service';
@@ -587,6 +590,9 @@ import { ChatterMessageDetailsRepository } from './repository/chatter-message-de
587
590
  ScheduledJobRepository,
588
591
  ScheduledJobSubscriber,
589
592
  AlphaNumExternalIdComputationProvider,
593
+ ListOfValuesMetadataService,
594
+ ListOfValuesMetadataSubscriber,
595
+ ListOfValuesMapper,
590
596
  MailFactory,
591
597
  ChatterMessageRepository,
592
598
  ChatterMessageDetailsRepository,
@@ -0,0 +1,115 @@
1
+ import { Injectable, Logger } from '@nestjs/common';
2
+ import { InjectDataSource } from "@nestjs/typeorm";
3
+ import { ListOfValues } from 'src/entities/list-of-values.entity';
4
+ import { ModuleMetadataHelperService } from "src/helpers/module-metadata-helper.service";
5
+ import { ListOfValuesMetadataService } from 'src/services/list-of-values-metadata.service';
6
+ import { DataSource, EntityManager, EntitySubscriberInterface, InsertEvent, RemoveEvent, UpdateEvent } from "typeorm";
7
+
8
+ @Injectable()
9
+ export class ListOfValuesMetadataSubscriber implements EntitySubscriberInterface<ListOfValues> {
10
+ private readonly logger = new Logger(this.constructor.name);
11
+ constructor(
12
+ @InjectDataSource()
13
+ private readonly dataSource: DataSource,
14
+ readonly moduleMetadataHelperService: ModuleMetadataHelperService,
15
+ readonly listOfValuesMetadataService: ListOfValuesMetadataService,
16
+ ) {
17
+ this.dataSource.subscribers.push(this);
18
+ }
19
+
20
+ listenTo() {
21
+ return ListOfValues;
22
+ }
23
+
24
+ async afterInsert(event: InsertEvent<ListOfValues>) {
25
+ if (!event.entity) {
26
+ this.logger.debug('No listofvalue entity found in the ListofValueSubscriber afterInsert method');
27
+ return;
28
+ }
29
+ await this.saveListOfValuesToConfig(event.entity, event.queryRunner.manager);
30
+ }
31
+
32
+ async afterUpdate(event: UpdateEvent<ListOfValues>) {
33
+ if (!event.entity) {
34
+ this.logger.debug('No listofvalue entity found in the ListofValueSubscriber afterInsert method');
35
+ return;
36
+ }
37
+
38
+ //@ts-ignore
39
+ await this.updateListOfValuesToConfig(event.databaseEntity, event.entity, event.queryRunner.manager);
40
+ }
41
+
42
+ // async beforeRemove(event: RemoveEvent<ListOfValues>) {
43
+ // if (!event.entity) {
44
+ // this.logger.debug('No listofvalue entity found in the ListofValueSubscriber beforeRemove method');
45
+ // return;
46
+ // }
47
+
48
+ // await this.deleteListOfValuesFromConfig(event.entity, event.queryRunner.manager);
49
+ // }
50
+
51
+
52
+ private async saveListOfValuesToConfig(listOfValues: ListOfValues, entityManager: EntityManager): Promise<void> {
53
+ if (!listOfValues || !listOfValues.id) {
54
+ this.logger.debug('on save Listofvalue id is undefined');
55
+ return;
56
+ }
57
+
58
+ // Load the Listofvalue with module relation populated
59
+ const populatedLov = await entityManager.findOne(ListOfValues, {
60
+ where: { id: listOfValues.id },
61
+ relations: ['module'],
62
+ });
63
+
64
+ if (!populatedLov) {
65
+ this.logger.error(`Listofvalue not found for id ${listOfValues.id}`);
66
+ return;
67
+ }
68
+
69
+ // Call the saveListofValuesToConfig method from the ListOfValuesMetadataService
70
+ await this.listOfValuesMetadataService.saveListofValuesToConfig(populatedLov);
71
+ }
72
+
73
+ private async updateListOfValuesToConfig(oldlistOfValues: ListOfValues, listOfValues: ListOfValues, entityManager: EntityManager): Promise<void> {
74
+ if (!listOfValues || !listOfValues.id) {
75
+ this.logger.debug('on update Listofvalue id is undefined');
76
+ return;
77
+ }
78
+
79
+ // Load the Listofvalue with module relation populated
80
+ const populatedLov = await entityManager.findOne(ListOfValues, {
81
+ where: { id: listOfValues.id },
82
+ relations: ['module'],
83
+ });
84
+
85
+ if (!populatedLov) {
86
+ this.logger.error(`Listofvalue not found for id ${listOfValues.id}`);
87
+ return;
88
+ }
89
+
90
+ // Call the updateListofValuesToConfig method from the ListOfValuesMetadataService
91
+ await this.listOfValuesMetadataService.updateListofValuesToConfig(oldlistOfValues, populatedLov);
92
+ }
93
+
94
+ private async deleteListOfValuesFromConfig(listOfValues: ListOfValues, entityManager: EntityManager): Promise<void> {
95
+ if (!listOfValues || !listOfValues.id) {
96
+ this.logger.debug('on delete Listofvalue id is undefined');
97
+ return;
98
+ }
99
+
100
+ // Load the Listofvalue with module relation populated
101
+ const populatedLov = await entityManager.findOne(ListOfValues, {
102
+ where: { id: listOfValues.id },
103
+ relations: ['module'],
104
+ });
105
+
106
+ if (!populatedLov) {
107
+ this.logger.error(`Listofvalue not found for id ${listOfValues.id}`);
108
+ return;
109
+ }
110
+
111
+ // Call the deleteListOfValuesFromConfig method from the ListOfValuesMetadataService
112
+ await this.listOfValuesMetadataService.deleteListOfValuesFromConfig(populatedLov);
113
+ }
114
+
115
+ }