From 2c0a8608ac06c8d344d1b51a8784d7202646fab5 Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Mon, 22 Dec 2025 11:34:43 -0600 Subject: [PATCH] feat(util): return helper to hit the api,logging,socket.io returns --- backend/src/utils/returnHelper.utils.ts | 48 +++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 backend/src/utils/returnHelper.utils.ts diff --git a/backend/src/utils/returnHelper.utils.ts b/backend/src/utils/returnHelper.utils.ts new file mode 100644 index 0000000..c9333b8 --- /dev/null +++ b/backend/src/utils/returnHelper.utils.ts @@ -0,0 +1,48 @@ +interface Data { + success: boolean; + module: "system" | "ocp"; + subModule?: "db" | "labeling" | "printer"; + level: "info" | "error" | "debug" | "fatal"; + message: string; + data?: unknown[]; + notify?: boolean; +} + +/** + * This dose the return process and log at the same time, vs needing to log and return at the same time. + * When to use. + * APIs + * actual returns and needing to stop. + * Example Data + * success:true + * module: system | printers | etc + * submodule: sql connection | printer test | etc + * level "info" | "error" | "debug" | "fatal" + * message: "short description of the return" + * data: [] the data that will be passed back + * notify: false by default this is to send a notification to a users email to alert them of an issue. + */ +export const returnFunc = (data: Data) => { + const notify = data.notify ? data.notify : false; + // handle the logging part + switch (data.level) { + case "info": + console.log({ notify: notify }, data.message); + break; + case "error": + console.log({ notify: notify }, data.message); + break; + case "debug": + console.log({ notify: notify }, data.message); + break; + case "fatal": + console.log({ notify: notify }, data.message); + } + + // api section to return + return { + success: data.success, + message: data.message, + data: data.data || [], + }; +};