manifold/web/lib/firebase/txns.ts
Marshall Polaris acc9c84e2e
More absolute imports (#156)
* Configure functions module to allow absolute imports

* Convert common imports in functions to be absolute

* Convert common imports in web to be absolute

* Convert lib imports in web to be absolute

* Convert hooks imports in web to be absolute

* Convert components imports in web to be absolute
2022-05-09 09:04:36 -04:00

30 lines
770 B
TypeScript

import { collection, query, where, orderBy } from 'firebase/firestore'
import _ from 'lodash'
import { Txn } from 'common/txn'
import { db } from './init'
import { getValues, listenForValues } from './utils'
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)
}
const charitiesQuery = query(txnCollection, where('toType', '==', 'CHARITY'))
export function getAllCharityTxns() {
return getValues<Txn>(charitiesQuery)
}