90 lines
2.9 KiB
JavaScript
90 lines
2.9 KiB
JavaScript
import ownConn from "../dbConfig.js";
|
|
|
|
//get single master production order todo
|
|
export const getMasterProductionOrderTodoById = async (id, result) => {
|
|
try {
|
|
let sql = `SELECT * FROM masterordertodos WHERE templateID = ? ORDER BY rowID ASC`;
|
|
const results = await ownConn.execute(sql, [id])
|
|
result(null, results);
|
|
}
|
|
catch (err) {
|
|
// Manage Errors
|
|
console.log("SQL error : ", err);
|
|
result(err, null);
|
|
}
|
|
};
|
|
|
|
// Update master production order to Database
|
|
export const updateMasterProductionOrderTodoById = async (data, result) => {
|
|
try {
|
|
const id = data.primaryID;
|
|
let sql = `UPDATE masterordertodos SET templateID = ?, asset = ? , task = ?, comment = ? WHERE primaryID = ?`;
|
|
const results = await ownConn.query(sql, [data.templateID, data.asset, data.task, data.comment, id])
|
|
result(null, results);
|
|
}
|
|
catch (err) {
|
|
// Manage Errors
|
|
console.log("SQL error : ", err);
|
|
result(err, null);
|
|
}
|
|
};
|
|
|
|
|
|
// Delete master production order todo to Database
|
|
export const deleteMasterProductionOrderTodoById = async (id, result) => {
|
|
try {
|
|
let sql = `DELETE FROM masterordertodos WHERE primaryID = ?`;
|
|
const results = await ownConn.query(sql, [id])
|
|
result(null, results);
|
|
}
|
|
catch (err) {
|
|
// Manage Errors
|
|
console.log("SQL error : ", err);
|
|
result(err, null);
|
|
}
|
|
};
|
|
|
|
// Delete master production order todo by templateID to Database
|
|
export const deleteMasterProductionOrderTodoByTemplateId = async (id, result) => {
|
|
try {
|
|
let sql = `DELETE FROM masterordertodos WHERE templateID = ?`;
|
|
const results = await ownConn.query(sql, [id])
|
|
result(null, results);
|
|
}
|
|
catch (err) {
|
|
// Manage Errors
|
|
console.log("SQL error : ", err);
|
|
result(err, null);
|
|
}
|
|
};
|
|
|
|
// Update all master production order todos to Database
|
|
export const updateMasterProductionOrderTodos = async (data, result) => {
|
|
try {
|
|
let sql = `UPDATE masterordertodos SET rowID = ? WHERE primaryID = ?`;
|
|
data.data.forEach(async i => {
|
|
let id = i.primaryID;
|
|
let rowId = i.rowID;
|
|
const results = await ownConn.query(sql, [rowId, id])
|
|
result(null, results);
|
|
});
|
|
}
|
|
catch (err) {
|
|
// Manage Errors
|
|
console.log("SQL error : ", err);
|
|
result(err, null);
|
|
}
|
|
};
|
|
|
|
//insert master production order todo to databased
|
|
export const insertMasterProductionOrderTodo = async (data, result) => {
|
|
try {
|
|
const results = await ownConn.query(`INSERT INTO masterordertodos(templateID, rowID, asset, task, comment) VALUES(?, ?, ?, ?, ?)`, [data.templateID, data.rowID, data.asset, data.task, data.comment])
|
|
result(null, results);
|
|
}
|
|
catch (err) {
|
|
// Manage Errors
|
|
console.log("SQL error : ", err);
|
|
result(err, null);
|
|
}
|
|
}; |