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

177
Visualizações
How to get the public property value of a class?

I created a function in a class that inserts a data in the users table. I have a data property that stores the all inserted data. My current problem is, whenever I will try to log the data, it returns an empty array.

I can confirm that there is nothing wrong with prisma, because the it logs the actual inserted data (there is a console log in the code below). I suspect that this could be promise issue, but I can't confirm and until now I'm unable to find solution.

I have tried wrapping the forEach by Promise.all(..), but it returns a typescript error. I would appreciate any comment or suggestion, since I already burned over an hour of this problem.

my class:

class StudentFac {
  public data: IProvider[] = []

  public run = async () => {
    ....
  
    data.forEach(async (data, index) => {
      this.data[index] = await prisma.user.create({ data })
      console.log(this.data[index])  <------------ it displays actual data here
    })
  }
}

how I use:

const studentFac = new StudentFac()
await studentFac.run();

console.log(studentFac.data) <--------------- returns empty array
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