Compare commits
2 Commits
c6f766089b
...
be6510f912
| Author | SHA1 | Date | |
|---|---|---|---|
| be6510f912 | |||
| 006ec1bfc0 |
@@ -5,17 +5,16 @@ meta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
post {
|
post {
|
||||||
url: {{url}}/lst/api/admin/users
|
url: {{url}}/lst/api/admin/users/new
|
||||||
body: none
|
body: json
|
||||||
auth: inherit
|
auth: inherit
|
||||||
}
|
}
|
||||||
|
|
||||||
body:json {
|
body:json {
|
||||||
{
|
{
|
||||||
"username":"matthes01",
|
"username":"hardin001",
|
||||||
"name":"blake",
|
"email":"ryan.hardin@alpla.com",
|
||||||
"email":"blake.matthes@alpla.com",
|
"password":"Alpla2025!"
|
||||||
"password":"nova0511"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
27
LogisticsSupportTool_API_DOCS/app/admin/User/Get roles.bru
Normal file
27
LogisticsSupportTool_API_DOCS/app/admin/User/Get roles.bru
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
meta {
|
||||||
|
name: Get roles
|
||||||
|
type: http
|
||||||
|
seq: 7
|
||||||
|
}
|
||||||
|
|
||||||
|
patch {
|
||||||
|
url: {{url}}/lst/api/admin/users/:userID/grant
|
||||||
|
body: json
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
params:path {
|
||||||
|
userID: 0hlO48C7Jw1J804FxrCnonKjQ2zh48R6
|
||||||
|
}
|
||||||
|
|
||||||
|
body:json {
|
||||||
|
{
|
||||||
|
"module":"siloAdjustments",
|
||||||
|
"role":"viewer"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
settings {
|
||||||
|
encodeUrl: true
|
||||||
|
timeout: 0
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
vars {
|
vars {
|
||||||
url: https://usiow2prod.alpla.net
|
url: http://localhost:4200
|
||||||
session_cookie:
|
session_cookie:
|
||||||
urlv2: http://localhost:3000
|
urlv2: http://localhost:3000
|
||||||
jwtV2:
|
jwtV2:
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import morgan from "morgan";
|
|||||||
import os from "os";
|
import os from "os";
|
||||||
import { dirname, join } from "path";
|
import { dirname, join } from "path";
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
|
import { userMigrate } from "./src/internal/auth/controller/userMigrate.js";
|
||||||
import { schedulerManager } from "./src/internal/logistics/controller/schedulerManager.js";
|
import { schedulerManager } from "./src/internal/logistics/controller/schedulerManager.js";
|
||||||
import { printers } from "./src/internal/ocp/printers/printers.js";
|
import { printers } from "./src/internal/ocp/printers/printers.js";
|
||||||
import { setupRoutes } from "./src/internal/routerHandler/routeHandler.js";
|
import { setupRoutes } from "./src/internal/routerHandler/routeHandler.js";
|
||||||
@@ -188,6 +189,7 @@ const main = async () => {
|
|||||||
|
|
||||||
// start up the v1listener
|
// start up the v1listener
|
||||||
v1Listener();
|
v1Listener();
|
||||||
|
userMigrate();
|
||||||
}, 5 * 1000);
|
}, 5 * 1000);
|
||||||
|
|
||||||
// start the server up
|
// start the server up
|
||||||
|
|||||||
34
app/src/internal/auth/controller/userMigrate.ts
Normal file
34
app/src/internal/auth/controller/userMigrate.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { Client } from "pg";
|
||||||
|
import { auth } from "../../../pkg/auth/auth.js";
|
||||||
|
import { createLogger } from "../../../pkg/logger/logger.js";
|
||||||
|
|
||||||
|
export const userMigrate = async () => {
|
||||||
|
const log = createLogger({ module: "admin", subModule: "migrate users" });
|
||||||
|
const client = new Client({
|
||||||
|
connectionString: process.env.DATABASE_URL_V1,
|
||||||
|
});
|
||||||
|
|
||||||
|
await client.connect();
|
||||||
|
|
||||||
|
const res = await client.query(`
|
||||||
|
SELECT username, email
|
||||||
|
FROM users
|
||||||
|
`);
|
||||||
|
|
||||||
|
for (const u of res.rows) {
|
||||||
|
log.info({}, `${u.username}, being transferred`);
|
||||||
|
try {
|
||||||
|
await auth.api.signUpEmail({
|
||||||
|
body: {
|
||||||
|
username: u.username,
|
||||||
|
name: u.username,
|
||||||
|
email: u.email,
|
||||||
|
password: "Alpla2025!",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
log.info({}, `${u.username}, transferred`);
|
||||||
|
} catch (e) {
|
||||||
|
log.info({}, `${u.username}, already existed`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -53,7 +53,7 @@ router.post("/", async (req: Request, res: Response) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (err instanceof APIError) {
|
if (err instanceof APIError) {
|
||||||
return res.status(400).json({
|
return res.status(200).json({
|
||||||
success: false,
|
success: false,
|
||||||
message: err.message,
|
message: err.message,
|
||||||
error: err.status,
|
error: err.status,
|
||||||
|
|||||||
10
app/src/internal/system/controller/modules/baseModules.ts
Normal file
10
app/src/internal/system/controller/modules/baseModules.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { readFileSync } from "fs";
|
||||||
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
|
export const baseModules = async () => {
|
||||||
|
const modulePath = path.resolve(__dirname, "./modules.json");
|
||||||
|
};
|
||||||
30
app/src/internal/system/controller/modules/modules.json
Normal file
30
app/src/internal/system/controller/modules/modules.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "plantToken",
|
||||||
|
"value": "test3",
|
||||||
|
"description": "The plant token for the plant IE: test3 or usday1",
|
||||||
|
"moduleName": "system",
|
||||||
|
"roles": ["systemAdmin"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "dbServer",
|
||||||
|
"value": "usmcd1vms036",
|
||||||
|
"description": "What is the db server",
|
||||||
|
"moduleName": "system",
|
||||||
|
"roles": ["systemAdmin"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "v1Server",
|
||||||
|
"value": "localhost",
|
||||||
|
"description": "What is the port the v1app is on",
|
||||||
|
"moduleName": "system",
|
||||||
|
"roles": ["systemAdmin"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "v1Port",
|
||||||
|
"value": "3000",
|
||||||
|
"description": "What is the port the v1app is on",
|
||||||
|
"moduleName": "system",
|
||||||
|
"roles": ["systemAdmin"]
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -1,40 +1,41 @@
|
|||||||
import { OpenAPIHono } from "@hono/zod-openapi";
|
import { OpenAPIHono } from "@hono/zod-openapi";
|
||||||
|
|
||||||
import login from "./routes/login.js";
|
import login from "./routes/login.js";
|
||||||
import register from "./routes/register.js";
|
import register from "./routes/register.js";
|
||||||
import session from "./routes/session.js";
|
import session from "./routes/session.js";
|
||||||
import getAccess from "./routes/user/getUserRoles.js";
|
import getAccess from "./routes/user/getUserRoles.js";
|
||||||
import setAccess from "./routes/userAdmin/setUserRoles.js";
|
|
||||||
import profile from "./routes/user/profileUpdate.js";
|
import profile from "./routes/user/profileUpdate.js";
|
||||||
import { areRolesIn } from "./utils/roleCheck.js";
|
|
||||||
import createUser from "./routes/userAdmin/createUser.js";
|
import createUser from "./routes/userAdmin/createUser.js";
|
||||||
import allUsers from "./routes/userAdmin/getUsers.js";
|
|
||||||
import updateUser from "./routes/userAdmin/updateUser.js";
|
|
||||||
import allUserRoles from "./routes/userAdmin/getAllUserRoles.js";
|
import allUserRoles from "./routes/userAdmin/getAllUserRoles.js";
|
||||||
|
import allUsers from "./routes/userAdmin/getUsers.js";
|
||||||
|
import setAccess from "./routes/userAdmin/setUserRoles.js";
|
||||||
|
import updateUser from "./routes/userAdmin/updateUser.js";
|
||||||
import { massAccountCreation } from "./utils/DefaultAccountCreation.js";
|
import { massAccountCreation } from "./utils/DefaultAccountCreation.js";
|
||||||
|
import { areRolesIn } from "./utils/roleCheck.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
// run the role check
|
// run the role check
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
areRolesIn();
|
areRolesIn();
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
login,
|
login,
|
||||||
register,
|
register,
|
||||||
session,
|
session,
|
||||||
profile,
|
profile,
|
||||||
getAccess,
|
getAccess,
|
||||||
setAccess,
|
setAccess,
|
||||||
createUser,
|
createUser,
|
||||||
allUsers,
|
allUsers,
|
||||||
allUserRoles,
|
allUserRoles,
|
||||||
updateUser,
|
updateUser,
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
// app.route("/server", modules);
|
// app.route("/server", modules);
|
||||||
const appRoutes = routes.forEach((route) => {
|
const appRoutes = routes.forEach((route) => {
|
||||||
app.route("/auth", route);
|
app.route("/auth", route);
|
||||||
});
|
});
|
||||||
|
|
||||||
// setTimeout(() => {
|
// setTimeout(() => {
|
||||||
|
|||||||
@@ -1,115 +1,108 @@
|
|||||||
|
import { format } from "date-fns-tz";
|
||||||
import { sql } from "drizzle-orm";
|
import { sql } from "drizzle-orm";
|
||||||
import { db } from "../../../../database/dbclient.js";
|
import { db } from "../../../../database/dbclient.js";
|
||||||
import { invHistoricalData } from "../../../../database/schema/historicalINV.js";
|
import { invHistoricalData } from "../../../../database/schema/historicalINV.js";
|
||||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
import { createLog } from "../../logger/logger.js";
|
import { createLog } from "../../logger/logger.js";
|
||||||
import { query } from "../../sqlServer/prodSqlServer.js";
|
|
||||||
import { totalInvNoRn } from "../../sqlServer/querys/dataMart/totalINV.js";
|
|
||||||
import { format } from "date-fns-tz";
|
|
||||||
import { serverSettings } from "../../server/controller/settings/getSettings.js";
|
import { serverSettings } from "../../server/controller/settings/getSettings.js";
|
||||||
import { deleteHistory } from "./removeHistorical.js";
|
import { query } from "../../sqlServer/prodSqlServer.js";
|
||||||
import { activeArticle } from "../../sqlServer/querys/dataMart/article.js";
|
import { activeArticle } from "../../sqlServer/querys/dataMart/article.js";
|
||||||
|
import { totalInvNoRn } from "../../sqlServer/querys/dataMart/totalINV.js";
|
||||||
|
import { deleteHistory } from "./removeHistorical.js";
|
||||||
|
|
||||||
export const historicalInvIMmport = async () => {
|
export const historicalInvIMmport = async () => {
|
||||||
const plantToken = serverSettings.filter((n) => n.name === "plantToken");
|
const plantToken = serverSettings.filter((n) => n.name === "plantToken");
|
||||||
const { data, error } = (await tryCatch(
|
const { data, error } = (await tryCatch(
|
||||||
db.select().from(invHistoricalData)
|
db.select().from(invHistoricalData),
|
||||||
)) as any;
|
)) as any;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
createLog(
|
createLog(
|
||||||
"error",
|
"error",
|
||||||
"eom",
|
"eom",
|
||||||
"eom",
|
"eom",
|
||||||
`There was an error getting the historical data`
|
`There was an error getting the historical data`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// check if we have data already for today this way we dont duplicate anything.
|
// check if we have data already for today this way we dont duplicate anything.
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
//today.setDate(today.getDate() - 1);
|
//today.setDate(today.getDate() - 1);
|
||||||
|
|
||||||
const dateCheck = data?.filter(
|
const dateCheck = data?.filter(
|
||||||
(i: any) => i.histDate === format(today, "yyyy-MM-dd")
|
(i: any) => i.histDate === format(today, "yyyy-MM-dd"),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (dateCheck.length === 0) {
|
if (dateCheck.length === 0) {
|
||||||
// get the historical data from the sql
|
// get the historical data from the sql
|
||||||
const { data: inv, error: invError } = (await tryCatch(
|
const { data: inv, error: invError } = (await tryCatch(
|
||||||
query(totalInvNoRn, "eom historical data")
|
query(totalInvNoRn.replace("(6, 1)", "(6)"), "eom historical data"),
|
||||||
)) as any;
|
)) as any;
|
||||||
|
|
||||||
if (invError) {
|
if (invError) {
|
||||||
createLog(
|
createLog(
|
||||||
"error",
|
"error",
|
||||||
"eom",
|
"eom",
|
||||||
"eom",
|
"eom",
|
||||||
`There was an error getting the sql data`
|
`There was an error getting the sql data`,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inv.data.length === 0) {
|
if (inv.data.length === 0) {
|
||||||
createLog("error", "eom", "eom", inv.message);
|
createLog("error", "eom", "eom", inv.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data: articles, error: avError } = (await tryCatch(
|
const { data: articles, error: avError } = (await tryCatch(
|
||||||
query(activeArticle, "Get active articles")
|
query(activeArticle, "Get active articles"),
|
||||||
)) as any;
|
)) as any;
|
||||||
|
|
||||||
const av = articles.data.length > 0 ? articles.data : ([] as any);
|
const av = articles.data.length > 0 ? articles.data : ([] as any);
|
||||||
|
|
||||||
const importInv = inv.data ? inv.data : [];
|
const importInv = inv.data ? inv.data : [];
|
||||||
const eomImportData = importInv.map((i: any) => {
|
const eomImportData = importInv.map((i: any) => {
|
||||||
return {
|
return {
|
||||||
//histDate: sql`(NOW() - INTERVAL '1 day')::date`,
|
//histDate: sql`(NOW() - INTERVAL '1 day')::date`,
|
||||||
histDate: sql`(NOW())::date`,
|
histDate: sql`(NOW())::date`,
|
||||||
plantToken: plantToken[0].value,
|
plantToken: plantToken[0].value,
|
||||||
article: i.av,
|
article: i.av,
|
||||||
articleDescription: i.Alias,
|
articleDescription: i.Alias,
|
||||||
materialType:
|
materialType:
|
||||||
av.filter((a: any) => a.IdArtikelvarianten === i.av)
|
av.filter((a: any) => a.IdArtikelvarianten === i.av).length > 0
|
||||||
.length > 0
|
? av.filter((a: any) => a.IdArtikelvarianten === i.av)[0]
|
||||||
? av.filter(
|
?.TypeOfMaterial
|
||||||
(a: any) => a.IdArtikelvarianten === i.av
|
: "Item not defined",
|
||||||
)[0]?.TypeOfMaterial
|
total_QTY: i.Total_PalletQTY,
|
||||||
: "Item not defined",
|
avaliable_QTY: i.Avaliable_PalletQTY,
|
||||||
total_QTY: i.Total_PalletQTY,
|
coa_QTY: i.COA_QTY,
|
||||||
avaliable_QTY: i.Avaliable_PalletQTY,
|
held_QTY: i.Held_QTY,
|
||||||
coa_QTY: i.COA_QTY,
|
consignment: i.Consigment,
|
||||||
held_QTY: i.Held_QTY,
|
lot_Number: i.lot,
|
||||||
consignment: i.Consigment,
|
};
|
||||||
lot_Number: i.lot,
|
});
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
const { data: dataImport, error: errorImport } = await tryCatch(
|
const { data: dataImport, error: errorImport } = await tryCatch(
|
||||||
db.insert(invHistoricalData).values(eomImportData)
|
db.insert(invHistoricalData).values(eomImportData),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (errorImport) {
|
if (errorImport) {
|
||||||
createLog(
|
createLog(
|
||||||
"error",
|
"error",
|
||||||
"eom",
|
"eom",
|
||||||
"eom",
|
"eom",
|
||||||
`There was an error importing all the inventory data.`
|
`There was an error importing all the inventory data.`,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataImport) {
|
if (dataImport) {
|
||||||
createLog(
|
createLog("info", "eom", "eom", `All data was imported succefully.`);
|
||||||
"info",
|
return;
|
||||||
"eom",
|
}
|
||||||
"eom",
|
} else {
|
||||||
`All data was imported succefully.`
|
createLog("info", "eom", "eom", `Yesterdays Data already in..`);
|
||||||
);
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
createLog("info", "eom", "eom", `Yesterdays Data already in..`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// do the check to delete old data
|
// do the check to delete old data
|
||||||
deleteHistory();
|
deleteHistory();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user