Issue
I'm trying to create a form to add more admins to my project.
async addAdmin() {
const querySnapshot = await getDocs(collection(this.db, "admin-requests"));
querySnapshot.forEach((doc) => {
if (doc.data().email === this.addAdminFormGroup.controls.adminEmail.value) {
setDoc(doc(this.db, "admins", doc.data().uid), {
name: doc.data().name,
email: doc.data().email,
uid: doc.data().uid
});
}
});
}
setDoc(doc(...
doc part is giving me an error that is:
(parameter) doc: QueryDocumentSnapshot DocumentData
This expression is not callable. Type 'QueryDocumentSnapshot DocumentData ' has no call signatures.ts(2349)
Solution
The problem was using doc name for both forEach document and for the function.
Changed the forEach document name for fixing the problem and snapshot name for more readability.
Correct way:
async addAdmin() {
const adminRequestsSnapshot = await getDocs(collection(this.db, "admin-requests"));
adminRequestsSnapshot.forEach((adminRequestDoc) => {
if (adminRequestDoc.data().email === this.addAdminFormGroup.controls.adminEmail.value) {
setDoc(doc(this.db, "admins", adminRequestDoc.data().uid), {
name: adminRequestDoc.data().name,
email: adminRequestDoc.data().email,
uid: adminRequestDoc.data().uid
});
}
});
}
Answered By - lowint
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.