45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { LotType } from "@/types/lots";
|
|
import axios from "axios";
|
|
|
|
export const manualPrintLabels = async (lot: LotType, user: any) => {
|
|
//console.log(lot);
|
|
const labelUrl = `/api/ocp/manualprintandfollow`;
|
|
|
|
try {
|
|
const res = await axios.post(
|
|
labelUrl,
|
|
{ line: lot.MachineLocation, printerName: lot.PrinterName },
|
|
{ headers: { Authorization: `Basic ${user?.prod}` } }
|
|
);
|
|
|
|
if (res.data.success) {
|
|
return {
|
|
success: true,
|
|
message: `A new label was printed for ${lot.MachineDescription} to printer: ${lot.PrinterName}`,
|
|
};
|
|
} else {
|
|
return {
|
|
success: false,
|
|
message: `Line ${lot.MachineDescription} encountered an error printing labels: ${res.data.message}`,
|
|
};
|
|
}
|
|
} catch (error: any) {
|
|
if (error.response.status === 500) {
|
|
//toast.error(`Internal Server error please try again.`);
|
|
return {
|
|
success: false,
|
|
message: `Internal Server error please try again.`,
|
|
};
|
|
}
|
|
|
|
if (error.response.status === 401) {
|
|
//console.log(e.response);
|
|
//toast.error(`You are not authorized to do this.`);
|
|
return {
|
|
success: false,
|
|
message: `You are not authorized to do this.`,
|
|
};
|
|
}
|
|
}
|
|
};
|