manifold/web/lib/firebase/contract-metrics.ts
James Grugett 70b2b14f80
Daily profit 💰 (#1023)
* Daily profit client side

* Filter out those where profit rounds to 0

* Tabs to spaces
2022-10-11 00:32:55 -05:00

24 lines
515 B
TypeScript

import { ContractMetrics } from 'common/calculate-metrics'
import {
query,
limit,
Query,
collection,
orderBy,
where,
} from 'firebase/firestore'
import { db } from './init'
export function getUserContractMetricsQuery(
userId: string,
count: number,
sort: 'asc' | 'desc'
) {
return query(
collection(db, 'users', userId, 'contract-metrics'),
where('from.day.profit', sort === 'desc' ? '>' : '<', 0),
orderBy('from.day.profit', sort),
limit(count)
) as Query<ContractMetrics>
}