manifold/web/lib/firebase/txns.ts
Sinclair Chen db695875c4
CPM: sort charities by amount raised (#117)
* Sort charities by amount raised (after Featured)

* Sort donations chronologically

* refactor charities query to remove parens
2022-05-02 10:55:40 -07:00

30 lines
819 B
TypeScript

import { collection, query, where, orderBy } from 'firebase/firestore'
import _ from 'lodash'
import { Txn } from '../../../common/txn'
import { db } from './init'
import { 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 listenForAllCharityTxns(setTxns: (txns: Txn[]) => void) {
return listenForValues<Txn>(charitiesQuery, setTxns)
}