fix(dm): correction to passing the username over for the importing of the file

This commit is contained in:
2025-10-31 09:41:08 -05:00
parent 1283a63b5f
commit a7a9aa2874
7 changed files with 50 additions and 12 deletions

View File

@@ -12,4 +12,6 @@ type IncomingForecastData = {
CustomerArticleNumber: number;
};
export const forecastData = async (data: IncomingForecastData) => {};
export const forecastData = async (data: IncomingForecastData) => {
console.log(data);
};

View File

@@ -0,0 +1,9 @@
import { Router } from "express";
import { requireAuth } from "../../../../pkg/middleware/authMiddleware.js";
import forecastData from "./forecastEDIData.js";
const router = Router();
router.use("/", requireAuth(), forecastData);
export default router;

View File

@@ -0,0 +1,27 @@
import type { Request, Response } from "express";
import { Router } from "express";
import z from "zod";
import { preprintLabels } from "../../controller/labeling/preprint.js";
export const Preprint = z.object({
scannerId: z.number(),
lotNr: z.number(),
machineId: z.number(), // 457=22, 458=23
printerId: z.number(), // 457=22, 458=23
layoutId: z.number(),
numberOfCopies: z.number(),
qtyToPrint: z.number().default(1),
});
const router = Router();
router.post("/preprint", async (req: Request, res: Response) => {
const parsed = Preprint.safeParse(req.body);
const print = await preprintLabels(req.body, req.user?.username || "");
res
.status(200)
.json({ success: print.success, message: print.message, data: print.data });
});
export default router;

View File

@@ -2,11 +2,13 @@ import axios from "axios";
import { useRef, useState } from "react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { useAuth } from "@/lib/authClient";
export default function ForecastImport(props: any) {
const fileInputRef: any = useRef(null);
const [posting, setPosting] = useState(false);
const token = localStorage.getItem("auth_token");
//const token = localStorage.getItem("auth_token");
const { session } = useAuth();
//const [fileType, setFileType] = useState("");
const importOrders = async (e: any) => {
const file = e.target.files[0];
@@ -20,6 +22,8 @@ export default function ForecastImport(props: any) {
const formData = new FormData();
formData.append("postForecast", e.target.files[0]);
formData.append("fileType", props.fileType); // extra field
formData.append("username", `${session?.user.username}`);
// console.log(formData);
toast.success("Import started.");
try {
@@ -29,7 +33,6 @@ export default function ForecastImport(props: any) {
{
headers: {
"Content-Type": "multipart/form-data",
Authorization: `Bearer ${token}`,
},
},
);

View File

@@ -2,11 +2,12 @@ import axios from "axios";
import { useRef, useState } from "react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { useAuth } from "@/lib/authClient";
export default function OrderImport(props: any) {
const fileInputRef: any = useRef(null);
const [posting, setPosting] = useState(false);
const token = localStorage.getItem("auth_token");
const { session } = useAuth();
//const [fileType, setFileType] = useState("");
const importOrders = async (e: any) => {
const file = e.target.files[0];
@@ -20,6 +21,7 @@ export default function OrderImport(props: any) {
const formData = new FormData();
formData.append("postOrders", e.target.files[0]);
formData.append("fileType", props.fileType); // extra field
formData.append("username", `${session?.user.username}`);
try {
const response = await axios.post(
@@ -28,7 +30,6 @@ export default function OrderImport(props: any) {
{
headers: {
"Content-Type": "multipart/form-data",
Authorization: `Bearer ${token}`,
},
},
);

View File

@@ -36,15 +36,13 @@ app.openapi(
async (c) => {
apiHit(c, { endpoint: "/postbulkorders" });
const body = await c.req.parseBody();
//console.log(body); // File | string
//console.log(body.username); // File | string
// if (body["fileType"] === "standard") {
// console.log(`doing standard orders in.`);
// }
const { data: orders, error } = await tryCatch(
ordersIn(body, c.get("user")),
);
const { data: orders, error } = await tryCatch(ordersIn(body, body));
if (error) {
console.log(error);

View File

@@ -44,9 +44,7 @@ app.openapi(
// console.log(`doing standard orders in.`);
// }
const { data: orders, error } = await tryCatch(
forecastIn(body, c.get("user")),
);
const { data: orders, error } = await tryCatch(forecastIn(body, body));
if (error) {
console.log(error);