Files
Checkmate/Server/controllers/settingsController.js
T

47 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-10-15 11:57:37 +08:00
import { successMessages } from "../utils/messages.js";
import { updateAppSettingsBodyValidation } from "../validation/joi.js";
import { handleValidationError, handleError } from "./controllerUtils.js";
const SERVICE_NAME = "SettingsController";
2024-12-24 11:58:42 -08:00
class SettingsController {
constructor(db, settingsService) {
this.db = db;
this.settingsService = settingsService;
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({
2024-12-24 11:58:42 -08:00
msg: successMessages.GET_APP_SETTINGS,
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({
2024-12-24 11:58:42 -08:00
msg: successMessages.UPDATE_APP_SETTINGS,
data: updatedSettings,
});
} catch (error) {
next(handleError(error, SERVICE_NAME, "updateAppSettings"));
}
};
}
2024-12-24 11:58:42 -08:00
export default SettingsController;