fix(logging): updated entire server side to the new logging system

This commit is contained in:
2025-03-07 13:40:29 -06:00
parent ce11b1f57e
commit 12e15babb4
33 changed files with 482 additions and 72 deletions

View File

@@ -0,0 +1,3 @@
export const labelData = `
select Barcode as barcode from alplaprod_test1.dbo.V_LagerPositionenBarcodes (NOLOCK) where lfdnr = [rn]
`;

View File

@@ -0,0 +1,46 @@
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
import {apiHit} from "../../../globalUtils/apiHits.js";
import {closePool} from "../prodSqlServer.js";
const app = new OpenAPIHono();
const responseSchema = z.object({
success: z.boolean().openapi({example: true}),
message: z.string().optional().openapi({example: "user access"}),
});
app.openapi(
createRoute({
tags: ["Server:PRODSQL"],
summary: "Close connection",
method: "get",
path: "/",
middleware: authMiddleware,
description: "Closes the connection to the prod sql server.",
responses: {
200: {
content: {"application/json": {schema: responseSchema}},
description: "stopped",
},
400: {
content: {"application/json": {schema: responseSchema}},
description: "Failed to stop",
},
},
}),
async (c) => {
apiHit(c, {endpoint: "api/sqlProd/close"});
try {
const pool = await closePool();
//return apiReturn(c, true, access?.message, access?.data, 200);
return c.json({success: pool.success, message: pool.message}, 200);
} catch (error) {
console.log(error);
//return apiReturn(c, false, "Error in setting the user access", error, 400);
return c.json({success: false, message: "Error in closing connection", data: error}, 400);
}
}
);
export default app;

View File

@@ -0,0 +1,48 @@
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
import {apiHit} from "../../../globalUtils/apiHits.js";
import {closePool, initializeProdPool} from "../prodSqlServer.js";
const app = new OpenAPIHono();
const responseSchema = z.object({
success: z.boolean().openapi({example: true}),
message: z.string().optional().openapi({example: "user access"}),
});
app.openapi(
createRoute({
tags: ["Server:PRODSQL"],
summary: "restart sql connection",
method: "get",
path: "/",
middleware: authMiddleware,
description: "Restarts the sql connection.",
responses: {
200: {
content: {"application/json": {schema: responseSchema}},
description: "Succefull restart",
},
400: {
content: {"application/json": {schema: responseSchema}},
description: "Failed to restart server",
},
},
}),
async (c) => {
apiHit(c, {endpoint: "api/sqlProd/restart"});
try {
const poolClose = await closePool();
await new Promise((resolve) => setTimeout(resolve, 5000));
const poolStart = await initializeProdPool();
//return apiReturn(c, true, access?.message, access?.data, 200);
return c.json({success: poolStart.success, message: "The connection has been restarted."}, 200);
} catch (error) {
console.log(error);
//return apiReturn(c, false, "Error in setting the user access", error, 400);
return c.json({success: false, message: "Error in restarting the connection", data: error}, 400);
}
}
);
export default app;

View File

@@ -0,0 +1,46 @@
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
import {apiHit} from "../../../globalUtils/apiHits.js";
import {initializeProdPool} from "../prodSqlServer.js";
const app = new OpenAPIHono();
const responseSchema = z.object({
success: z.boolean().openapi({example: true}),
message: z.string().optional().openapi({example: "user access"}),
});
app.openapi(
createRoute({
tags: ["Server:PRODSQL"],
summary: "Connects to the sql server",
method: "get",
path: "/",
middleware: authMiddleware,
description: "Initilized the connetion",
responses: {
200: {
content: {"application/json": {schema: responseSchema}},
description: "restarred",
},
400: {
content: {"application/json": {schema: responseSchema}},
description: "Failed start",
},
},
}),
async (c) => {
apiHit(c, {endpoint: "api/sqlProd/connect"});
try {
const pool = await initializeProdPool();
//return apiReturn(c, true, access?.message, access?.data, 200);
return c.json({success: pool.success, message: pool.message}, 200);
} catch (error) {
console.log(error);
//return apiReturn(c, false, "Error in setting the user access", error, 400);
return c.json({success: false, message: "Error in initalizing the connection", data: error}, 400);
}
}
);
export default app;

View File

@@ -0,0 +1,43 @@
import {db} from "../../../../database/dbclient.js";
import {settings} from "../../../../database/schema/settings.js";
import {createLog} from "../../logger/logger.js";
export const prodSqlConfig = async () => {
try {
const serverSetting = await db.select().from(settings);
// create dummy type data
const server = serverSetting.filter((s) => s.name === "dbServer");
const plantToken = serverSetting.filter((s) => s.name === "plantToken");
const dbUser = serverSetting.filter((s) => s.name === "dbUser");
// if erroring out double check the password was actually encoded before saving
const dbPassword = serverSetting.filter((s) => s.name === "dbPass");
const sqlConfig = {
server: server[0].value,
database: `AlplaPROD_${plantToken[0].value}_cus`,
user: dbUser[0].value,
password: atob(dbPassword[0].value),
options: {
encrypt: true,
trustServerCertificate: true,
},
requestTimeout: 90000, // in milliseconds
pool: {
max: 20, // Maximum number of connections in the pool
min: 0, // Minimum number of connections in the pool
idleTimeoutMillis: 10000, // How long a connection is allowed to be idle before being released
reapIntervalMillis: 1000, // how often to check for idle resourses to destory
acquireTimeoutMillis: 100000, // How long until a complete timeout happens
},
};
return sqlConfig;
} catch (error) {
createLog(
"info",
"lst",
"sqlProd",
`${JSON.stringify(error)} "There was an error getting/setting up the config for the prod sql server."`
);
}
};