Skip to content

Instantly share code, notes, and snippets.

@cmilfont
Created November 17, 2016 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmilfont/d3ac5321be3b50d33cfa6fa26f67f356 to your computer and use it in GitHub Desktop.
Save cmilfont/d3ac5321be3b50d33cfa6fa26f67f356 to your computer and use it in GitHub Desktop.
Async / Await in Javascript
const models = require('./server/models');
const email = 'cmilfont@gmail.com';
async function fetchData(email) {
const [user, kind] = await Promise.all([
models.User.findOne({
where: { email }
}),
models.Kind.findOne({
where: { description: 'EAT' }
})
]);
const activity = await models.Activity.create({
UserId: user.id,
KindId: kind.id,
description: '#vaimonstro #birl #sanduba90cm',
secret: true
});
return activity;
}
fetchData(email).then(activity => console.log("Gravou", activity.dataValues))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment