Files
Checkmate/Server/controllers/settingsController.js
T

48 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-10-15 11:57:37 +08:00
import { updateAppSettingsBodyValidation } from "../validation/joi.js";
import { handleValidationError, handleError } from "./controllerUtils.js";
2025-01-30 00:41:31 +03:00
const SERVICE_NAME = "SettingsController";
2024-12-24 11:58:42 -08:00
class SettingsController {
2025-01-30 08:37:42 +03:00
constructor(db, settingsService, stringService) {
2024-12-24 11:58:42 -08:00
this.db = db;
this.settingsService = settingsService;
2025-01-30 08:37:42 +03:00
this.stringService = stringService;
2024-10-17 12:07:30 +08:00
}
2024-12-24 11:58:42 -08:00
getAppSettings = async (req, res, next) => {
try {
const settings = { ...(await this.settingsService.getSettings()) };
delete settings.jwtSecret;
2025-01-20 11:02:55 -08:00
return res.success({
2025-01-30 00:41:31 +03:00
msg: this.stringService.getAppSettings,
2024-12-24 11:58:42 -08:00
data: settings,
});
} catch (error) {
next(handleError(error, SERVICE_NAME, "getAppSettings"));
}
};
2024-12-24 11:58:42 -08:00
updateAppSettings = async (req, res, next) => {
try {
await updateAppSettingsBodyValidation.validateAsync(req.body);
} catch (error) {
next(handleValidationError(error, SERVICE_NAME));
return;
}
try {
await this.db.updateAppSettings(req.body);
const updatedSettings = { ...(await this.settingsService.reloadSettings()) };
delete updatedSettings.jwtSecret;
return res.success({
2025-01-30 00:41:31 +03:00
msg: this.stringService.updateAppSettings,
2024-12-24 11:58:42 -08:00
data: updatedSettings,
});
} catch (error) {
next(handleError(error, SERVICE_NAME, "updateAppSettings"));
}
};
}
2024-12-24 11:58:42 -08:00
export default SettingsController;