From 29b3be41a1de98d886df9ebaeab73b994a05883e Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Mon, 16 Feb 2026 09:38:10 -0600 Subject: [PATCH] build(notification): fixed fifo index ts errors --- .../services/logistics/logisticsService.ts | 3 + .../controller/notifications/fifoIndex.ts | 186 +++++++++--------- 2 files changed, 96 insertions(+), 93 deletions(-) diff --git a/lstV2/server/services/logistics/logisticsService.ts b/lstV2/server/services/logistics/logisticsService.ts index 0322f26..a5b2173 100644 --- a/lstV2/server/services/logistics/logisticsService.ts +++ b/lstV2/server/services/logistics/logisticsService.ts @@ -1,7 +1,9 @@ import { OpenAPIHono } from "@hono/zod-openapi"; + import { migrateAdjustments } from "./controller/siloAdjustments/migrateAdjustments.js"; import { getLanesToCycleCount } from "./controller/warehouse/cycleCountChecks/cyclecountCheck.js"; import attachSilo from "./route/attachSilo.js"; +import bookOutPallet from "./route/bookout.js"; import comsumeMaterial from "./route/consumeMaterial.js"; import detachSilo from "./route/detachSilo.js"; import postBulkOrders from "./route/dm/bulkOrdersIn.js"; @@ -56,6 +58,7 @@ const routes = [ // logisitcs removeAsNonReable, getSSCC, + bookOutPallet, ] as const; // app.route("/server", modules); diff --git a/lstV2/server/services/notifications/controller/notifications/fifoIndex.ts b/lstV2/server/services/notifications/controller/notifications/fifoIndex.ts index a3f8c1a..02f4242 100644 --- a/lstV2/server/services/notifications/controller/notifications/fifoIndex.ts +++ b/lstV2/server/services/notifications/controller/notifications/fifoIndex.ts @@ -1,112 +1,112 @@ import { isBefore } from "date-fns"; +import { db } from "../../../../../database/dbclient.js"; +import { fifoIndex } from "../../../../../database/schema/fifoIndex.js"; import { tryCatch } from "../../../../globalUtils/tryCatch.js"; import { query } from "../../../sqlServer/prodSqlServer.js"; import { currentInv } from "../../../sqlServer/querys/notifications/fifoIndex/currentInv.js"; import { shippedPallets } from "../../../sqlServer/querys/notifications/fifoIndex/shippedPallets.js"; -import { db } from "../../../../../database/dbclient.js"; -import { fifoIndex } from "../../../../../database/schema/fifoIndex.js"; export default async function fifoIndexCheck() { - /** - * getting the shipped pallets - */ - const { data: shipped, error: eShipped } = await tryCatch( - query(shippedPallets, "notify shipped pallets") - ); + /** + * getting the shipped pallets + */ + const { data: shipped, error: eShipped } = await tryCatch( + query(shippedPallets, "notify shipped pallets"), + ); - const { data: currentStuff, error: eCurrentInv } = await tryCatch( - query(currentInv, "notify shipped pallets") - ); + const { data: currentStuff, error: eCurrentInv } = await tryCatch( + query(currentInv, "notify shipped pallets"), + ); - // console.log(shipped?.data[2]); - // console.log(currentStuff?.data[2]); + // console.log(shipped?.data[2]); + // console.log(currentStuff?.data[2]); - /** - * We want to check if the each shippened pallet is out of fifo - */ - const check = shipped?.data.map((n: any) => { - /** - * Returns all data so we know if we are in or out. - */ - //check if there are pallets older than the current one we are mapped on. - const fifoCheck = currentStuff?.data.filter( - (i: any) => isBefore(i.prodDate, n.prodDate) && i.av === n.av - ); - //console.log(fifoCheck.length); - if (fifoCheck.length > 0) { - // console.log("Out of fifo", { - // av: n.av, - // rn: n.runningNr, - // fRn: fifoCheck[0].runningNr, - // dates: [fifoCheck[0].prodDate, n.prodDate], - // }); - } + /** + * We want to check if the each shippened pallet is out of fifo + */ + const check: any = shipped?.data.map((n: any) => { + /** + * Returns all data so we know if we are in or out. + */ + //check if there are pallets older than the current one we are mapped on. + const fifoCheck = currentStuff?.data.filter( + (i: any) => isBefore(i.prodDate, n.prodDate) && i.av === n.av, + ) as any; + //console.log(fifoCheck.length); + if (fifoCheck.length > 0) { + // console.log("Out of fifo", { + // av: n.av, + // rn: n.runningNr, + // fRn: fifoCheck[0].runningNr, + // dates: [fifoCheck[0].prodDate, n.prodDate], + // }); + } - return { - ...n, - // currentInv: fifoCheck[0], - fifoFollowed: fifoCheck.length === 0 ? true : false, - }; - }); + return { + ...n, + // currentInv: fifoCheck[0], + fifoFollowed: fifoCheck.length === 0 ? true : false, + }; + }); - /** - * lets see just the av that is our or in - */ + /** + * lets see just the av that is our or in + */ - const avCheck = (check: any) => { - /** - * This will only return the data based on out of fifo. - */ - // check how many times each av showed up - const avCounts = check.reduce((a: any, c: any) => { - if (c.fifoFollowed === false) { - const avValue = c.av; - a[avValue] = (a[avValue] || 0) + 1; - } - return a; - }, {}); + const avCheck = (check: any) => { + /** + * This will only return the data based on out of fifo. + */ + // check how many times each av showed up + const avCounts = check.reduce((a: any, c: any) => { + if (c.fifoFollowed === false) { + const avValue = c.av; + a[avValue] = (a[avValue] || 0) + 1; + } + return a; + }, {}); - // transform them back to an avCount Object - const result = Object.keys(avCounts).map((av) => ({ - av: parseInt(av, 10), - count: avCounts[av], - })); + // transform them back to an avCount Object + const result = Object.keys(avCounts).map((av) => ({ + av: parseInt(av, 10), + count: avCounts[av], + })); - return result; - }; + return result; + }; - const outOfFifo: any = avCheck(check); - const totalOut = outOfFifo.reduce((sum: any, c: any) => { - return sum + c.count; - }, 0); + const outOfFifo: any = avCheck(check); + const totalOut = outOfFifo.reduce((sum: any, c: any) => { + return sum + c.count; + }, 0); - /** - * add the data to the db - */ - for (let i = 0; i < check.length; i++) { - const { data: dbInsert, error: dbE } = await tryCatch( - db - .insert(fifoIndex) - .values({ - lot: check[i].lot, - av: check[i].av, - runningNr: check[i].runningNr, - prodDate: check[i].prodDate, - fifoFollowed: check[i].fifoFollowed, - add_Date: check[i].add_Date, - }) - .onConflictDoNothing() - ); - } + /** + * add the data to the db + */ + for (let i = 0; i < check!.length; i++) { + const { data: dbInsert, error: dbE } = await tryCatch( + db + .insert(fifoIndex) + .values({ + lot: check[i].lot, + av: check[i].av, + runningNr: check[i].runningNr, + prodDate: check[i].prodDate, + fifoFollowed: check[i].fifoFollowed, + add_Date: check[i].add_Date, + }) + .onConflictDoNothing(), + ); + } - return { - success: true, - message: "Fifo index data", - data: { - palletsOut: check, - totalShipped: shipped?.data.length, - inFifo: shipped?.data.length - totalOut, - outOfFifoData: outOfFifo, - }, - }; + return { + success: true, + message: "Fifo index data", + data: { + palletsOut: check, + totalShipped: shipped?.data.length, + inFifo: shipped!.data.length - totalOut, + outOfFifoData: outOfFifo, + }, + }; }