Last active
October 3, 2017 13:17
-
-
Save kaueDM/b1cbe9562ed84cb594a6b67864e98a93 to your computer and use it in GitHub Desktop.
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
const getList = (employeeUID) => { | |
let result = {}; | |
const ref = database.ref('employee_works').child(employeeUID).orderByValue().equalTo(true); | |
return new Promise((resolve, reject) => { | |
ref.once('value') | |
.then(workUIDs => { | |
if (workUIDs.val()) { | |
Object.keys(workUIDs.val()).map(item => { | |
database.ref('works').child(item).once('value') | |
.then(workDetails => result[item] = workDetails.val()) | |
.catch(e => reject('Erro ao capturar dados: ', e)) | |
}) | |
return resolve(console.log('Resultado: ', result)) | |
} | |
}) | |
.catch(e => reject('Nenhuma obra relacionada a este funcionário', e)) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Retornando o objeto estruturado:
return Promise.all(PromiseStack).then(PromiseValues => result)