@solidstarters/solid-core 1.2.12 → 1.2.13

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": "@solidstarters/solid-core",
3
- "version": "1.2.12",
3
+ "version": "1.2.13",
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",
@@ -40,10 +40,10 @@ export class SettingController {
40
40
  }
41
41
 
42
42
  @ApiBearerAuth("jwt")
43
- @Get('/getSettings')
44
- async getAllSettings() {
45
- return this.service.getAllSettings();
46
- }
43
+ @Get('/wrapped')
44
+ async wrapSettings() {
45
+ return this.service.wrapSettings();
46
+ }
47
47
 
48
48
  @ApiBearerAuth("jwt")
49
49
  @ApiQuery({ name: 'showSoftDeleted', required: false, type: Boolean })
@@ -27,6 +27,11 @@ import { SolidRegistry } from '../helpers/solid-registry';
27
27
  import { RoleMetadataService } from '../services/role-metadata.service';
28
28
  import { getCoreModuleNames, getDynamicModuleNames } from '../helpers/module.helper';
29
29
  import solidCoreMetadata from './seed-data/solid-core-metadata.json';
30
+ import { iamConfig } from 'src/config/iam.config';
31
+ import commonConfig from 'src/config/common.config';
32
+ import { CreateSettingDto } from 'src/dtos/create-setting.dto';
33
+ import { SettingService } from 'src/services/setting.service';
34
+ import { Setting } from 'src/entities/setting.entity';
30
35
 
31
36
  @Injectable()
32
37
  export class ModuleMetadataSeederService {
@@ -51,12 +56,36 @@ export class ModuleMetadataSeederService {
51
56
  private readonly solidRegistry: SolidRegistry,
52
57
  @Inject(appBuilderConfig.KEY)
53
58
  private readonly appBuilderConfiguration: ConfigType<typeof appBuilderConfig>,
59
+ @Inject(iamConfig.KEY) private readonly iamConfiguration: ConfigType<typeof iamConfig>,
60
+ @Inject(commonConfig.KEY)
61
+ private readonly commonConfiguration: ConfigType<typeof commonConfig>,
62
+ private readonly service: SettingService,
63
+ @InjectRepository(Setting, 'default')
64
+ readonly settingsRepo: Repository<Setting>,
54
65
  ) { }
55
66
 
56
67
  async seed() {
57
68
 
58
69
  const typedSolidCoreMetadata: any = solidCoreMetadata;
59
70
 
71
+ const settingsSeederData: any = {
72
+ iamAllowPublicRegistration: this.iamConfiguration.allowPublicRegistration,
73
+ iamPasswordRegistrationEnabled: false,
74
+ iamPasswordLessRegistrationEnabled: this.iamConfiguration.passwordlessRegistration,
75
+ iamActivateUserOnRegistration: this.iamConfiguration.activateUserOnRegistration,
76
+ iamGoogleOAuthEnabled: false,
77
+ authPagesLayout: "center",
78
+ authPagesTheme: "light",
79
+ appTitle: process.env.SOLID_APP_NAME || "Solid App",
80
+ appLogo: "",
81
+ appDescription: "",
82
+ appTnc: "",
83
+ appPrivacyPolicy: "",
84
+ iamDefaultRole: this.iamConfiguration.defaultRole,
85
+ shouldQueueEmails: this.commonConfiguration.shouldQueueEmails,
86
+ shouldQueueSms: this.commonConfiguration.shouldQueueSms
87
+ }
88
+
60
89
  // Run the permissions seeder.
61
90
  // await this.permissionsSeederService.seed();
62
91
  await this.seedPermissions();
@@ -157,6 +186,10 @@ export class ModuleMetadataSeederService {
157
186
  await this.seedSmsTemplates(smsTemplates);
158
187
  this.logger.log(`[End] Processing sms templates for ${moduleMetadata.name}`);
159
188
 
189
+ // Sms templates
190
+ this.logger.log(`[Start] Processing settings for ${moduleMetadata.name}`);
191
+ await this.seedSettings(settingsSeederData);
192
+ this.logger.log(`[End] Processing settings for ${moduleMetadata.name}`);
160
193
 
161
194
  this.logger.log(`[End] module seed data: ${overallMetadata}`);
162
195
 
@@ -167,8 +200,8 @@ export class ModuleMetadataSeederService {
167
200
  // 1. Give all permissions to the Admin role.
168
201
  this.logger.log(`About to add all permissions to the Admin role`);
169
202
  await this.roleService.addAllPermissionsToRole("Admin");
170
- // 2. Give getAllSettings permissions to the Public role.
171
- await this.roleService.addPermissionToRole('Public', 'SettingController.getAllSettings');
203
+ // 2. Give wrapSettings permissions to the Public role.
204
+ await this.roleService.addPermissionToRole('Public', 'SettingController.wrapSettings');
172
205
  this.logger.log(`All Seeders finished`);
173
206
 
174
207
  }
@@ -418,4 +451,11 @@ export class ModuleMetadataSeederService {
418
451
  }
419
452
  }
420
453
  }
454
+
455
+ async seedSettings(createDto: CreateSettingDto) {
456
+ const settingsArray: any[] = await this.settingsRepo.find();
457
+ if (!settingsArray || settingsArray.length === 0) {
458
+ this.service.create(createDto);
459
+ }
460
+ }
421
461
  }
@@ -40,12 +40,23 @@ export class SettingService extends CRUDService<Setting>{
40
40
  );
41
41
  }
42
42
 
43
- async getAllSettings(): Promise<Record<string, any>> {
44
- const settings: any = await this.repo.find();
45
- if (!settings || settings.length === 0) {
46
- return this.getDefaultSettings();
43
+ async wrapSettings(): Promise<Record<string, any>> {
44
+ const settingsArray: any[] = await this.repo.find();
45
+
46
+ if (!settingsArray || settingsArray.length === 0) {
47
+ return this.getDefaultSettings();
47
48
  }
48
- return settings;
49
+
50
+ const settings = settingsArray[0];
51
+
52
+ const defaultSettings = this.getDefaultSettings();
53
+
54
+ const mergedSettings = Object.keys(defaultSettings).reduce((acc, key) => {
55
+ acc[key] = settings[key] !== null && settings[key] !== undefined ? settings[key] : defaultSettings[key];
56
+ return acc;
57
+ }, {} as Record<string, any>);
58
+
59
+ return mergedSettings;
49
60
  }
50
61
 
51
62
  private getDefaultSettings(): Record<string, any> {
@@ -57,7 +68,7 @@ export class SettingService extends CRUDService<Setting>{
57
68
  iamGoogleOAuthEnabled: false,
58
69
  authPagesLayout: "center",
59
70
  authPagesTheme: "light",
60
- appTitle: process.env.SOLID_APP_NAME || "Default App",
71
+ appTitle: process.env.SOLID_APP_NAME || "Solid App",
61
72
  appLogo: "",
62
73
  appDescription: "",
63
74
  appTnc: "",