-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added functions to take file, find fs doc using userID and to u…
…pdate it with file URL
- Loading branch information
Showing
6 changed files
with
81 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// uploading to cloudinary | ||
export const uploadReceipt = async imageFile => { | ||
try { | ||
const formData = new FormData(); | ||
formData.append('file', imageFile); | ||
formData.append('upload_preset', import.meta.env.VITE_PUBLIC_CLOUDINARY_RECEIPT_NAME); | ||
|
||
const response = await fetch(import.meta.env.VITE_PUBLIC_CLOUDINARY_PRESET_URL, { | ||
method: 'POST', | ||
body: formData, | ||
}); | ||
|
||
if (!response.ok) { | ||
console.log('Failed to upload image:', response.statusText); | ||
throw new Error(`Failed to upload image: ${response.statusText}`); | ||
} | ||
|
||
const data = await response.json(); | ||
console.log('uploaded file', data.secure_url); | ||
return data.secure_url; | ||
} catch (error) { | ||
console.error('Error uploading image to Cloudinary:', error); | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { collection, getDocs, query, updateDoc, where } from 'firebase/firestore'; | ||
import { db } from './firebaseConfig'; | ||
|
||
// add proofURL to the doc using uid | ||
export const updateDocumentByUid = async (userId, proofURL) => { | ||
try { | ||
const q = query(collection(db, 'users'), where('uid', '==', userId)); | ||
const querySnapshot = await getDocs(q); | ||
|
||
if (!querySnapshot.empty) { | ||
const userDoc = querySnapshot.docs[0]; | ||
|
||
// Update the document by adding proof of payment | ||
await updateDoc(userDoc.ref, { | ||
paymentProof: proofURL, | ||
}); | ||
} else { | ||
console.log('No documents found matching the name: ', userId); | ||
} | ||
} catch (error) { | ||
console.error('Error updating document:', error); | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters