added backend implementation
This commit is contained in:
128
backend/controller/solutions.js
Normal file
128
backend/controller/solutions.js
Normal file
@ -0,0 +1,128 @@
|
||||
//import functions from solutions model
|
||||
import {
|
||||
getSolutions,
|
||||
getSolutionById,
|
||||
getSolutionByName,
|
||||
updateSolutionById,
|
||||
deleteSolutionById,
|
||||
insertSolution,
|
||||
getSelectedSolutionsByCustomer,
|
||||
getSelectedSolutionsBySolutionName,
|
||||
getSelectedSolutionsByAssetName,
|
||||
getSelectedSolutionsByType,
|
||||
} from "../models/solutionsModel.js";
|
||||
|
||||
//get all solutions
|
||||
export const showSolutions = (req, res) => {
|
||||
getSolutions((err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//get all selected solutions by customer
|
||||
export const showSelectedSolutionByCustomer = (req, res) => {
|
||||
getSelectedSolutionsByCustomer(req.params.id, (err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//get all selected solutions by solution name
|
||||
export const showSelectedSolutionBySolutionName = (req, res) => {
|
||||
getSelectedSolutionsBySolutionName(req.params.id, (err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//get all selected solutions by asset name
|
||||
export const showSelectedSolutionByAssetName = (req, res) => {
|
||||
getSelectedSolutionsByAssetName(req.params.id, (err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//get all selected solutions by type
|
||||
export const showSelectedSolutionByType = (req, res) => {
|
||||
getSelectedSolutionsByType(req.params.id, (err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
//create new solution
|
||||
export const createSolution = (req, res) => {
|
||||
const data = req.body;
|
||||
insertSolution(data, (err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//get single customer by primaryID
|
||||
export const showSolutionById = (req, res) => {
|
||||
getSolutionById(req.params.id, (err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//get single customer by name
|
||||
export const showSolutionByName = (req, res) => {
|
||||
getSolutionByName(req.params.id, (err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// Update solution
|
||||
export const updateSolution = (req, res) => {
|
||||
const data = req.body;
|
||||
updateSolutionById(data, (err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Delete solution
|
||||
export const deleteSolution = (req, res) => {
|
||||
const id = req.params.id;
|
||||
deleteSolutionById(id, (err, results) => {
|
||||
if (err) {
|
||||
res.send(err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user