2022-01-06 01:26:15 +00:00
|
|
|
import { Request, Response } from "express";
|
|
|
|
|
|
|
|
import { getIO } from "../libs/socket";
|
|
|
|
import AppError from "../errors/AppError";
|
|
|
|
|
|
|
|
import UpdateSettingService from "../services/SettingServices/UpdateSettingService";
|
|
|
|
import ListSettingsService from "../services/SettingServices/ListSettingsService";
|
|
|
|
|
|
|
|
export const index = async (req: Request, res: Response): Promise<Response> => {
|
2022-01-13 10:05:08 +00:00
|
|
|
if (req.user.profile !== "master") {
|
2022-01-06 01:26:15 +00:00
|
|
|
throw new AppError("ERR_NO_PERMISSION", 403);
|
|
|
|
}
|
|
|
|
|
|
|
|
const settings = await ListSettingsService();
|
|
|
|
|
|
|
|
return res.status(200).json(settings);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const update = async (
|
|
|
|
req: Request,
|
|
|
|
res: Response
|
|
|
|
): Promise<Response> => {
|
2022-01-13 10:05:08 +00:00
|
|
|
if (req.user.profile !== "master") {
|
2022-01-06 01:26:15 +00:00
|
|
|
throw new AppError("ERR_NO_PERMISSION", 403);
|
|
|
|
}
|
|
|
|
const { settingKey: key } = req.params;
|
|
|
|
const { value } = req.body;
|
|
|
|
|
|
|
|
const setting = await UpdateSettingService({
|
|
|
|
key,
|
|
|
|
value
|
|
|
|
});
|
|
|
|
|
|
|
|
const io = getIO();
|
|
|
|
io.emit("settings", {
|
|
|
|
action: "update",
|
|
|
|
setting
|
|
|
|
});
|
|
|
|
|
|
|
|
return res.status(200).json(setting);
|
|
|
|
};
|