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 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 = {
|
type Data = {
|
||||||
runningNr: string;
|
runningNr: string;
|
||||||
lotNum: number;
|
lotNum: number;
|
||||||
};
|
};
|
||||||
export const consumeMaterial = async (data: Data, prod: any) => {
|
export const consumeMaterial = async (data: Data, prod: any) => {
|
||||||
const {runningNr, lotNum} = data;
|
const { runningNr, lotNum } = data;
|
||||||
// replace the rn
|
// replace the rn
|
||||||
|
|
||||||
const rnReplace = labelData.replaceAll("[rn]", runningNr);
|
const rnReplace = labelData.replaceAll("[rn]", runningNr);
|
||||||
@@ -21,7 +22,12 @@ export const consumeMaterial = async (data: Data, prod: any) => {
|
|||||||
barcode = await query(rnReplace, "labelData");
|
barcode = await query(rnReplace, "labelData");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(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) {
|
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");
|
//throw Error("The provided runningNr is not in stock");
|
||||||
}
|
}
|
||||||
// create the url to post
|
// 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 = {
|
const consumeSomething = {
|
||||||
productionLot: lotNum,
|
productionLot: lotNum,
|
||||||
@@ -47,8 +55,16 @@ export const consumeMaterial = async (data: Data, prod: any) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
//console.log(results);
|
//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) {
|
} 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 axios from "axios";
|
||||||
import { laneInfo } from "../../sqlServer/querys/materialHelpers/laneInfo.js";
|
import { labelData } from "../../../sqlServer/querys/materialHelpers/labelInfo.js";
|
||||||
import { tryCatch } from "../../../globalUtils/tryCatch.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 = {
|
type Data = {
|
||||||
runningNr: string;
|
runningNr: string;
|
||||||
laneName: string;
|
laneName: string;
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||||
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
||||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
import {consumeMaterial} from "../controller/consumeMaterial.js";
|
|
||||||
import {verify} from "hono/jwt";
|
import { verify } from "hono/jwt";
|
||||||
|
import { consumeMaterial } from "../controller/materials/consumeMaterial.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
const responseSchema = z.object({
|
const responseSchema = z.object({
|
||||||
success: z.boolean().optional().openapi({example: true}),
|
success: z.boolean().optional().openapi({ example: true }),
|
||||||
message: z.string().optional().openapi({example: "user access"}),
|
message: z.string().optional().openapi({ example: "user access" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
app.openapi(
|
app.openapi(
|
||||||
@@ -18,24 +19,25 @@ app.openapi(
|
|||||||
method: "post",
|
method: "post",
|
||||||
path: "/consume",
|
path: "/consume",
|
||||||
middleware: authMiddleware,
|
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: {
|
responses: {
|
||||||
200: {
|
200: {
|
||||||
content: {"application/json": {schema: responseSchema}},
|
content: { "application/json": { schema: responseSchema } },
|
||||||
description: "stopped",
|
description: "stopped",
|
||||||
},
|
},
|
||||||
400: {
|
400: {
|
||||||
content: {"application/json": {schema: responseSchema}},
|
content: { "application/json": { schema: responseSchema } },
|
||||||
description: "Failed to stop",
|
description: "Failed to stop",
|
||||||
},
|
},
|
||||||
401: {
|
401: {
|
||||||
content: {"application/json": {schema: responseSchema}},
|
content: { "application/json": { schema: responseSchema } },
|
||||||
description: "Failed to stop",
|
description: "Failed to stop",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
apiHit(c, {endpoint: "api/sqlProd/close"});
|
apiHit(c, { endpoint: "api/sqlProd/close" });
|
||||||
const authHeader = c.req.header("Authorization");
|
const authHeader = c.req.header("Authorization");
|
||||||
const token = authHeader?.split("Bearer ")[1] || "";
|
const token = authHeader?.split("Bearer ")[1] || "";
|
||||||
|
|
||||||
@@ -45,14 +47,24 @@ app.openapi(
|
|||||||
//return apiReturn(c, true, access?.message, access?.data, 200);
|
//return apiReturn(c, true, access?.message, access?.data, 200);
|
||||||
const data = await c.req.json();
|
const data = await c.req.json();
|
||||||
const consume = await consumeMaterial(data, payload);
|
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) {
|
} catch (error) {
|
||||||
//console.log(error);
|
//console.log(error);
|
||||||
//return apiReturn(c, false, "Error in setting the user access", error, 400);
|
//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) {
|
} 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 { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
||||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
import { verify } from "hono/jwt";
|
import { verify } from "hono/jwt";
|
||||||
import { returnMaterial } from "../controller/returnMaterial.js";
|
import { returnMaterial } from "../controller/materials/returnMaterial.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user