Created
January 30, 2021 11:53
-
-
Save jinalshah999/9095fab8dddbc8ec1cb3a1443d64a67f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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