diff options
| author | omagdy7 <omar.professional8777@gmail.com> | 2023-12-23 01:39:59 +0200 |
|---|---|---|
| committer | omagdy7 <omar.professional8777@gmail.com> | 2023-12-23 01:39:59 +0200 |
| commit | fbaae8f461ff085356670d41506cd92180227beb (patch) | |
| tree | a7a6b9c83f22961c1b4e5cea02841a2f58f81116 /driver/src/utils | |
| parent | 776f680ca58d066e24284b009eb9a28ced03a6ea (diff) | |
| download | carpool-fbaae8f461ff085356670d41506cd92180227beb.tar.xz carpool-fbaae8f461ff085356670d41506cd92180227beb.zip | |
Final version
Diffstat (limited to 'driver/src/utils')
| -rw-r--r-- | driver/src/utils/fetchUserIdByPhoneNumber.ts | 24 | ||||
| -rw-r--r-- | driver/src/utils/updateStatus.ts | 24 |
2 files changed, 48 insertions, 0 deletions
diff --git a/driver/src/utils/fetchUserIdByPhoneNumber.ts b/driver/src/utils/fetchUserIdByPhoneNumber.ts new file mode 100644 index 0000000..843ac67 --- /dev/null +++ b/driver/src/utils/fetchUserIdByPhoneNumber.ts @@ -0,0 +1,24 @@ +import { auth, db } from "@/firebase/firebase_config"; +import { DocumentData, collection, getDocs, query, where } from "firebase/firestore"; + + +export const fetchUserIdByPhoneNumber = async (phoneNumber: any) => { + try { + const user = auth.currentUser; + let data = null + if (user) { + const usersRef = collection(db, "users") + const q = query(usersRef, where("phoneNumber", "==", phoneNumber)) + const querySnapshot = await getDocs(q); + querySnapshot.forEach((doc: DocumentData) => { + data = doc.data() + }); + return data.uid; + } else { + console.log("There is no user"); + return null; + } + } catch (error) { + console.error('Error fetching user details:', error); + } +}; diff --git a/driver/src/utils/updateStatus.ts b/driver/src/utils/updateStatus.ts new file mode 100644 index 0000000..a717905 --- /dev/null +++ b/driver/src/utils/updateStatus.ts @@ -0,0 +1,24 @@ +import { db } from "@/firebase/firebase_config"; +import { collection, doc, getDocs, query, updateDoc, where } from "firebase/firestore"; + +export const updateStatus = async (userId, newStatus) => { + console.log("userID: ", userId) + try { + const q = query(collection(db, 'RideRequest'), where('passengerID', '==', userId)); + const querySnapshot = await getDocs(q); + + querySnapshot.forEach(async (doc_data) => { + try { + const passengerRequestRef = doc(db, 'RideRequest', doc_data.id); + await updateDoc(passengerRequestRef, { + status: newStatus, + }); + console.log(`Status updated successfully for document ID: ${doc_data.id}`); + } catch (error) { + console.error('Error updating status:', error); + } + }); + } catch (error) { + console.error('Error fetching documents:', error); + } +}; |
