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

174
Visualizações
Converting a function into a promise

I have a function which takes some time to complete, because of that , I want to turn it into a promise.

  • My goal is to be able to call the function/promise and after it is fullfilled I can use use a .then() to do whatever I want.

  • I want getPlantMaterials() to be resolved , after I get the API response.

I'am not sure how to correctly convert this into a promise, though :

getPlantMaterials() {
            this.isLoadingPlantMaterials = true;
            this.$apollo
                .query({
                    query: gql`
                        query getMaterialByPotSizeId($plantPotSizeId: ID) {
                            tenantPlantMaterials(
                                plantPotSize_Id: $plantPotSizeId
                            ) {
                                edges {
                                    node {
                                        id
                                        quantity
                                        material {
                                            id
                                            name
                                            materialType {
                                                name
                                                id
                                            }
                                            brand
                                            vendor
                                            size
                                            unit
                                            inventory
                                            id
                                        }
                                    }
                                }
                                totalCount
                            }
                        }
                    `,
                    variables: {
                        plantPotSizeId: this.selectedPlant.plantPotSize.id,
                        materialId: null,
                        quantity: null
                    }
                })
                .then(response => {
                    this.selectedPlantMaterials =
                        response.data.tenantPlantMaterials.edges;
                    this.selectedPlantMaterials.map(item => {
                        item.node.totalAmount =
                            item.node.quantity * this.totalPlantQuantity;
                    });
                    console.log(
                        "this.selectedPlantMaterials",
                        this.selectedPlantMaterials
                    );
                })
                .finally(() => {
                    this.isLoadingPlantMaterials = false;
                });
        },

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