Skip to content

Instantly share code, notes, and snippets.

@larizzatg
Created April 26, 2018 01:35
Show Gist options
  • Save larizzatg/cbc8e6cdbad10db09a79fbeb7f428f80 to your computer and use it in GitHub Desktop.
Save larizzatg/cbc8e6cdbad10db09a79fbeb7f428f80 to your computer and use it in GitHub Desktop.
Async Await and Promises
// First Function
const canRegister = async (idCard, yunenCard) => {
const url = `${names.API_ENDPOINT_AFFILIATE}BuscarPendienteRegistro`;
const request = {
usuario: null,
requerimiento: `${idCard}-${yunenCard}`,
};
return new Promise((resolve, reject) => {
axios.post(url, request)
.then((response) => {
resolve(response.data);
})
.catch((error) => {
reject(error);
});
});
};
// Second Function (calling first)
async confirmAffiliate({ commit }, affiliate) {
return await apiRegister.canRegister(affiliate.idCard, affiliate.yunenCard);
}
// Third Function: Calling the second function
async onSubmit() {
try {
const value = await this.$store.dispatch('auth/confirmAffiliate', {
idCard: this.idCard,
yunenCard: this.yunenCard,
});
console.log('returning v');
console.log(value);
} catch (error) {
console.log('errr');
console.log(error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment