Skip to content

Commit

Permalink
refactor: remove redundant getTask function
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlo-skumenko committed Aug 17, 2024
1 parent e8da273 commit 18680fd
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions src/services/tasks/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
import { Task } from '@/types';
import { addDoc, collection, CollectionReference, deleteDoc, doc, getDoc, updateDoc } from 'firebase/firestore';
import { addDoc, collection, CollectionReference, deleteDoc, doc, updateDoc } from 'firebase/firestore';
import { db } from '../db';

export const getTasksCollection = (): CollectionReference => {
return collection(db, 'tasks');
};

export const getTask = async (taskId: Task['id']): Promise<Task | null | undefined> => {
const docRef = doc(db, 'tasks', taskId);
const docSnap = await getDoc(docRef);

if (!docSnap.exists()) {
throw Error();
}

const data = {
...docSnap.data(),
id: taskId,
};

return data as Task;
};

export const createTask = async (task: Omit<Task, 'id' | 'isCompleted'>) => {
const tasksCol = getTasksCollection();
await addDoc(tasksCol, task);
Expand Down

0 comments on commit 18680fd

Please sign in to comment.