Files
Checkmate/server/src/db/mongo/modules/settingsModule.js
T

36 lines
944 B
JavaScript
Raw Normal View History

2025-07-31 11:57:55 -07:00
// import AppSettings from "../../models/AppSettings.js";
2025-04-20 11:29:53 -07:00
const SERVICE_NAME = "SettingsModule";
2025-07-31 11:57:55 -07:00
class SettingsModule {
constructor({ AppSettings }) {
this.AppSettings = AppSettings;
2025-04-20 11:29:53 -07:00
}
2025-07-31 11:57:55 -07:00
updateAppSettings = async (newSettings) => {
try {
const update = { $set: { ...newSettings } };
2025-05-09 13:26:39 -07:00
2025-07-31 11:57:55 -07:00
if (newSettings.pagespeedApiKey === "") {
update.$unset = { pagespeedApiKey: "" };
delete update.$set.pagespeedApiKey;
}
2025-05-09 13:26:39 -07:00
2025-07-31 11:57:55 -07:00
if (newSettings.systemEmailPassword === "") {
update.$unset = { systemEmailPassword: "" };
delete update.$set.systemEmailPassword;
}
2025-05-09 14:53:03 -07:00
2025-07-31 11:57:55 -07:00
await this.AppSettings.findOneAndUpdate({}, update, {
upsert: true,
});
const settings = await this.AppSettings.findOne().select("-__v -_id -createdAt -updatedAt -singleton").lean();
return settings;
} catch (error) {
error.service = SERVICE_NAME;
error.method = "updateAppSettings";
throw error;
}
};
}
2025-04-20 11:29:53 -07:00
2025-07-31 11:57:55 -07:00
export default SettingsModule;