Add reload settings method, reload settings when DB updated

This commit is contained in:
Alex Holliday committed 2024-09-26 15:45:54 +08:00
1 parent 0832e8438a
commit 97419b436c
2 files changed
+14

No files matched your search

+1
View File
@@ -31,6 +31,7 @@ const updateAppSettings = async (req, res, next) => {
try {
const settings = await req.db.updateAppSettings(req.body);
await req.settingsService.reloadSettings();
return res.status(200).json({
success: true,
msg: successMessages.UPDATE_APP_SETTINGS,
+13
View File
@@ -22,6 +22,19 @@ class SettingsService {
}
}
async reloadSettings() {
try {
this.settings = await AppSettings.findOne();
if (!this.settings) {
throw new Error("Settings not found");
}
} catch (error) {
error.service === undefined ? (error.service = SERVICE_NAME) : null;
error.method === undefined ? (error.method = "reloadSettings") : null;
throw error;
}
}
getSettings() {
if (!this.settings) {
throw new Error("Settings have not been loaded");