Skip to content

Instantly share code, notes, and snippets.

@raviyasas
Created July 16, 2022 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raviyasas/96ce1af06f5dcf618c56ee9194c16716 to your computer and use it in GitHub Desktop.
Save raviyasas/96ce1af06f5dcf618c56ee9194c16716 to your computer and use it in GitHub Desktop.
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