2022-04-29 23:35:56 +00:00
|
|
|
import { collection, query, where, orderBy } from 'firebase/firestore'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { Txn } from 'common/txn'
|
2022-04-29 23:35:56 +00:00
|
|
|
|
|
|
|
import { db } from './init'
|
2022-05-03 17:25:14 +00:00
|
|
|
import { getValues, listenForValues } from './utils'
|
2022-04-29 23:35:56 +00:00
|
|
|
|
|
|
|
const txnCollection = collection(db, 'txns')
|
|
|
|
|
|
|
|
const getCharityQuery = (charityId: string) =>
|
|
|
|
query(
|
|
|
|
txnCollection,
|
|
|
|
where('toType', '==', 'CHARITY'),
|
|
|
|
where('toId', '==', charityId),
|
|
|
|
orderBy('createdTime', 'desc')
|
|
|
|
)
|
|
|
|
|
|
|
|
export function listenForCharityTxns(
|
|
|
|
charityId: string,
|
|
|
|
setTxns: (txns: Txn[]) => void
|
|
|
|
) {
|
|
|
|
return listenForValues<Txn>(getCharityQuery(charityId), setTxns)
|
|
|
|
}
|
2022-05-02 17:55:40 +00:00
|
|
|
|
|
|
|
const charitiesQuery = query(txnCollection, where('toType', '==', 'CHARITY'))
|
|
|
|
|
2022-05-03 17:25:14 +00:00
|
|
|
export function getAllCharityTxns() {
|
|
|
|
return getValues<Txn>(charitiesQuery)
|
2022-05-02 17:55:40 +00:00
|
|
|
}
|