fix(logging): updated entire server side to the new logging system
This commit is contained in:
54
server/services/logistics/controller/consumeMaterial.ts
Normal file
54
server/services/logistics/controller/consumeMaterial.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
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";
|
||||
|
||||
type Data = {
|
||||
runningNr: string;
|
||||
lotNum: number;
|
||||
};
|
||||
export const consumeMaterial = async (data: Data, prod: any) => {
|
||||
const {runningNr, lotNum} = data;
|
||||
// replace the rn
|
||||
|
||||
const rnReplace = labelData.replaceAll("[rn]", runningNr);
|
||||
|
||||
let barcode;
|
||||
// get the barcode from the running number
|
||||
try {
|
||||
barcode = await query(rnReplace, "labelData");
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
createLog("error", prod.user.username, "logistics", `Error getting barcode: ${error}`);
|
||||
}
|
||||
|
||||
if (barcode.length === 0) {
|
||||
return {
|
||||
success: false,
|
||||
message: "The running number provided is not in stock please check if stock and try again.",
|
||||
};
|
||||
//throw Error("The provided runningNr is not in stock");
|
||||
}
|
||||
// create the url to post
|
||||
const url = await prodEndpointCreation("/public/v1.0/IssueMaterial/ConsumeNonPreparedManualMaterial");
|
||||
|
||||
const consumeSomething = {
|
||||
productionLot: lotNum,
|
||||
barcode: barcode[0]?.barcode,
|
||||
};
|
||||
|
||||
try {
|
||||
const results = await axios.post(url, consumeSomething, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Basic ${prod.user.prod}`,
|
||||
},
|
||||
});
|
||||
//console.log(results);
|
||||
return {success: true, message: "Material was consumed", status: results.status};
|
||||
} catch (error: any) {
|
||||
return {success: false, status: error.response?.status, message: error.response?.data.errors[0].message};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user