Last active
January 12, 2020 06:22
-
-
Save anshuman-singh-93/e6d4b9236ba18d9a9d029b24f562d877 to your computer and use it in GitHub Desktop.
user.controller.js
This file contains hidden or 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 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