added pot todos functionality
This commit is contained in:
@ -5,7 +5,9 @@ import https from 'https';
|
||||
let productionOrderTemplates = [];
|
||||
let selectedPOTsByClient = [];
|
||||
let selectedPOTsByPOT = [];
|
||||
let potTodosByTemplateId = [];
|
||||
let pot = [];
|
||||
let insertId = -1;
|
||||
let errorMsg = '';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
@ -51,9 +53,10 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
if (event.path.startsWith("/api/addPOT")) {
|
||||
const body = await readBody(event)
|
||||
// add the config item in the backend
|
||||
// add the pot in the backend
|
||||
try {
|
||||
let res = await axiosInstance.post(`https://${serversideConfig.url}:${serversideConfig.port}/masterProductionOrders`, body);
|
||||
insertId = res.data.insertId
|
||||
} catch (err) {
|
||||
if (axios.isAxiosError(err)) {
|
||||
const axiosError = err as AxiosError;
|
||||
@ -232,6 +235,158 @@ export default defineEventHandler(async (event) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event.path.startsWith("/api/getTodosProductionOrderTemplate")) {
|
||||
// get production order template todos object from backend
|
||||
let itemId = null;
|
||||
const path = event._path;
|
||||
const pathSegments = path.split('/');
|
||||
itemId = pathSegments[pathSegments.length - 1];
|
||||
|
||||
try {
|
||||
let res = await axiosInstance.get(`https://${serversideConfig.url}:${serversideConfig.port}/masterProductionOrderTodos/${itemId}`);
|
||||
potTodosByTemplateId = res.data;
|
||||
} catch (err) {
|
||||
if (axios.isAxiosError(err)) {
|
||||
const axiosError = err as AxiosError;
|
||||
|
||||
if (axiosError.response) {
|
||||
// Axios error
|
||||
console.error(axiosError.response.data.message);
|
||||
errorMsg = axiosError.response.data.message;
|
||||
} else if (axiosError.request) {
|
||||
// If error was caused by the request
|
||||
console.error(axiosError.request);
|
||||
} else {
|
||||
// Other errors
|
||||
console.error('Error', axiosError.message);
|
||||
}
|
||||
} else {
|
||||
// No AxiosError
|
||||
console.error('Error', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event.path.startsWith("/api/addTodoPOT")) {
|
||||
const body = await readBody(event)
|
||||
// add the pot todo in the backend
|
||||
try {
|
||||
let res = await axiosInstance.post(`https://${serversideConfig.url}:${serversideConfig.port}/masterProductionOrderTodos`, body);
|
||||
} catch (err) {
|
||||
if (axios.isAxiosError(err)) {
|
||||
const axiosError = err as AxiosError;
|
||||
|
||||
if (axiosError.response) {
|
||||
// Axios error
|
||||
console.error(axiosError.response.data.message);
|
||||
errorMsg = axiosError.response.data.message;
|
||||
} else if (axiosError.request) {
|
||||
console.log(err)
|
||||
// If error was caused by the request
|
||||
console.error(axiosError.request);
|
||||
} else {
|
||||
// Other errors
|
||||
console.error('Error', axiosError.message);
|
||||
}
|
||||
} else {
|
||||
// No AxiosError
|
||||
console.error('Error', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event.path.startsWith("/api/updatePOTTodo")) {
|
||||
const body = await readBody(event)
|
||||
// update the production order template todo in the backend
|
||||
try {
|
||||
let res = await axiosInstance.put(`https://${serversideConfig.url}:${serversideConfig.port}/masterProductionOrderTodos`, body);
|
||||
} catch (err) {
|
||||
if (axios.isAxiosError(err)) {
|
||||
const axiosError = err as AxiosError;
|
||||
|
||||
if (axiosError.response) {
|
||||
// Axios error
|
||||
console.error(axiosError.response.data.message);
|
||||
errorMsg = axiosError.response.data.message;
|
||||
} else if (axiosError.request) {
|
||||
console.log(err)
|
||||
// If error was caused by the request
|
||||
console.error(axiosError.request);
|
||||
} else {
|
||||
// Other errors
|
||||
console.error('Error', axiosError.message);
|
||||
}
|
||||
} else {
|
||||
// No AxiosError
|
||||
console.error('Error', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event.path.startsWith("/api/deleteTodosPOT")) {
|
||||
let potId = null;
|
||||
const path = event._path;
|
||||
const pathSegments = path.split('/');
|
||||
potId = pathSegments[pathSegments.length - 1];
|
||||
|
||||
// delete the pot in the backend
|
||||
try {
|
||||
let res = await axiosInstance.delete(`https://${serversideConfig.url}:${serversideConfig.port}/masterProductionOrderTodosByTemplateid/${potId}`);
|
||||
} catch (err) {
|
||||
if (axios.isAxiosError(err)) {
|
||||
const axiosError = err as AxiosError;
|
||||
|
||||
if (axiosError.response) {
|
||||
// Axios error
|
||||
console.error(axiosError.response.data.message);
|
||||
errorMsg = axiosError.response.data.message;
|
||||
} else if (axiosError.request) {
|
||||
console.log(err)
|
||||
// If error was caused by the request
|
||||
console.error(axiosError.request);
|
||||
} else {
|
||||
// Other errors
|
||||
console.error('Error', axiosError.message);
|
||||
}
|
||||
} else {
|
||||
// No AxiosError
|
||||
console.error('Error', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event.path.startsWith("/api/deletePOTTodo")) {
|
||||
let potId = null;
|
||||
const path = event._path;
|
||||
const pathSegments = path.split('/');
|
||||
potId = pathSegments[pathSegments.length - 1];
|
||||
|
||||
// delete the pot in the backend
|
||||
try {
|
||||
let res = await axiosInstance.delete(`https://${serversideConfig.url}:${serversideConfig.port}/masterProductionOrderTodos/${potId}`);
|
||||
} catch (err) {
|
||||
if (axios.isAxiosError(err)) {
|
||||
const axiosError = err as AxiosError;
|
||||
|
||||
if (axiosError.response) {
|
||||
// Axios error
|
||||
console.error(axiosError.response.data.message);
|
||||
errorMsg = axiosError.response.data.message;
|
||||
} else if (axiosError.request) {
|
||||
console.log(err)
|
||||
// If error was caused by the request
|
||||
console.error(axiosError.request);
|
||||
} else {
|
||||
// Other errors
|
||||
console.error('Error', axiosError.message);
|
||||
}
|
||||
} else {
|
||||
// No AxiosError
|
||||
console.error('Error', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export { productionOrderTemplates, selectedPOTsByClient, selectedPOTsByPOT, pot, errorMsg };
|
||||
export { productionOrderTemplates, selectedPOTsByClient, selectedPOTsByPOT, pot, potTodosByTemplateId, insertId, errorMsg };
|
||||
Reference in New Issue
Block a user