71 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import ownConn from "../dbConfig.js";
 | |
| 
 | |
| //insert production order todo to databased
 | |
| export const insertProductionOrderTodo = async (data, result) => {
 | |
|     try {
 | |
|         const results = await ownConn.query(`INSERT INTO productionordertodos(templateID, step, asset, task, comment, done) VALUES(?, ?, ?, ?, ?, ?)`, [data.templateID, data.step, data.asset, data.task, data.comment, data.done]);
 | |
|         result(null, results);
 | |
|     }
 | |
|     catch (err) {
 | |
|         // Manage Errors
 | |
|         console.log("SQL error : ", err);
 | |
|         result(err, null);
 | |
|     }
 | |
| };
 | |
| 
 | |
| //get single production order todo by id
 | |
| export const getProductionOrderTodosById = async (id, result) => {
 | |
|     try {
 | |
|         let sql = `SELECT * FROM productionordertodos WHERE templateID = ? ORDER BY primaryID ASC`;
 | |
|         const results = await ownConn.execute(sql, [id])
 | |
|         result(null, results);
 | |
|     }
 | |
|     catch (err) {
 | |
|         // Manage Errors
 | |
|         console.log("SQL error : ", err);
 | |
|         result(err, null);
 | |
|     }
 | |
| };
 | |
| 
 | |
| //get single production order todo by asset
 | |
| export const getProductionOrderTodosByAsset = async (id, result) => {
 | |
|     try {
 | |
|         let sql = `SELECT * FROM productionordertodos WHERE asset = ? ORDER BY primaryID ASC`;
 | |
|         const results = await ownConn.execute(sql, [id])
 | |
|         result(null, results);
 | |
|     }
 | |
|     catch (err) {
 | |
|         // Manage Errors
 | |
|         console.log("SQL error : ", err);
 | |
|         result(err, null);
 | |
|     }
 | |
| };
 | |
| 
 | |
| // Update production order todo to Database
 | |
| export const updateProductionOrderTodoById = async (data, result) => {
 | |
|     try {
 | |
|         const id = data.primaryID;
 | |
|         let sql = `UPDATE productionordertodos SET step = ?, asset = ?, task = ?, comment = ?, done = ? WHERE primaryID = ?`;
 | |
|         const results = await ownConn.query(sql, [data.step, data.asset, data.task, data.comment, data.done, id])
 | |
|         result(null, results);
 | |
|     }
 | |
|     catch (err) {
 | |
|         // Manage Errors
 | |
|         console.log("SQL error : ", err);
 | |
|         result(err, null);
 | |
|     }
 | |
| };
 | |
| 
 | |
| // Delete production order todos to Database
 | |
| export const deleteProductionOrderTodosChecklistID = async (id, result) => {
 | |
|     try {
 | |
|         let sql = `DELETE FROM productionordertodos WHERE templateID = ?`;
 | |
|         const results = await ownConn.query(sql, [id])
 | |
|         result(null, results);
 | |
|     }
 | |
|     catch (err) {
 | |
|         // Manage Errors
 | |
|         console.log("SQL error : ", err);
 | |
|         result(err, null);
 | |
|     }
 | |
| }; |