Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
yuto-trd committed Oct 26, 2024
1 parent eda9f21 commit 4469862
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions task_yell/src/firebase/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ import {
deleteDoc,
doc,
//追加
WithFieldValue,
DocumentData,
type WithFieldValue,
type DocumentData,
getDoc,
} from "firebase/firestore";

/** dataが WithFieldValue<DocumentData> を拡張するように制約を追加 */
export async function createData<T extends WithFieldValue<DocumentData>>(
collectionName: string,
data: T
data: T,
): Promise<string> {
const docRef = await addDoc(collection(db, collectionName), data);
return docRef.id;
}

export async function readData<T>(collectionName: string): Promise<T[]> {
const snapshot = await getDocs(collection(db, collectionName));
return snapshot.docs.map((doc) => ({ id: doc.id, ...doc.data() } as T));
return snapshot.docs.map((doc) => ({ id: doc.id, ...doc.data() }) as T);
}

export async function readSingleData<T>(
collectionName: string,
id: string
id: string,
): Promise<T | null> {
const docRef = doc(db, collectionName, id);
const snapshot = await getDoc(docRef);
Expand All @@ -39,15 +39,15 @@ export async function readSingleData<T>(
export async function updateData<T>(
collectionName: string,
id: string,
data: Partial<T>
data: Partial<T>,
): Promise<void> {
const docRef = doc(db, collectionName, id);
await updateDoc(docRef, data);
}

export async function deleteData(
collectionName: string,
id: string
id: string,
): Promise<void> {
const docRef = doc(db, collectionName, id);
await deleteDoc(docRef);
Expand Down
2 changes: 1 addition & 1 deletion task_yell/src/lib/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function readSingleEvent(id: string): Promise<Event | null> {

export async function updateEvent(
id: string,
eventData: Partial<Event>
eventData: Partial<Event>,
): Promise<void> {
return updateData<Event>(COLLECTION_NAME, id, eventData);
}
Expand Down
2 changes: 1 addition & 1 deletion task_yell/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export interface Notification {
type: "call" | "push";
eventOrTaskRef: string;
userId: string;
}
}

0 comments on commit 4469862

Please sign in to comment.