Remove DB settings from settings service

This commit is contained in:
Alex Holliday
2025-05-08 13:11:51 -07:00
parent c466edb751
commit 91c2f7f0d5
6 changed files with 24 additions and 86 deletions
+6 -33
View File
@@ -1,6 +1,4 @@
const SERVICE_NAME = "SettingsService";
import dotenv from "dotenv";
dotenv.config();
const envConfig = {
logLevel: process.env.LOG_LEVEL,
clientHost: process.env.CLIENT_HOST,
@@ -20,8 +18,6 @@ const envConfig = {
* SettingsService
*
* This service is responsible for loading and managing the application settings.
* It gives priority to environment variables and will only load settings
* from the database if they are not set in the environment.
*/
class SettingsService {
static SERVICE_NAME = SERVICE_NAME;
@@ -34,40 +30,17 @@ class SettingsService {
this.settings = { ...envConfig };
}
/**
* Load settings from the database and merge with environment settings.
* If there are any settings that weren't set by environment variables, use user settings from the database.
* @returns {Promise<Object>} The merged settings.
* @throws Will throw an error if settings are not found in the database or if settings have not been loaded.
*/ async loadSettings() {
try {
const dbSettings = await this.appSettings.findOne();
if (!this.settings) {
throw new Error("Settings not found");
}
// If there are any settings that weren't set by environment variables, use user settings from DB
for (const key in envConfig) {
if (
typeof envConfig?.[key] === "undefined" &&
typeof dbSettings?.[key] !== "undefined"
) {
this.settings[key] = dbSettings[key];
}
}
await this.appSettings.updateOne({}, { $set: this.settings }, { upsert: true });
return this.settings;
} catch (error) {
error.service === undefined ? (error.service = SERVICE_NAME) : null;
error.method === undefined ? (error.method = "loadSettings") : null;
throw error;
}
* Load settings from env settings
* @returns {Object>} The settings.
*/
loadSettings() {
return this.settings;
}
/**
* Reload settings by calling loadSettings.
* @returns {Promise<Object>} The reloaded settings.
*/
async reloadSettings() {
reloadSettings() {
return this.loadSettings();
}
/**