return updated settings
This commit is contained in:
1 parent
7c275db662
commit
7d333c6d93
3 files changed
+22
-16
No files matched your search
@@ -11,8 +11,7 @@ class SettingsController {
|
|||||||
this.emailService = emailService;
|
this.emailService = emailService;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAppSettings = async (req, res, next) => {
|
buildAppSettings = (dbSettings) => {
|
||||||
const dbSettings = await this.settingsService.getDBSettings();
|
|
||||||
const sanitizedSettings = { ...dbSettings };
|
const sanitizedSettings = { ...dbSettings };
|
||||||
delete sanitizedSettings.version;
|
delete sanitizedSettings.version;
|
||||||
|
|
||||||
@@ -30,6 +29,14 @@ class SettingsController {
|
|||||||
delete sanitizedSettings.systemEmailPassword;
|
delete sanitizedSettings.systemEmailPassword;
|
||||||
}
|
}
|
||||||
returnSettings.settings = sanitizedSettings;
|
returnSettings.settings = sanitizedSettings;
|
||||||
|
return returnSettings;
|
||||||
|
};
|
||||||
|
|
||||||
|
getAppSettings = async (req, res, next) => {
|
||||||
|
const dbSettings = await this.settingsService.getDBSettings();
|
||||||
|
|
||||||
|
const returnSettings = this.buildAppSettings(dbSettings);
|
||||||
|
console.log(returnSettings);
|
||||||
return res.success({
|
return res.success({
|
||||||
msg: this.stringService.getAppSettings,
|
msg: this.stringService.getAppSettings,
|
||||||
data: returnSettings,
|
data: returnSettings,
|
||||||
@@ -45,12 +52,11 @@ class SettingsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.db.updateAppSettings(req.body);
|
const updatedSettings = await this.db.updateAppSettings(req.body);
|
||||||
const updatedSettings = { ...(await this.settingsService.reloadSettings()) };
|
const returnSettings = this.buildAppSettings(updatedSettings);
|
||||||
delete updatedSettings.jwtSecret;
|
|
||||||
return res.success({
|
return res.success({
|
||||||
msg: this.stringService.updateAppSettings,
|
msg: this.stringService.updateAppSettings,
|
||||||
data: updatedSettings,
|
data: returnSettings,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(handleError(error, SERVICE_NAME, "updateAppSettings"));
|
next(handleError(error, SERVICE_NAME, "updateAppSettings"));
|
||||||
|
|||||||
@@ -26,10 +26,12 @@ const updateAppSettings = async (newSettings) => {
|
|||||||
delete update.$set.systemEmailPassword;
|
delete update.$set.systemEmailPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
const settings = await AppSettings.findOneAndUpdate({}, update, {
|
await AppSettings.findOneAndUpdate({}, update, {
|
||||||
new: true,
|
|
||||||
upsert: true,
|
upsert: true,
|
||||||
});
|
});
|
||||||
|
const settings = await AppSettings.findOne()
|
||||||
|
.select("-__v -_id -createdAt -updatedAt -singleton")
|
||||||
|
.lean();
|
||||||
return settings;
|
return settings;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ class SettingsService {
|
|||||||
* Constructs a new SettingsService
|
* Constructs a new SettingsService
|
||||||
* @constructor
|
* @constructor
|
||||||
* @throws {Error}
|
* @throws {Error}
|
||||||
*/ constructor(appSettings) {
|
*/ constructor(AppSettings) {
|
||||||
this.appSettings = appSettings;
|
this.AppSettings = AppSettings;
|
||||||
this.settings = { ...envConfig };
|
this.settings = { ...envConfig };
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -60,16 +60,14 @@ class SettingsService {
|
|||||||
|
|
||||||
async getDBSettings() {
|
async getDBSettings() {
|
||||||
// Remove any old settings
|
// Remove any old settings
|
||||||
await this.appSettings.deleteMany({ version: { $exists: false } });
|
await this.AppSettings.deleteMany({ version: { $exists: false } });
|
||||||
|
|
||||||
let settings = await this.appSettings
|
let settings = await this.AppSettings.findOne({ singleton: true })
|
||||||
.findOne({ singleton: true })
|
|
||||||
.select("-__v -_id -createdAt -updatedAt -singleton")
|
.select("-__v -_id -createdAt -updatedAt -singleton")
|
||||||
.lean();
|
.lean();
|
||||||
if (settings === null) {
|
if (settings === null) {
|
||||||
await this.appSettings.create({});
|
await this.AppSettings.create({});
|
||||||
settings = await this.appSettings
|
settings = await this.AppSettings.findOne({ singleton: true })
|
||||||
.findOne({ singleton: true })
|
|
||||||
.select("-__v -_id -createdAt -updatedAt -singleton")
|
.select("-__v -_id -createdAt -updatedAt -singleton")
|
||||||
.lean();
|
.lean();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user