Skip to content

Instantly share code, notes, and snippets.

@leleofg
Last active October 22, 2019 14:33
Show Gist options
  • Save leleofg/bf1ed0c0cdaca339f0aa360264f17486 to your computer and use it in GitHub Desktop.
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
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