Last active
October 22, 2019 14:33
-
-
Save leleofg/bf1ed0c0cdaca339f0aa360264f17486 to your computer and use it in GitHub Desktop.
Demonstração repositorry crud async/await com node.js para o post no medium https://medium.com/@leoo.farias/crud-com-async-await-no-node-js-4e1032da5a33
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
exports.get = async() => { | |
return await User.find({}, 'name email'); | |
} | |
exports.getById = async(id) => { | |
return await User.findById(id, 'name email'); | |
} | |
exports.create = async(data) => { | |
const user = new User(data); | |
await user.save(); | |
} | |
exports.update = async(id, data) => { | |
await User | |
.findByIdAndUpdate(id, { | |
$set: { | |
name: data.name | |
} | |
}); | |
} | |
exports.delete = async(id) => { | |
await User.findByIdAndRemove(id); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment