fix(quality request): bug fixes

lots of bug fixes plug 2 new counters, quality inspect time and warehouse return time
This commit is contained in:
2025-11-12 20:22:21 -06:00
parent fef0303cd6
commit 6f632ecd68
17 changed files with 4986 additions and 316 deletions

View File

@@ -5,13 +5,13 @@ meta {
} }
get { get {
url: {{url}}/lst/old/api/eom/histinv?month=2025-11-01 url: {{url}}/lst/old/api/eom/histinv?month=2025/11/1
body: none body: none
auth: inherit auth: inherit
} }
params:query { params:query {
month: 2025-11-01 month: 2025/11/1
} }
settings { settings {

View File

@@ -0,0 +1,16 @@
meta {
name: materialPerDay
type: http
seq: 2
}
get {
url: {{urlv2}}/api/notify/materialperday
body: none
auth: inherit
}
settings {
encodeUrl: true
timeout: 0
}

View File

@@ -0,0 +1,25 @@
meta {
name: Add pallet
type: http
seq: 2
}
post {
url: {{url}}/lst/old/api/quality/newrequest
body: json
auth: inherit
}
body:json {
{
"username": "matthes01",
"runningNr": 618302,
"palletStatusText":"return" // returned will be the only allowed key
//"moveTo": "hold area" //hold area, rework, inspection
}
}
settings {
encodeUrl: true
timeout: 0
}

View File

@@ -0,0 +1,16 @@
meta {
name: Get Pallets
type: http
seq: 1
}
get {
url: {{url}}/lst/old/api/quality/getrequest
body: none
auth: inherit
}
settings {
encodeUrl: true
timeout: 0
}

View File

@@ -0,0 +1,8 @@
meta {
name: Quality
seq: 7
}
auth {
mode: inherit
}

View File

@@ -5,11 +5,16 @@ meta {
} }
get { get {
url: url: {{url}}/lst/api/user/me
body: none body: none
auth: inherit auth: bearer
}
auth:bearer {
token: jpHHbLNGJRpUMvfrVOYmhbJL2Ux0arse
} }
settings { settings {
encodeUrl: true encodeUrl: true
timeout: 0
} }

View File

@@ -0,0 +1,20 @@
meta {
name: otacheck
type: http
seq: 3
}
get {
url: http://10.193.0.56:4000/api/mobile/updates
body: none
auth: inherit
}
headers {
expo-runtime-version: 1.0.0
}
settings {
encodeUrl: true
timeout: 0
}

View File

@@ -0,0 +1 @@
ALTER TABLE "qualityRequest" ADD COLUMN "qualityDurationToInspect" integer;

View File

@@ -0,0 +1 @@
ALTER TABLE "qualityRequest" ADD COLUMN "returnDurationToInspect" integer;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -519,6 +519,20 @@
"when": 1760708711258, "when": 1760708711258,
"tag": "0073_bumpy_dust", "tag": "0073_bumpy_dust",
"breakpoints": true "breakpoints": true
},
{
"idx": 74,
"version": "7",
"when": 1762966327361,
"tag": "0074_overconfident_may_parker",
"breakpoints": true
},
{
"idx": 75,
"version": "7",
"when": 1762983466464,
"tag": "0075_tan_unicorn",
"breakpoints": true
} }
] ]
} }

View File

