agent starting :D
This commit is contained in:
@@ -5,9 +5,8 @@ import { settings } from "../db/schema/settings.schema.js";
|
||||
|
||||
import { apiReturn } from "../utils/returnHelper.utils.js";
|
||||
import { tryCatch } from "../utils/trycatch.utils.js";
|
||||
import { featureControl } from "./settingsFeatures.controller.js";
|
||||
|
||||
// export const updateSetting = async (setting: Setting) => {
|
||||
// // TODO: when the setting is a feature setting we will need to have it run each kill switch on the crons well just stop them and during a reset it just wont start them
|
||||
// // TODO: when the setting is a system we will need to force an app restart
|
||||
// // TODO: when the setting is standard we don't do anything.
|
||||
// };
|
||||
@@ -38,17 +37,17 @@ r.patch("/:name", async (req: Request, res: Response) => {
|
||||
});
|
||||
}
|
||||
|
||||
// if (sName?.length === 0) {
|
||||
// return apiReturn(res, {
|
||||
// success: false,
|
||||
// level: "error",
|
||||
// module: "system",
|
||||
// subModule: "settings",
|
||||
// message: `The setting "${name}" dose not appear to be a valid setting please check the name and try again. `,
|
||||
// data: [],
|
||||
// status: 400,
|
||||
// });
|
||||
// }
|
||||
if (sName?.length === 0) {
|
||||
return apiReturn(res, {
|
||||
success: false,
|
||||
level: "error",
|
||||
module: "system",
|
||||
subModule: "settings",
|
||||
message: `The setting "${name}" dose not appear to be a valid setting please check the name and try again. `,
|
||||
data: [],
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
// manage the actual setting. we will still do an upsert just in case we strangely get past everything
|
||||
|
||||
@@ -79,14 +78,32 @@ r.patch("/:name", async (req: Request, res: Response) => {
|
||||
updates.upd_user = req.user?.username || "lst_user";
|
||||
updates.upd_date = sql`NOW()`;
|
||||
|
||||
const updatedSetting = await db
|
||||
.update(settings)
|
||||
.set(updates)
|
||||
.where(eq(settings.name, name ?? ""))
|
||||
.returning();
|
||||
|
||||
// the switch statment will only run when the setting actually updates
|
||||
switch (updatedSetting[0]?.settingType) {
|
||||
case "feature":
|
||||
await featureControl(updatedSetting[0]);
|
||||
break;
|
||||
case "system":
|
||||
// TODO: add the system control logic in to restart the app if not in dev mode
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return apiReturn(res, {
|
||||
success: true,
|
||||
level: "info",
|
||||
module: "system",
|
||||
subModule: "settings",
|
||||
message: `Setting "${name}" Was just updated. `,
|
||||
data: [updates],
|
||||
status: 400,
|
||||
data: updatedSetting,
|
||||
status: 200,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user