From b3f5b37de47bd473b94b2b4a03539d4fd2695f39 Mon Sep 17 00:00:00 2001 From: brayo Date: Tue, 26 Mar 2024 12:21:41 +0300 Subject: [PATCH] add querying support --- src/firebase/data.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/firebase/data.ts b/src/firebase/data.ts index 4702d7c..0e52c78 100644 --- a/src/firebase/data.ts +++ b/src/firebase/data.ts @@ -50,10 +50,14 @@ export async function addScreenTimeData(userId: number, data: ScreenTimeData) { } } -export async function getScreenTimeData(userId: string): Promise { - const colPath = `screentime/${userId}/${userId}` - const colRef = collection(db, colPath) - const snapshot = await getDocs(colRef) +export async function getScreenTimeData(userId: string, since: Date | null = null, _public: Boolean = true): Promise { + const q = query( + collection(db, 'screentime/' + userId + '/' + userId), + // where('date', '>=', since || new Date('1900-1-1')), + where('public', '==', _public) + ) + + const snapshot = await getDocs(q) if (snapshot.empty) { return null }