Skip to content

Instantly share code, notes, and snippets.

@anshuman-singh-93
Last active January 12, 2020 06:22
Show Gist options
  • Save anshuman-singh-93/e6d4b9236ba18d9a9d029b24f562d877 to your computer and use it in GitHub Desktop.
Save anshuman-singh-93/e6d4b9236ba18d9a9d029b24f562d877 to your computer and use it in GitHub Desktop.
user.controller.js
const saveUser = async (req, res) => {
let { body } = req;
let result1, result2;
if (typeof body !== 'object') {
return res.status(400).json({ message: 'data must be an object' })
}
try {
result1 = await saveUserInDB(body);
}
catch (err) {
console.error(err);
return res.status(400).json({ message: err.message })
}
try {
result2 = await sendToOtherService(result1);
}
catch (err) {
console.error(err);
return res.status(400).json({ message: err.message })
}
res.json( {data: result1 } )
};
module.exports = { saveUser }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment