function returned undefined

Can anybody help me? my function is returning undefined even the returned variable is not undefined.


export function getMembro (invoc, senha) {
console.log("Pegando Membro em : " + invoc + " " + senha + “…”);
wixData.query(“Membros”)
// Query the collection for any items whose “Name” field contains
// the value the user entered in the input element
.eq(“invocador”, invoc)
.find()// Run the query
.then(res => {
res.query.eq(“senha”, senha)
.find()
.then(ress => {
//return JSON.stringify(ress.items[0]);
console.log("Pegou Membro com sucesso! : ");
console.log(ress.items[0]);
return ress.items[0];
}). catch ( (error) => {
console.log(“Nâo foi possivel pegar o Membro!(senha)”);
} );
}). catch ( (error) => {
console.log(“Nâo foi possivel pegar o Membro!(invocador)”);
} );
}


plssss

console.log(ress.items[0]); in console it shows anything?

Try using the “and” condition since you are testing for two conditions. The way you did it, it appears you are trying to query the results of the first query. Using the “and approach” you will not be able to tell which one failed, but it should return the correct results if both conditions are met. I redid your query to give you an idea of how to proceed doing it this way. Obviously, I can’t test it since I don’t have your data and am not sure exactly what you’re trying to do. I did test this approach on a collection that I have, and it returned the expected results.

export function getMembro (invoc, senha) {
console.log("Pegando Membro em : " + invoc + " " + senha + “…”);
wixData.query(“Membros”)
// Query the collection for any items whose “Name” field contains
// the value the user entered in the input element
.eq(“invocador”, invoc)
.and(
wixData.query(“Membros”)
.eq(“senha”, senha)
)
.find()// Run the query
.then(res => {
console.log("Pegou Membro com sucesso! : ");
console.log(res.items[0]);
return res.items[0];
}). catch ( (error) => {
console.log(“Nâo foi possivel pegar o Membro!(invocador)”);
} );
}

1 Like