refactor(materials): moved for better sturcture
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
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;
|
||||
lotNum: number;
|
||||
};
|
||||
export const consumeMaterial = async (data: Data, prod: any) => {
|
||||
const {runningNr, lotNum} = data;
|
||||
const { runningNr, lotNum } = data;
|
||||
// replace the rn
|
||||
|
||||
const rnReplace = labelData.replaceAll("[rn]", runningNr);
|
||||
@@ -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,14 +1,15 @@
|
||||
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 { 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 { consumeMaterial } from "../controller/materials/consumeMaterial.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
const responseSchema = z.object({
|
||||
success: z.boolean().optional().openapi({example: true}),
|
||||
message: z.string().optional().openapi({example: "user access"}),
|
||||
success: z.boolean().optional().openapi({ example: true }),
|
||||
message: z.string().optional().openapi({ example: "user access" }),
|
||||
});
|
||||
|
||||
app.openapi(
|
||||
@@ -18,24 +19,25 @@ 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}},
|
||||
content: { "application/json": { schema: responseSchema } },
|
||||
description: "stopped",
|
||||
},
|
||||
400: {
|
||||
content: {"application/json": {schema: responseSchema}},
|
||||
content: { "application/json": { schema: responseSchema } },
|
||||
description: "Failed to stop",
|
||||
},
|
||||
401: {
|
||||
content: {"application/json": {schema: responseSchema}},
|
||||
content: { "application/json": { schema: responseSchema } },
|
||||
description: "Failed to stop",
|
||||
},
|
||||
},
|
||||
}),
|
||||
async (c) => {
|
||||
apiHit(c, {endpoint: "api/sqlProd/close"});
|
||||
apiHit(c, { endpoint: "api/sqlProd/close" });
|
||||
const authHeader = c.req.header("Authorization");
|
||||
const token = authHeader?.split("Bearer ")[1] || "";
|
||||
|
||||
@@ -45,14 +47,24 @@ 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);
|
||||
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