Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

277
Visualizações
function on call returns empty object. How to get it to wait for map value

I know this has to do with async but I can't figure it out.

This returns an empty object. The functions.logger.log(groupName) is logging a value so I know there's data there.

exports.getMinistryMembers = functions.https.onCall((req) => {
  // calls
  const getMinistry = admin.database().ref(`organization/${req.orgId}`);
  const getMinistryForUser = admin.database().ref(`organization/${req.orgId}/attendanceOptionsMinistries`)
  const ministryMembers = admin.database().ref(`organization/${req.orgId}/inMinistries`);
  const ministryGroup = admin.database().ref(`organization/${req.orgId}/ministryGroups`);


  return getMinistryForUser
    .child(req.uid)
    .once('value')
    .then(snapshot => {
      if (snapshot.val()) {
        const ministryUids = snapshot.val();
        return Object.keys(ministryUids).map((ministryItem, i) => {

          // get name of group
          return ministryGroup
            .child(ministryItem)
            .once('value')
            .then(groupSnap => {
              const groupName = groupSnap.val();
              functions.logger.log(groupName);
              return groupName;
            })
        });
      }

    })
});

I would expect the value to return since it's in a then call but I'm not sure what I'm missing. As a side note this works but not the second then.

exports.getMinistryMembers = functions.https.onCall((req) => { // calls const getMinistry = admin.database().ref(organization/${req.orgId}); const getMinistryForUser = admin.database().ref(organization/${req.orgId}/attendanceOptionsMinistries) const ministryMembers = admin.database().ref(organization/${req.orgId}/inMinistries); const ministryGroup = admin.database().ref(organization/${req.orgId}/ministryGroups);

  return getMinistryForUser
    .child(req.uid)
    .once('value')
    .then(snapshot => {
      if (snapshot.val()) {
        const ministryUids = snapshot.val();
        return Object.keys(ministryUids).map((ministryItem, i) => {
          return ministryItem;

        });
      }

    })
});
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda