@solidstarters/solid-core 1.2.12 → 1.2.14
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/dist/controllers/setting.controller.d.ts +1 -1
- package/dist/controllers/setting.controller.d.ts.map +1 -1
- package/dist/controllers/setting.controller.js +4 -4
- package/dist/controllers/setting.controller.js.map +1 -1
- package/dist/seeders/module-metadata-seeder.service.d.ts +11 -1
- package/dist/seeders/module-metadata-seeder.service.d.ts.map +1 -1
- package/dist/seeders/module-metadata-seeder.service.js +41 -3
- package/dist/seeders/module-metadata-seeder.service.js.map +1 -1
- package/dist/services/crud.service.d.ts +8 -0
- package/dist/services/crud.service.d.ts.map +1 -1
- package/dist/services/crud.service.js +52 -0
- package/dist/services/crud.service.js.map +1 -1
- package/dist/services/setting.service.d.ts +1 -1
- package/dist/services/setting.service.d.ts.map +1 -1
- package/dist/services/setting.service.js +11 -5
- package/dist/services/setting.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/controllers/setting.controller.ts +4 -4
- package/src/seeders/module-metadata-seeder.service.ts +42 -2
- package/src/services/crud.service.ts +74 -1
- package/src/services/setting.service.ts +17 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidstarters/solid-core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.14",
|
|
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('/
|
|
44
|
-
async
|
|
45
|
-
|
|
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
|
|
171
|
-
await this.roleService.addPermissionToRole('Public', 'SettingController.
|
|
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
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BadRequestException } from "@nestjs/common";
|
|
2
2
|
import { ConfigService } from "@nestjs/config";
|
|
3
3
|
import { DiscoveryService } from "@nestjs/core";
|
|
4
|
-
import { EntityManager, QueryFailedError, SelectQueryBuilder } from "typeorm";
|
|
4
|
+
import { EntityManager, In, IsNull, Not, QueryFailedError, SelectQueryBuilder } from "typeorm";
|
|
5
5
|
import { Repository } from "typeorm/repository/Repository";
|
|
6
6
|
import { BasicFilterDto } from "../dtos/basic-filters.dto";
|
|
7
7
|
import { ComputedFieldValueType, RelationType, SelectionValueType, SolidFieldType } from "../dtos/create-field-metadata.dto";
|
|
@@ -649,4 +649,77 @@ export class CRUDService<T> { //Add two generic value i.e Person,CreatePersonDto
|
|
|
649
649
|
// return removedEntities
|
|
650
650
|
}
|
|
651
651
|
|
|
652
|
+
async recover(id: number) {
|
|
653
|
+
try {
|
|
654
|
+
const softDeletedRows = await this.repo.findOne({
|
|
655
|
+
where: {
|
|
656
|
+
//@ts-ignore
|
|
657
|
+
id, deletedAt: Not(IsNull())
|
|
658
|
+
},
|
|
659
|
+
withDeleted: true,
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
if (!softDeletedRows) {
|
|
663
|
+
throw new Error('No soft-deleted record found with the given ID.');
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
await this.repo.update(id, {
|
|
667
|
+
//@ts-ignore
|
|
668
|
+
deletedAt: null, deletedTracker: "not-deleted"
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
return { message: 'Record successfully recovered', data: softDeletedRows };
|
|
672
|
+
} catch (error) {
|
|
673
|
+
if (error instanceof QueryFailedError) {
|
|
674
|
+
if ((error as any).code === '23505') {
|
|
675
|
+
throw new Error('Another record is conflicting with the record you are attempting to Un-Archive, either delete or change the other record so as to avoid this conflict.');
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
throw new Error(error);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
async recoverMany(ids: number[]) {
|
|
684
|
+
try {
|
|
685
|
+
if (!ids || ids.length === 0) {
|
|
686
|
+
throw new Error("No IDs provided for recovery.");
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// Find soft-deleted records matching the given IDs
|
|
690
|
+
const softDeletedRows = await this.repo.find({
|
|
691
|
+
where: {
|
|
692
|
+
//@ts-ignore
|
|
693
|
+
id: In(ids),
|
|
694
|
+
deletedAt: Not(IsNull()),
|
|
695
|
+
},
|
|
696
|
+
withDeleted: true,
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
if (softDeletedRows.length === 0) {
|
|
700
|
+
throw new Error("No matching soft-deleted records found.");
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// Recover the specific records by setting deletedAt to null
|
|
704
|
+
await this.repo.update(
|
|
705
|
+
//@ts-ignore
|
|
706
|
+
{ id: In(ids) },
|
|
707
|
+
{ deletedAt: null, deletedTracker: "not-deleted" }
|
|
708
|
+
);
|
|
709
|
+
|
|
710
|
+
return { message: "Selected records successfully recovered", recoveredIds: ids };
|
|
711
|
+
} catch (error) {
|
|
712
|
+
if (error instanceof QueryFailedError) {
|
|
713
|
+
if ((error as any).code === "23505") {
|
|
714
|
+
throw new Error(
|
|
715
|
+
"Another record is conflicting with the record you are attempting to Un-Archive, either delete or change the other record to avoid this conflict."
|
|
716
|
+
);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
throw new Error(error);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
|
|
652
725
|
}
|
|
@@ -40,12 +40,23 @@ export class SettingService extends CRUDService<Setting>{
|
|
|
40
40
|
);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
async
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
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 || "
|
|
71
|
+
appTitle: process.env.SOLID_APP_NAME || "Solid App",
|
|
61
72
|
appLogo: "",
|
|
62
73
|
appDescription: "",
|
|
63
74
|
appTnc: "",
|