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

118
Visualizações
Nodejs Firestore: Returning nothing

I am using firebase to check a users punishment history, and when I call it: I want it to return the array of embeds to post rather than just that. I am awaiting the function so I'm kind of confused why this is happening

  • This is what happens in the console.log:

    enter image description here

    [AsyncFunction: CheckHistory]
    
  • CALL

    let hist = await CheckHistory(id);
    console.log(CheckHistory);
    
  • FUNCTION

        async function CheckHistory(user){
          CheckBan(user);
          let historyArray = [];
    
          const colRef = db.collection('punishments')
          colRef.where('user', '==', user).get().then(async querySnapshot => {
            length = querySnapshot.size;
            if (querySnapshot.empty){
              console.log(querySnapshot.size)
              return 0;
            } else {
              let docs = querySnapshot.docs;
              for (let documentSnapshot of docs) {
                const revoke = documentSnapshot.get('revoke')
    
                let active = documentSnapshot.get('active')
                if (active = true){
                  active = "Active"
                } else {
                  active = `Revoked for ${revoke}`
                }
                const mod = documentSnapshot.get('mod')
                const reason = documentSnapshot.get('reason');
                const time = documentSnapshot.get('time');
    
                let type = documentSnapshot.get('type');
                if (type == 1){
                  type = "Blacklist";
                } else if (type == 2){
                  type = "Dayban";
                } else if (type == 3){
                  type = "Warning";
                }
    
                const username = await API.getUsernameFromId(user);
                const modname = await API.getUsernameFromId(mod);
    
                const historyEmbed = new MessageEmbed()
                  .setColor('#0099ff')
                  .setTitle(`'Punishment of ${username}:${user}`)
                  .setDescription(`This is a punishment log.`)
                  .addFields(
                    { name: 'Status', value: `${active}`},
                    { name: 'Moderator', value: `${modname}:${mod}` },
                    { name: 'Reason', value: `${reason}` },
                    { name: 'Type', value: `${type}` },
                    { name: 'Time', value: `<t:${time}>`}
                  )
    
                historyArray.push(historyEmbed);
    
                if (historyArray.length >= length) {
                  return historyArray;
                }
              }
            }
          });
        }
    
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

As stated by @Sergey Sosunov:

You forgot to actually return anything from your method, you should

return colRef.where('user', '==', user).get().then....

Or to change .then() callback approach to actually await one. Like:

const querySnapshot = await colRef.where('user', '==', user).get(); 

and so on.


Also, the way you call the function only returns function definition; you should pass with parameters or print the variable value equal to your function. For example:

//Sample function
function test(id) { return id; }

//Returns function definition
console.log(test) 

//Returns function value
console.log(test(1))

//Print variable value
let x = test(1)
console.log(x)

about 4 years ago · Santiago Gelvez Relatório
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