feat(silo): added in charts and historical data
This commit is contained in:
@@ -56,17 +56,17 @@ export const migrateAdjustments = async () => {
|
||||
/**
|
||||
* Migrate all the silo adjustments :D
|
||||
*/
|
||||
const silo: any = s?.data;
|
||||
const silo: any = s?.data.data;
|
||||
createLog("info", "silo", "logistics", "Starting migration.");
|
||||
for (let i = 0; i < silo.length; i++) {
|
||||
const migrate = await db.insert(siloAdjustments).values({
|
||||
warehouseID: silo[0].warehouseID,
|
||||
locationID: silo[0].locationID,
|
||||
currentStockLevel: silo[0].currentStockLevel,
|
||||
newLevel: silo[0].newLevel,
|
||||
dateAdjusted: new Date(silo[0].dateAdjusted),
|
||||
lastDateAdjusted: new Date(silo[0].lastDateAdjusted),
|
||||
add_user: silo[0].add_user,
|
||||
warehouseID: silo[i].warehouseID,
|
||||
locationID: silo[i].locationID,
|
||||
currentStockLevel: silo[i].currentStockLevel,
|
||||
newLevel: silo[i].newLevel,
|
||||
dateAdjusted: new Date(silo[i].dateAdjusted),
|
||||
lastDateAdjusted: new Date(silo[i].lastDateAdjusted),
|
||||
add_user: silo[i].add_user,
|
||||
});
|
||||
createLog(
|
||||
"info",
|
||||
@@ -87,5 +87,3 @@ export const migrateAdjustments = async () => {
|
||||
.where(eq(settings.name, "siloAdjMigrations"));
|
||||
createLog("info", "silo", "logistics", "Migration completed.");
|
||||
};
|
||||
|
||||
migrateAdjustments();
|
||||
|
||||
@@ -7,6 +7,8 @@ import postComment from "./route/siloAdjustments/postComment.js";
|
||||
import getStockSilo from "./route/siloAdjustments/getStockData.js";
|
||||
import { migrateAdjustments } from "./controller/siloAdjustments/migrateAdjustments.js";
|
||||
import getSiloAdjustments from "./route/siloAdjustments/getSiloAdjustments.js";
|
||||
import { getLanesToCycleCount } from "./controller/warehouse/cycleCountChecks/cyclecountCheck.js";
|
||||
import getCycleCountCheck from "./route/getCycleCountChecks.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
@@ -19,6 +21,8 @@ const routes = [
|
||||
postComment,
|
||||
getStockSilo,
|
||||
getSiloAdjustments,
|
||||
//lanes
|
||||
getCycleCountCheck,
|
||||
] as const;
|
||||
|
||||
// app.route("/server", modules);
|
||||
@@ -28,6 +32,17 @@ const appRoutes = routes.forEach((route) => {
|
||||
|
||||
setTimeout(() => {
|
||||
migrateAdjustments();
|
||||
}, 10 * 1000);
|
||||
}, 120 * 1000);
|
||||
|
||||
/**
|
||||
* Start the cycle count check
|
||||
*/
|
||||
|
||||
setTimeout(() => {
|
||||
getLanesToCycleCount();
|
||||
}, 5 * 1000);
|
||||
setInterval(async () => {
|
||||
getLanesToCycleCount();
|
||||
}, 15 * 60 * 1000);
|
||||
|
||||
export default app;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
||||
import {modules} from "../../../../../database/schema/modules.js";
|
||||
import {db} from "../../../../../database/dbclient.js";
|
||||
import { z, createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
||||
import { modules } from "../../../../../database/schema/modules.js";
|
||||
import { db } from "../../../../../database/dbclient.js";
|
||||
import { desc } from "drizzle-orm";
|
||||
|
||||
// Define the request body schema
|
||||
const requestSchema = z.object({
|
||||
@@ -13,10 +14,16 @@ const requestSchema = z.object({
|
||||
// Define the response schema
|
||||
const responseSchema = z.object({
|
||||
message: z.string().optional(),
|
||||
module_id: z.string().openapi({example: "6c922c6c-7de3-4ec4-acb0-f068abdc"}).optional(),
|
||||
name: z.string().openapi({example: "Production"}).optional(),
|
||||
active: z.boolean().openapi({example: true}).optional(),
|
||||
roles: z.string().openapi({example: `["viewer","technician"]`}).optional(),
|
||||
module_id: z
|
||||
.string()
|
||||
.openapi({ example: "6c922c6c-7de3-4ec4-acb0-f068abdc" })
|
||||
.optional(),
|
||||
name: z.string().openapi({ example: "Production" }).optional(),
|
||||
active: z.boolean().openapi({ example: true }).optional(),
|
||||
roles: z
|
||||
.string()
|
||||
.openapi({ example: `["viewer","technician"]` })
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
@@ -30,7 +37,7 @@ app.openapi(
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {schema: responseSchema},
|
||||
"application/json": { schema: responseSchema },
|
||||
},
|
||||
description: "Response message",
|
||||
},
|
||||
@@ -40,7 +47,7 @@ app.openapi(
|
||||
//console.log("system modules");
|
||||
let module: any = [];
|
||||
try {
|
||||
module = await db.select().from(modules); // .where(eq(modules.active, true));
|
||||
module = await db.select().from(modules).orderBy(modules.name); // .where(eq(modules.active, true));
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
module = [];
|
||||
@@ -49,7 +56,7 @@ app.openapi(
|
||||
// parse the roles
|
||||
const updateModules = module.map((m: any) => {
|
||||
if (m.roles) {
|
||||
return {...m, roles: m?.roles};
|
||||
return { ...m, roles: m?.roles };
|
||||
}
|
||||
return m;
|
||||
}); //JSON.parse(module[0]?.roles);
|
||||
|
||||
@@ -47,7 +47,10 @@ app.openapi(
|
||||
//console.log("system modules");
|
||||
let module: any = [];
|
||||
try {
|
||||
module = await db.select().from(subModules); // .where(eq(modules.active, true));
|
||||
module = await db
|
||||
.select()
|
||||
.from(subModules)
|
||||
.orderBy(subModules.name); // .where(eq(modules.active, true));
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
module = [];
|
||||
|
||||
@@ -3,42 +3,69 @@
|
||||
* this will only run on a server start up
|
||||
*/
|
||||
|
||||
import {db} from "../../../../database/dbclient.js";
|
||||
import {modules} from "../../../../database/schema/modules.js";
|
||||
import {createLog} from "../../logger/logger.js";
|
||||
import { db } from "../../../../database/dbclient.js";
|
||||
import { modules } from "../../../../database/schema/modules.js";
|
||||
import { createLog } from "../../logger/logger.js";
|
||||
// "view", "technician", "supervisor","manager", "admin", "systemAdmin"
|
||||
const newModules = [
|
||||
{name: "production", active: true, roles: ["viewer", "tester", "systemAdmin"]},
|
||||
{name: "logistics", active: false, roles: ["viewer", "tester", "systemAdmin"]},
|
||||
{name: "quality", active: false, roles: ["viewer", "manager", "tester", "systemAdmin"]},
|
||||
{name: "forklift", active: false, roles: ["manager", "admin", "tester", "systemAdmin"]},
|
||||
{name: "eom", active: false, roles: ["manager", "admin", "tester", "systemAdmin"]},
|
||||
{name: "admin", active: true, roles: ["admin", "systemAdmin"]},
|
||||
{name: "ocp", active: false, roles: ["viewer", "admin", "tester", "systemAdmin"]},
|
||||
const newModules: any = [
|
||||
{
|
||||
name: "production",
|
||||
active: true,
|
||||
roles: ["viewer", "tester", "systemAdmin"],
|
||||
},
|
||||
{
|
||||
name: "logistics",
|
||||
active: false,
|
||||
roles: ["viewer", "manager", "supervisor", "tester", "systemAdmin"],
|
||||
},
|
||||
{
|
||||
name: "quality",
|
||||
active: false,
|
||||
roles: ["viewer", "manager", "tester", "systemAdmin"],
|
||||
},
|
||||
{
|
||||
name: "forklift",
|
||||
active: false,
|
||||
roles: ["manager", "admin", "tester", "systemAdmin"],
|
||||
},
|
||||
{
|
||||
name: "eom",
|
||||
active: false,
|
||||
roles: ["manager", "admin", "tester", "systemAdmin"],
|
||||
},
|
||||
{ name: "admin", active: true, roles: ["admin", "systemAdmin"] },
|
||||
{
|
||||
name: "ocp",
|
||||
active: false,
|
||||
roles: ["viewer", "admin", "tester", "systemAdmin"],
|
||||
},
|
||||
];
|
||||
export const areModulesIn = async () => {
|
||||
// get the roles
|
||||
try {
|
||||
const moduleCheck = await db.select().from(modules);
|
||||
|
||||
if (moduleCheck.length !== newModules.length) {
|
||||
try {
|
||||
const newRole = await db
|
||||
for (let i = 0; i < newModules.length; i++) {
|
||||
try {
|
||||
const newRole = await db
|
||||
.insert(modules)
|
||||
.values(newModules)
|
||||
.onConflictDoNothing() // this will only update the ones that are new :D
|
||||
.returning({name: modules.name});
|
||||
createLog("info", "lst", "server", "Roles were just added due to missing them on server startup");
|
||||
} catch (error) {
|
||||
createLog("error", "lst", "server", "There was an error adding new roles to the db");
|
||||
}
|
||||
.values(newModules[i])
|
||||
.onConflictDoUpdate({
|
||||
target: modules.name,
|
||||
set: { roles: newModules[i].roles },
|
||||
}) // this will only update the ones that are new :D
|
||||
.returning({ name: modules.name });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"server",
|
||||
"There was an error adding new modules to the db"
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
createLog(
|
||||
"error",
|
||||
"lst",
|
||||
"server",
|
||||
`Error: ${JSON.stringify(error)}"There was an error getting or adding new roles"`
|
||||
);
|
||||
}
|
||||
createLog(
|
||||
"info",
|
||||
"lst",
|
||||
"server",
|
||||
"Modules were just added due to missing them on server startup"
|
||||
);
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ const newSubModules = [
|
||||
link: "/siloAdjustments",
|
||||
icon: "Cylinder",
|
||||
active: false,
|
||||
roles: ["tester", "systemAdmin"],
|
||||
roles: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
||||
subSubModule: [],
|
||||
},
|
||||
{
|
||||
@@ -38,16 +38,6 @@ const newSubModules = [
|
||||
active: false,
|
||||
subSubModule: [],
|
||||
},
|
||||
{
|
||||
name: "Ocme cycle counts",
|
||||
moduleName: "logistics",
|
||||
description: "",
|
||||
link: "#",
|
||||
icon: "Package",
|
||||
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
||||
active: false,
|
||||
subSubModule: [],
|
||||
},
|
||||
{
|
||||
name: "Material Helper",
|
||||
moduleName: "logistics",
|
||||
|
||||
Reference in New Issue
Block a user