Sorry for my question which is probably simple but I didn't find the solution of my problem. I need to get one information from Firebase and the below function works well -> I've the console loging empty or not empty accordingly to the situation but I don't find a way to obtain the results elsewhere. It's probably cause I don't know how to use a Promise but ... I don't find the correct way to retrieve the boolean. Here is the function :
async checkIfCreatorUuidHasGameUuid(creatorUuid: string, showModeration: boolean, gameUuid : string): Promise<boolean> {
try {
let snap: firebase.firestore.QuerySnapshot;
if (showModeration) {
snap = await this.firestoreService.db.collection('announces').where('creatorUuid', '==', creatorUuid).where('gameUuid', '==', gameUuid).get();
} else {
snap = await this.firestoreService.db.collection('announces')
.where('creatorUuid', '==', creatorUuid).where('inModeration', '==', false).where('gameUuid', '==', gameUuid).get();
}
if(snap.empty){
console.log("empty")
return false;
} else {
console.log("not empty")
return true;
}
} catch (e) {
console.error(e);
}
}
Here is the call to this function :
if (this.announceService.checkIfCreatorUuidHasGameUuid(activeUser.uuid, true, this.game.uuid)) {
console.log("true")
}
It always log true and the promise returned by my previous function is always the same wether it's logging "empty" or "not empty" in the function above. What did I do wrong ? The function and the call to the function are in two separates pages for information Thanks