feat(sql): full sql start stop and query with crash prevention
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import type { Response } from "express";
|
||||
import { createLogger } from "../logger/logger.controller.js";
|
||||
|
||||
interface Data {
|
||||
success: boolean;
|
||||
module: "system" | "ocp";
|
||||
subModule: "db" | "labeling" | "printer";
|
||||
module: "system" | "ocp" | "routes";
|
||||
subModule: "db" | "labeling" | "printer" | "prodSql";
|
||||
level: "info" | "error" | "debug" | "fatal";
|
||||
message: string;
|
||||
data?: unknown[];
|
||||
@@ -49,3 +50,12 @@ export const returnFunc = (data: Data) => {
|
||||
data: data.data || [],
|
||||
};
|
||||
};
|
||||
|
||||
export function apiReturn(
|
||||
res: Response,
|
||||
opts: Data & { status?: number },
|
||||
): Response {
|
||||
const result = returnFunc(opts);
|
||||
const code = opts.status ?? (opts.success ? 200 : 500);
|
||||
return res.status(code ?? (opts.success ? 200 : 500)).json(result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user