@@ -25,6 +25,8 @@ export const qualityRequest = pgTable(
warehouseMovedTo: text("warehouseMovedTo"), warehouseMovedTo: text("warehouseMovedTo"),
locationMovedTo: text("locationMovedTo"), locationMovedTo: text("locationMovedTo"),
durationToMove: integer("durationToMove"), durationToMove: integer("durationToMove"),
qualityDurationToInspect: integer("qualityDurationToInspect"),
returnDurationToInspect: integer("returnDurationToInspect"),
locationDropOff: text("locationDropOff"), locationDropOff: text("locationDropOff"),
palletStatus: integer("palletStatus"), palletStatus: integer("palletStatus"),
palletStatusText: text("palletStatusText"), palletStatusText: text("palletStatusText"),

View File

@@ -1,31 +1,32 @@
import { differenceInMinutes } from "date-fns";
import { eq, sql } from "drizzle-orm"; import { eq, sql } from "drizzle-orm";
import { db } from "../../../../database/dbclient.js"; import { db } from "../../../../database/dbclient.js";
import { qualityRequest } from "../../../../database/schema/qualityRequest.js"; import { qualityRequest } from "../../../../database/schema/qualityRequest.js";
import { timeZoneFix } from "../../../globalUtils/timeZoneFix.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js"; import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { query } from "../../sqlServer/prodSqlServer.js"; import { query } from "../../sqlServer/prodSqlServer.js";
import { qrequestQuery } from "../../sqlServer/querys/quality/request.js"; import { qrequestQuery } from "../../sqlServer/querys/quality/request.js";
import { timeZoneFix } from "../../../globalUtils/timeZoneFix.js";
export const addNewPallet = async (data: any, user: string) => { export const addNewPallet = async (data: any) => {
/** /**
* Post new pallets * Post new pallets
*/ */
if (parseInt(data.runningNr) <= 0) { if (parseInt(data.runningNr) <= 0) {
return { return {
sucess: false, success: false,
message: "Please add a valid running number.", message: "Please add a valid running number.",
}; };
} }
const updateQuery = qrequestQuery.replaceAll( const updateQuery = qrequestQuery.replaceAll(
"[runningNumber]", "[runningNumber]",
data.runningNr data.runningNr,
); );
const { data: c, error: ce } = await tryCatch( const { data: c, error: ce } = await tryCatch(
db db
.select() .select()
.from(qualityRequest) .from(qualityRequest)
.where(eq(qualityRequest.runningNr, data.runningNr)) .where(eq(qualityRequest.runningNr, data.runningNr)),
); );
if (ce) { if (ce) {
return { return {
@@ -37,23 +38,22 @@ export const addNewPallet = async (data: any, user: string) => {
const palletData: any = c; const palletData: any = c;
// if the pallet exist then tell the user to check on it // if the pallet exist then tell the user to check on it
if ( const pStatus = [1, 4, 6];
(palletData && palletData[0]?.palletStatus === 1) || if (palletData && pStatus.includes(palletData[0]?.palletStatus)) {
palletData[0]?.palletStatus === 4
) {
return { return {
success: false, success: false,
message: `Running number ${data.runningNr} is already pending or reactivated please follow up with the warehouse team on status to be moved.`, message: `Running number ${data.runningNr} is already pending or reactivated please follow up with the warehouse team on status to be moved.`,
}; };
} }
// update the existing pallet if already in the system
if (palletData.length > 0) { if (palletData.length > 0) {
try { try {
// get the pallet info from stock // get the pallet info from stock
const { data: pa, error: pe } = await tryCatch( const { data: pa, error: pe } = await tryCatch(
query(updateQuery, "quality request") query(updateQuery, "quality request"),
); );
const p: any = pa; const p: any = pa ? pa.data : [];
if (pe) { if (pe) {
return { return {
success: false, success: false,
@@ -66,19 +66,26 @@ export const addNewPallet = async (data: any, user: string) => {
locationAtRequest: p[0].locationAtRequest, locationAtRequest: p[0].locationAtRequest,
warehouseMovedTo: null, warehouseMovedTo: null,
locationMovedTo: null, locationMovedTo: null,
palletStatus: 4, palletStatus: data.palletStatusText === "return" ? 6 : 4,
durationToMove: 0, //durationToMove: 0,
palletStatusText: "reactivated", palletStatusText:
data.palletStatusText === "return" ? "return" : "reactivated",
qualityDurationToInspect:
data.palletStatusText === "return"
? differenceInMinutes(new Date(Date.now()), p[0].lastMove)
: 0,
locationDropOff:
data.palletStatusText === "return" ? "Return to warhouse" : "",
palletRequest: palletData[0].palletStatus + 1, palletRequest: palletData[0].palletStatus + 1,
upd_user: user, upd_user: data.user,
upd_date: new Date(timeZoneFix()), upd_date: sql`NOW()`,
}; };
const { data: u, error } = await tryCatch( const { data: u, error } = await tryCatch(
db db
.update(qualityRequest) .update(qualityRequest)
.set(pData) .set(pData)
.where(eq(qualityRequest.runningNr, data.runningNr)) .where(eq(qualityRequest.runningNr, data.runningNr)),
); );
if (error) { if (error) {
@@ -97,10 +104,10 @@ export const addNewPallet = async (data: any, user: string) => {
}; };
} }
} catch (error) { } catch (error) {
console.log(error);
return { return {
success: false, success: false,
message: message: "There was an error updating the pallet in quality request",
"There was an error updating the pallet in quality request",
data: error, data: error,
}; };
} }
@@ -109,13 +116,14 @@ export const addNewPallet = async (data: any, user: string) => {
// add new pallet // add new pallet
try { try {
const { data: px, error: pe } = await tryCatch( const { data: px, error: pe } = await tryCatch(
query(updateQuery, "quality request") query(updateQuery, "quality request"),
); );
const p: any = px;
const p: any = px ? px.data : [];
if (p.length === 0) { if (p.length === 0) {
return { return {
success: false, success: false,
message: `Running Number ${data.runningNr} dose not exist in stock.`, message: `Running Number ${data.runningNr} dose not exist in stock, please check the running number and try again.`,
}; };
} }
@@ -126,7 +134,7 @@ export const addNewPallet = async (data: any, user: string) => {
data: pe, data: pe,
}; };
} }
console.log(p);
const nData = { const nData = {
article: p[0].article, article: p[0].article,
description: p[0].description, description: p[0].description,
@@ -138,12 +146,12 @@ export const addNewPallet = async (data: any, user: string) => {
palletStatus: 1, palletStatus: 1,
palletStatusText: "pending", palletStatusText: "pending",
palletRequest: 1, palletRequest: 1,
add_user: user, add_user: data.user,
upd_user: user, upd_user: data.user,
}; };
const { data: u, error } = await tryCatch( const { data: u, error } = await tryCatch(
db.insert(qualityRequest).values(nData) db.insert(qualityRequest).values(nData).onConflictDoNothing(),
); );
if (error) { if (error) {
@@ -162,6 +170,7 @@ export const addNewPallet = async (data: any, user: string) => {
}; };
} }
} catch (error) { } catch (error) {
console.log(error);
return { return {
success: false, success: false,
message: "There was an error adding the pallet in quality request", message: "There was an error adding the pallet in quality request",

View File

@@ -1,20 +1,23 @@
import { eq, inArray } from "drizzle-orm"; import { differenceInMinutes } from "date-fns";
import { eq, inArray, sql } from "drizzle-orm";
import { db } from "../../../../database/dbclient.js"; import { db } from "../../../../database/dbclient.js";
import { qualityRequest } from "../../../../database/schema/qualityRequest.js"; import { qualityRequest } from "../../../../database/schema/qualityRequest.js";
import { delay } from "../../../globalUtils/delay.js";
import { timeZoneFix } from "../../../globalUtils/timeZoneFix.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 { qrequestQuery } from "../../sqlServer/querys/quality/request.js";
import { query } from "../../sqlServer/prodSqlServer.js"; import { query } from "../../sqlServer/prodSqlServer.js";
import { differenceInMinutes } from "date-fns"; import { qrequestQuery } from "../../sqlServer/querys/quality/request.js";
import { timeZoneFix } from "../../../globalUtils/timeZoneFix.js";
export const qualityCycle = async () => { export const qualityCycle = async () => {
/** /**
* Cycles the pallets in the quality request to see whats been moved or changed. * Cycles the pallets in the quality request to see whats been moved or changed.
*/ */
const warehouse = [1, 4, 5];
// pallet request check interval 5min check to start // pallet request check interval 5min check to start
//setInterval(async () => { setInterval(
async () => {
// create the date stuff // create the date stuff
const currentTime = new Date(Date.now()); const currentTime = new Date(Date.now());
@@ -23,7 +26,7 @@ export const qualityCycle = async () => {
db db
.select() .select()
.from(qualityRequest) .from(qualityRequest)
.where(inArray(qualityRequest.palletStatus, [1, 4, 5])) .where(inArray(qualityRequest.palletStatus, [1, 4, 5, 6])),
); );
if (error) { if (error) {
@@ -31,7 +34,7 @@ export const qualityCycle = async () => {
"error", "error",
"lst", "lst",
"quality", "quality",
`There was an error getting quality request data: ${error}` `There was an error getting quality request data: ${error}`,
); );
return { return {
success: false, success: false,
@@ -48,15 +51,15 @@ export const qualityCycle = async () => {
// console.log(lstQData[i]); // console.log(lstQData[i]);
//update query with plant token //update query with plant token
// change the update the pallet number // update the the pallet number
const qPalletNumber = qrequestQuery.replaceAll( const qPalletNumber = qrequestQuery.replaceAll(
"[runningNumber]", "[runningNumber]",
lstQData[i].runningNr lstQData[i].runningNr,
); );
const queryData: any = await query( const queryData: any = await query(
qPalletNumber, qPalletNumber,
"Quality update check" "Quality update check",
); );
let prodData: any = let prodData: any =
queryData?.data.length === 0 ? [] : queryData.data; queryData?.data.length === 0 ? [] : queryData.data;
@@ -68,13 +71,24 @@ export const qualityCycle = async () => {
const qDataPost = { const qDataPost = {
warehouseMovedTo: prodData[0]?.warehouseAtRequest, warehouseMovedTo: prodData[0]?.warehouseAtRequest,
locationMovedTo: prodData[0]?.locationAtRequest, locationMovedTo: prodData[0]?.locationAtRequest,
durationToMove: differenceInMinutes( // how ling did it take the warhouse to originally move the pallet
timeZoneFix(), durationToMove: warehouse.includes(lstQData[i].palletStatus)
lstQData[i].upd_date ? differenceInMinutes(
), new Date(Date.now()),
lstQData[i].upd_date,
)
: lstQData[i].durationToMove,
// how long did it take warehouse to move the pallet back agian
returnDurationToInspect:
lstQData[i].palletStatus === 7
? differenceInMinutes(
new Date(Date.now()),
lstQData[i].upd_date,
)
: lstQData[i].qualityDurationToInspect,
palletStatus: 2, palletStatus: 2,
palletStatusText: "moved", palletStatusText: "moved",
upd_date: new Date(timeZoneFix()), upd_date: sql`NOW()`,
upd_user: "LST_System", upd_user: "LST_System",
}; };
@@ -87,24 +101,27 @@ export const qualityCycle = async () => {
"info", "info",
"lst", "lst",
"quality", "quality",
`Pallet ${lstQData[i].runningNr} was updated` `Pallet ${lstQData[i].runningNr} was updated`,
); );
} else { } else {
createLog( createLog(
"debug", "info",
"lst", "lst",
"quality", "quality",
`Pallet ${ `Pallet ${
lstQData[i].runningNr lstQData[i].runningNr
} has not been moved yet it has been pending for ${differenceInMinutes( } has not been moved yet it has been pending for ${differenceInMinutes(
timeZoneFix(), new Date(Date.now()),
lstQData[i].upd_date lstQData[i].upd_date,
)} min(s)` )} min(s)`,
); );
} }
} }
await delay(150);
} else { } else {
createLog("debug", "lst", "quality", "nothing to update"); createLog("info", "lst", "quality", "nothing to update");
} }
//}, 5 * 60 * 1000); // every 5 min },
5 * 60 * 1000,
); // every 5 min
}; };

View File

@@ -10,6 +10,8 @@ export const statusOptions = [
{ name: "removed", uid: "3" }, { name: "removed", uid: "3" },
{ name: "reactivated", uid: "4" }, { name: "reactivated", uid: "4" },
{ name: "canceled", uid: "5" }, { name: "canceled", uid: "5" },
{ name: "return", uid: "6" },
{ name: "readyToReturn", uid: "7" },
]; ];
const app = new OpenAPIHono(); const app = new OpenAPIHono();

View File

@@ -1,17 +1,17 @@
// an external way to creating logs // an external way to creating logs
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi"; import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
import { verify } from "hono/jwt";
import { apiHit } from "../../../globalUtils/apiHits.js";
import { responses } from "../../../globalUtils/routeDefs/responses.js"; import { responses } from "../../../globalUtils/routeDefs/responses.js";
import { getRequest } from "../controller/getRequests.js";
import { tryCatch } from "../../../globalUtils/tryCatch.js"; import { tryCatch } from "../../../globalUtils/tryCatch.js";
import { authMiddleware } from "../../auth/middleware/authMiddleware.js"; import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
import { addNewPallet } from "../controller/addNewPallet.js"; import { addNewPallet } from "../controller/addNewPallet.js";
import { verify } from "hono/jwt"; import { getRequest } from "../controller/getRequests.js";
import { apiHit } from "../../../globalUtils/apiHits.js";
const app = new OpenAPIHono({ strict: false }); const app = new OpenAPIHono({ strict: false });
const Body = z.object({ const Body = z.object({
runningNr: z.number().openapi({ example: 1528 }), runningNr: z.number().openapi({ example: 1528 }),
moveTo: z.string().openapi({ example: "rework" }), moveTo: z.string().optional().openapi({ example: "rework" }),
}); });
app.openapi( app.openapi(
createRoute({ createRoute({
@@ -30,11 +30,11 @@ app.openapi(
responses: responses(), responses: responses(),
}), }),
async (c) => { async (c) => {
const authHeader = c.req.header("Authorization"); // const authHeader = c.req.header("Authorization");
const token = authHeader?.split("Bearer ")[1] || ""; // const token = authHeader?.split("Bearer ")[1] || "";
const payload = await verify(token, process.env.JWT_SECRET!); // const payload = await verify(token, process.env.JWT_SECRET!);
const user: any = payload.user; // const user: any = payload.user;
const { data: b, error: e } = await tryCatch(c.req.json()); const { data: b, error: e } = await tryCatch(c.req.json());
apiHit(c, { endpoint: "/newrequest", lastBody: b }); apiHit(c, { endpoint: "/newrequest", lastBody: b });
@@ -53,9 +53,7 @@ app.openapi(
// }); // });
// } // }
const { data, error } = await tryCatch( const { data, error } = await tryCatch(addNewPallet(body));
addNewPallet(body, user?.username)
);
if (error) { if (error) {
return c.json({ return c.json({
@@ -69,6 +67,6 @@ app.openapi(
message: data?.message, message: data?.message,
data: data?.data, data: data?.data,
}); });
} },
); );
export default app; export default app;