Created
April 26, 2018 01:35
-
-
Save larizzatg/cbc8e6cdbad10db09a79fbeb7f428f80 to your computer and use it in GitHub Desktop.
Async Await and Promises
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
// 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