fix(createurl): add catches for when server not installed

This commit is contained in:
2025-05-02 19:13:17 -05:00
parent 9f68cd2146
commit 8f828d764a

View File

@@ -1,32 +1,40 @@
import {eq} from "drizzle-orm"; import { eq } from "drizzle-orm";
import {db} from "../../database/dbclient.js"; import { db } from "../../database/dbclient.js";
import {settings} from "../../database/schema/settings.js"; import { settings } from "../../database/schema/settings.js";
// create the test server stuff // create the test server stuff
const testServers = [ const testServers = [
{token: "test1", port: 8940}, { token: "test1", port: 8940 },
{token: "test2", port: 8941}, { token: "test2", port: 8941 },
{token: "test3", port: 8942}, { token: "test3", port: 8942 },
]; ];
export const prodEndpointCreation = async (endpoint: string) => { export const prodEndpointCreation = async (endpoint: string) => {
let url = ""; let url = "";
//get the plant token //get the plant token
const plantToken = await db.select().from(settings).where(eq(settings.name, "plantToken")); const plantToken = await db
.select()
.from(settings)
.where(eq(settings.name, "plantToken"));
// check if we are a test server // check if we are a test server
const testServer = testServers.some((server) => server.token === plantToken[0].value); const testServer = testServers.some(
const server = await db.select().from(settings).where(eq(settings.name, "dbServer")); (server) => server.token === plantToken[0]?.value
);
const server = await db
.select()
.from(settings)
.where(eq(settings.name, "dbServer"));
if (testServer) { if (testServer) {
//filter out what testserver we are //filter out what testserver we are
const test = testServers.filter((t) => t.token === plantToken[0].value); const test = testServers.filter((t) => t.token === plantToken[0].value);
// "https://usmcd1vms036.alpla.net:8942/application/public/v1.0/DemandManagement/ORDERS" // "https://usmcd1vms036.alpla.net:8942/application/public/v1.0/DemandManagement/ORDERS"
// "https://usmcd1vms036.alpla.net:8492/application/public/v1.0/DemandManagement/ORDERS" // "https://usmcd1vms036.alpla.net:8492/application/public/v1.0/DemandManagement/ORDERS"
url = `https://${server[0].value}.alpla.net:${test[0].port}/application${endpoint}`; url = `https://${server[0]?.value}.alpla.net:${test[0]?.port}/application${endpoint}`;
return url; return url;
} else { } else {
url = `https://${plantToken[0].value}prod.alpla.net/application${endpoint}`; url = `https://${plantToken[0]?.value}prod.alpla.net/application${endpoint}`;
return url; return url;
} }
}; };