refactor(materials): moved for better sturcture
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import {ConsoleLogWriter} from "drizzle-orm";
|
||||
import {prodEndpointCreation} from "../../../globalUtils/createUrl.js";
|
||||
import {createLog} from "../../logger/logger.js";
|
||||
import {query} from "../../sqlServer/prodSqlServer.js";
|
||||
import {labelData} from "../../sqlServer/querys/materialHelpers/labelInfo.js";
|
||||
import axios from "axios";
|
||||
import { labelData } from "../../../sqlServer/querys/materialHelpers/labelInfo.js";
|
||||
|
||||
import { query } from "../../../sqlServer/prodSqlServer.js";
|
||||
import { createLog } from "../../../logger/logger.js";
|
||||
|
||||
import { prodEndpointCreation } from "../../../../globalUtils/createUrl.js";
|
||||
|
||||
type Data = {
|
||||
runningNr: string;
|
||||
@@ -21,7 +22,12 @@ export const consumeMaterial = async (data: Data, prod: any) => {
|
||||
barcode = await query(rnReplace, "labelData");
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
createLog("error", prod.user.username, "logistics", `Error getting barcode: ${error}`);
|
||||
createLog(
|
||||
"error",
|
||||
prod.user.username,
|
||||
"logistics",
|
||||
`Error getting barcode: ${error}`
|
||||
);
|
||||
}
|
||||
|
||||
if (barcode.length === 0) {
|
||||
@@ -32,7 +38,9 @@ export const consumeMaterial = async (data: Data, prod: any) => {
|
||||
//throw Error("The provided runningNr is not in stock");
|
||||
}
|
||||
// create the url to post
|
||||
const url = await prodEndpointCreation("/public/v1.0/IssueMaterial/ConsumeNonPreparedManualMaterial");
|
||||
const url = await prodEndpointCreation(
|
||||
"/public/v1.0/IssueMaterial/ConsumeNonPreparedManualMaterial"
|
||||
);
|
||||
|
||||
const consumeSomething = {
|
||||
productionLot: lotNum,
|
||||
@@ -47,8 +55,16 @@ export const consumeMaterial = async (data: Data, prod: any) => {
|
||||
},
|
||||
});
|
||||
//console.log(results);
|
||||
return {success: true, message: "Material was consumed", status: results.status};
|
||||
return {
|
||||
success: true,
|
||||
message: "Material was consumed",
|
||||
status: results.status,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {success: false, status: 200, message: error.response?.data.errors[0].message};
|
||||
return {
|
||||
success: false,
|
||||
status: 200,
|
||||
message: error.response?.data.errors[0].message,
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -1,12 +1,10 @@
|
||||
import { ConsoleLogWriter } from "drizzle-orm";
|
||||
import { prodEndpointCreation } from "../../../globalUtils/createUrl.js";
|
||||
import { createLog } from "../../logger/logger.js";
|
||||
import { query } from "../../sqlServer/prodSqlServer.js";
|
||||
import { labelData } from "../../sqlServer/querys/materialHelpers/labelInfo.js";
|
||||
import axios from "axios";
|
||||
import { laneInfo } from "../../sqlServer/querys/materialHelpers/laneInfo.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
|
||||
import { labelData } from "../../../sqlServer/querys/materialHelpers/labelInfo.js";
|
||||
import { laneInfo } from "../../../sqlServer/querys/materialHelpers/laneInfo.js";
|
||||
import { query } from "../../../sqlServer/prodSqlServer.js";
|
||||
import { createLog } from "../../../logger/logger.js";
|
||||
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||
import { prodEndpointCreation } from "../../../../globalUtils/createUrl.js";
|
||||
type Data = {
|
||||
runningNr: string;
|
||||
laneName: string;
|
||||
@@ -1,8 +1,9 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
import {consumeMaterial} from "../controller/consumeMaterial.js";
|
||||
|
||||
import { verify } from "hono/jwt";
|
||||
import { consumeMaterial } from "../controller/materials/consumeMaterial.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
@@ -18,7 +19,8 @@ app.openapi(
|
||||
method: "post",
|
||||
path: "/consume",
|
||||
middleware: authMiddleware,
|
||||
description: "Provided a running number and lot number you can consume material.",
|
||||
description:
|
||||
"Provided a running number and lot number you can consume material.",
|
||||
responses: {
|
||||
200: {
|
||||
content: { "application/json": { schema: responseSchema } },
|
||||
@@ -45,11 +47,21 @@ app.openapi(
|
||||
//return apiReturn(c, true, access?.message, access?.data, 200);
|
||||
const data = await c.req.json();
|
||||
const consume = await consumeMaterial(data, payload);
|
||||
return c.json({success: consume?.success, message: consume?.message}, 200);
|
||||
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);
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Missing data please try again",
|
||||
error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
return c.json({ success: false, message: "Unauthorized" }, 401);
|
||||
|
||||
@@ -2,7 +2,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
import { verify } from "hono/jwt";
|
||||
import { returnMaterial } from "../controller/returnMaterial.js";
|
||||
import { returnMaterial } from "../controller/materials/returnMaterial.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user