fix(dm): correction to passing the username over for the importing of the file
This commit is contained in:
@@ -12,4 +12,6 @@ type IncomingForecastData = {
|
|||||||
CustomerArticleNumber: number;
|
CustomerArticleNumber: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const forecastData = async (data: IncomingForecastData) => {};
|
export const forecastData = async (data: IncomingForecastData) => {
|
||||||
|
console.log(data);
|
||||||
|
};
|
||||||
|
|||||||
9
app/src/internal/logistics/routes/demandMgt/dmRoutes.ts
Normal file
9
app/src/internal/logistics/routes/demandMgt/dmRoutes.ts
Normal 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;
|
||||||
@@ -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;
|
||||||
@@ -2,11 +2,13 @@ import axios from "axios";
|
|||||||
import { useRef, useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { useAuth } from "@/lib/authClient";
|
||||||
|
|
||||||
export default function ForecastImport(props: any) {
|
export default function ForecastImport(props: any) {
|
||||||
const fileInputRef: any = useRef(null);
|
const fileInputRef: any = useRef(null);
|
||||||
const [posting, setPosting] = useState(false);
|
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 [fileType, setFileType] = useState("");
|
||||||
const importOrders = async (e: any) => {
|
const importOrders = async (e: any) => {
|
||||||
const file = e.target.files[0];
|
const file = e.target.files[0];
|
||||||
@@ -20,6 +22,8 @@ export default function ForecastImport(props: any) {
|
|||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("postForecast", e.target.files[0]);
|
formData.append("postForecast", e.target.files[0]);
|
||||||
formData.append("fileType", props.fileType); // extra field
|
formData.append("fileType", props.fileType); // extra field
|
||||||
|
formData.append("username", `${session?.user.username}`);
|
||||||
|
|
||||||
// console.log(formData);
|
// console.log(formData);
|
||||||
toast.success("Import started.");
|
toast.success("Import started.");
|
||||||
try {
|
try {
|
||||||
@@ -29,7 +33,6 @@ export default function ForecastImport(props: any) {
|
|||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "multipart/form-data",
|
"Content-Type": "multipart/form-data",
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,11 +2,12 @@ import axios from "axios";
|
|||||||
import { useRef, useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { useAuth } from "@/lib/authClient";
|
||||||
|
|
||||||
export default function OrderImport(props: any) {
|
export default function OrderImport(props: any) {
|
||||||
const fileInputRef: any = useRef(null);
|
const fileInputRef: any = useRef(null);
|
||||||
const [posting, setPosting] = useState(false);
|
const [posting, setPosting] = useState(false);
|
||||||
const token = localStorage.getItem("auth_token");
|
const { session } = useAuth();
|
||||||
//const [fileType, setFileType] = useState("");
|
//const [fileType, setFileType] = useState("");
|
||||||
const importOrders = async (e: any) => {
|
const importOrders = async (e: any) => {
|
||||||
const file = e.target.files[0];
|
const file = e.target.files[0];
|
||||||
@@ -20,6 +21,7 @@ export default function OrderImport(props: any) {
|
|||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("postOrders", e.target.files[0]);
|
formData.append("postOrders", e.target.files[0]);
|
||||||
formData.append("fileType", props.fileType); // extra field
|
formData.append("fileType", props.fileType); // extra field
|
||||||
|
formData.append("username", `${session?.user.username}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
@@ -28,7 +30,6 @@ export default function OrderImport(props: any) {
|
|||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "multipart/form-data",
|
"Content-Type": "multipart/form-data",
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -36,15 +36,13 @@ app.openapi(
|
|||||||
async (c) => {
|
async (c) => {
|
||||||
apiHit(c, { endpoint: "/postbulkorders" });
|
apiHit(c, { endpoint: "/postbulkorders" });
|
||||||
const body = await c.req.parseBody();
|
const body = await c.req.parseBody();
|
||||||
//console.log(body); // File | string
|
//console.log(body.username); // File | string
|
||||||
|
|
||||||
// if (body["fileType"] === "standard") {
|
// if (body["fileType"] === "standard") {
|
||||||
// console.log(`doing standard orders in.`);
|
// console.log(`doing standard orders in.`);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const { data: orders, error } = await tryCatch(
|
const { data: orders, error } = await tryCatch(ordersIn(body, body));
|
||||||
ordersIn(body, c.get("user")),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|||||||
@@ -44,9 +44,7 @@ app.openapi(
|
|||||||
// console.log(`doing standard orders in.`);
|
// console.log(`doing standard orders in.`);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const { data: orders, error } = await tryCatch(
|
const { data: orders, error } = await tryCatch(forecastIn(body, body));
|
||||||
forecastIn(body, c.get("user")),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user