added backend implementation
This commit is contained in:
85
backend/models/checklistSolutionsModel.js
Normal file
85
backend/models/checklistSolutionsModel.js
Normal file
@ -0,0 +1,85 @@
|
||||
import ownConn from "../dbConfig.js";
|
||||
|
||||
//insert checklist solution todo to databased
|
||||
export const insertChecklistSolutionTodo = async (data, result) => {
|
||||
try {
|
||||
const results = await ownConn.query(`INSERT INTO checklistSolutions(solutionID, step, asset, task, comments) VALUES(?, ?, ?, ?, ?)`, [data.solutionID, data.step, data.asset, data.task, data.comments]);
|
||||
result(null, results);
|
||||
}
|
||||
catch (err) {
|
||||
// Manage Errors
|
||||
console.log("SQL error : ", err);
|
||||
result(err, null);
|
||||
}
|
||||
};
|
||||
|
||||
//get single checklist solution todo by id
|
||||
export const getChecklistSolutionTodosById = async (id, result) => {
|
||||
try {
|
||||
let sql = `SELECT * FROM checklistSolutions WHERE solutionID = ? 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 checklist solution todo by asset
|
||||
export const getChecklistSolutionTodosByAsset = async (id, result) => {
|
||||
try {
|
||||
let sql = `SELECT * FROM checklistSolutions 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 checklist solution todo to Database
|
||||
export const updateChecklistSolutionTodoById = async (data, result) => {
|
||||
try {
|
||||
const id = data.primaryID;
|
||||
let sql = `UPDATE checklistSolutions SET step = ?, asset = ?, task = ?, comments = ? WHERE primaryID = ?`;
|
||||
const results = await ownConn.query(sql, [data.step, data.asset, data.task, data.comments, id])
|
||||
result(null, results);
|
||||
}
|
||||
catch (err) {
|
||||
// Manage Errors
|
||||
console.log("SQL error : ", err);
|
||||
result(err, null);
|
||||
}
|
||||
};
|
||||
|
||||
// Delete all checklist solution todos by template ID to Database
|
||||
export const deleteAllChecklistSolutionTodosSolutionID = async (id, result) => {
|
||||
try {
|
||||
let sql = `DELETE FROM checklistSolutions WHERE solutionID = ?`;
|
||||
const results = await ownConn.query(sql, [id])
|
||||
result(null, results);
|
||||
}
|
||||
catch (err) {
|
||||
// Manage Errors
|
||||
console.log("SQL error : ", err);
|
||||
result(err, null);
|
||||
}
|
||||
};
|
||||
|
||||
// Delete single checklist solution todo by primary ID to Database
|
||||
export const deleteChecklistSolutionTodo = async (id, result) => {
|
||||
try {
|
||||
let sql = `DELETE FROM checklistSolutions WHERE primaryID = ?`;
|
||||
const results = await ownConn.query(sql, [id])
|
||||
result(null, results);
|
||||
}
|
||||
catch (err) {
|
||||
// Manage Errors
|
||||
console.log("SQL error : ", err);
|
||||
result(err, null);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user