Created
July 16, 2022 19:51
-
-
Save raviyasas/96ce1af06f5dcf618c56ee9194c16716 to your computer and use it in GitHub Desktop.
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
import { db } from "../firebase-config" | |
import { doc, getDoc, getDocs, collection, addDoc, updateDoc, deleteDoc} from "firebase/firestore"; | |
const tasksCollectionRef = collection(db, "tasks"); | |
class TaskService{ | |
getTask = (id) => { | |
const taskDoc = doc(db, "tasks", id); | |
return getDoc(taskDoc); | |
} | |
getAllTasks = () => { | |
return getDocs(tasksCollectionRef); | |
} | |
addTasks = (newTask) => { | |
return addDoc(tasksCollectionRef, newTask); | |
} | |
updateTask = (id, updatedTask) => { | |
const taskDoc = doc(db, "tasks", id); | |
return updateDoc(taskDoc, updatedTask); | |
} | |
deleteTask = (id) => { | |
const taskDoc = doc(db, "tasks", id); | |
return deleteDoc(taskDoc); | |
} | |
} | |
export default new TaskService(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment