Skip to content

Instantly share code, notes, and snippets.

@jinalshah999
Created January 30, 2021 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jinalshah999/9095fab8dddbc8ec1cb3a1443d64a67f to your computer and use it in GitHub Desktop.
Save jinalshah999/9095fab8dddbc8ec1cb3a1443d64a67f to your computer and use it in GitHub Desktop.
const productMssql = require('./product.mssql');
class product {
async getAllProducts(req, res) {
try {
const output = await productMssql.getAllProducts();
res.sendResponse(output);
}
catch (error) {
console.log(error);
res.sendError(global.HELPER.getException({ error, message: 'Error in getting products list.' }));
}
}
async addProduct(req, res) {
try {
const output = await productMssql.addProduct(req.body);
res.send(output);
}
catch (error) {
console.log(error);
res.sendError(global.HELPER.getException({ error, message: 'Error in adding product.' }));
}
}
async updateProduct(req, res) {
try {
const output = await productMssql.updateProduct(req.body);
res.send(output);
}
catch (error) {
console.log(error);
res.sendError(global.HELPER.getException({ error, message: 'Error in updating product.' }));
}
}
async deleteProduct(req, res) {
const id = req.params.id;
try {
if (!id) {
throw new global.EXCEPTION('ValidationError', 'please provide id');
}
const output = await productMssql.deleteProduct(id);
res.send(output);
}
catch (error) {
console.log(error);
res.sendError(global.HELPER.getException({ error, message: 'Error in deleting product.' }));
}
}
}
module.exports = new product();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment