From 360549aaf4c29a0ca8831b105dc086be98202580 Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Thu, 18 Sep 2025 10:59:55 -0500 Subject: [PATCH] fix(consume material): changes made to remove the rest of the auth needs --- .../consumption/ConsumeMaterial.tsx | 68 ++++++++++++------- .../controller/materials/consumeMaterial.ts | 9 +-- .../logistics/route/consumeMaterial.ts | 42 ++++++------ 3 files changed, 66 insertions(+), 53 deletions(-) diff --git a/frontend/src/components/logistics/materialHelper/consumption/ConsumeMaterial.tsx b/frontend/src/components/logistics/materialHelper/consumption/ConsumeMaterial.tsx index b788e5e..3c7a5da 100644 --- a/frontend/src/components/logistics/materialHelper/consumption/ConsumeMaterial.tsx +++ b/frontend/src/components/logistics/materialHelper/consumption/ConsumeMaterial.tsx @@ -1,26 +1,30 @@ -import {LstCard} from "@/components/extendedUI/LstCard"; -import {Button} from "@/components/ui/button"; -import {CardHeader} from "@/components/ui/card"; -import {Input} from "@/components/ui/input"; -import {Label} from "@/components/ui/label"; -import {useSessionStore} from "@/lib/store/sessionStore"; -import axios from "axios"; -import {useState} from "react"; +import { LstCard } from "@/components/extendedUI/LstCard"; +import { Button } from "@/components/ui/button"; +import { CardHeader } from "@/components/ui/card"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; -import {useForm} from "react-hook-form"; -import {toast} from "sonner"; +import axios from "axios"; +import { useState } from "react"; + +import { useForm } from "react-hook-form"; +import { toast } from "sonner"; export default function ConsumeMaterial() { - const {register: register1, handleSubmit: handleSubmit1, reset} = useForm(); + const { + register: register1, + handleSubmit: handleSubmit1, + reset, + } = useForm(); const [submitting, setSubmitting] = useState(false); - const {token} = useSessionStore(); const handleConsume = async (data: any) => { setSubmitting(true); try { - const result = await axios.post(`/api/logistics/consume`, data, { - headers: {Authorization: `Bearer ${token}`}, - }); + // const result = await axios.post(`/api/logistics/consume`, data, { + // headers: {Authorization: `Bearer ${token}`}, + // }); + const result = await axios.post(`/api/logistics/consume`, data); if (result.data.success) { toast.success(result.data.message); setSubmitting(false); @@ -33,12 +37,14 @@ export default function ConsumeMaterial() { toast.error(result.data.message); } } catch (error: any) { - //console.log(error); + console.log(error); setSubmitting(false); if (error.status === 401) { toast.error("Unauthorized to do this task."); } else { - toast.error("Unexpected error if this continues please constact an admin."); + toast.error( + "Unexpected error if this continues please constact an admin." + ); } } }; @@ -53,7 +59,9 @@ export default function ConsumeMaterial() {
- +
- +
-
@@ -81,12 +96,19 @@ export default function ConsumeMaterial() {
    -
  1. 1. Enter the running number of the material you would like to consume
  2. -
  3. 2. Enter the lot number you will be consuming to
  4. +
  5. + 1. Enter the running number of the + material you would like to consume +
  6. +
  7. + 2. Enter the lot number you will be + consuming to +
  8. 3. Press consume material

- *This process is only for barcoded material, if it is set to auto consume you will + *This process is only for barcoded material, + if it is set to auto consume you will encounter and error.

diff --git a/server/services/logistics/controller/materials/consumeMaterial.ts b/server/services/logistics/controller/materials/consumeMaterial.ts index e5fe5a3..417fe22 100644 --- a/server/services/logistics/controller/materials/consumeMaterial.ts +++ b/server/services/logistics/controller/materials/consumeMaterial.ts @@ -13,7 +13,7 @@ type Data = { runningNr: string; lotNum: number; }; -export const consumeMaterial = async (data: Data, prod: any) => { +export const consumeMaterial = async (data: Data) => { const { runningNr, lotNum } = data; // replace the rn @@ -28,12 +28,7 @@ export const consumeMaterial = async (data: Data, prod: any) => { barcode = r?.data; } catch (error) { console.log(error); - createLog( - "error", - prod.user.username, - "logistics", - `Error getting barcode: ${error}` - ); + createLog("error", "", "logistics", `Error getting barcode: ${error}`); } if (barcode.length === 0) { diff --git a/server/services/logistics/route/consumeMaterial.ts b/server/services/logistics/route/consumeMaterial.ts index 1184b9b..3304436 100644 --- a/server/services/logistics/route/consumeMaterial.ts +++ b/server/services/logistics/route/consumeMaterial.ts @@ -51,33 +51,29 @@ app.openapi( ); } apiHit(c, { endpoint: "/consume", lastBody: data }); - const authHeader = c.req.header("Authorization"); - const token = authHeader?.split("Bearer ")[1] || ""; + //const authHeader = c.req.header("Authorization"); + //const token = authHeader?.split("Bearer ")[1] || ""; + //const payload = await verify(token, process.env.JWT_SECRET!); try { - const payload = await verify(token, process.env.JWT_SECRET!); - try { - //return apiReturn(c, true, access?.message, access?.data, 200); + //return apiReturn(c, true, access?.message, access?.data, 200); - const consume = await consumeMaterial(data, payload); - return c.json( - { success: consume?.success, message: consume?.message }, - 200 - ); - } catch (error) { - //console.log(error); - //return apiReturn(c, false, "Error in setting the user access", error, 400); - return c.json( - { - success: false, - message: "Missing data please try again", - error, - }, - 400 - ); - } + const consume = await consumeMaterial(data); + return c.json( + { success: consume?.success, message: consume?.message }, + 200 + ); } catch (error) { - return c.json({ success: false, message: "Unauthorized" }, 401); + //console.log(error); + //return apiReturn(c, false, "Error in setting the user access", error, 400); + return c.json( + { + success: false, + message: "Missing data please try again", + error, + }, + 400 + ); } } );