Skip to content

Commit

Permalink
add querying support
Browse files Browse the repository at this point in the history
  • Loading branch information
brayo-pip committed Mar 26, 2024
1 parent 12d6e53 commit b3f5b37
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/firebase/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ export async function addScreenTimeData(userId: number, data: ScreenTimeData) {
}
}

export async function getScreenTimeData(userId: string): Promise<ScreenTimeData[] | null> {
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<ScreenTimeData[] | null> {
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
}
Expand Down

0 comments on commit b3f5b37

Please sign in to comment.