-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ffd92e
commit 1290292
Showing
3 changed files
with
33 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
import { User } from "firebase/auth"; | ||
import {getTransactions} from "./firestore.ts"; | ||
import {User} from "firebase/auth"; | ||
import {getTransactions, getTransactionsFilterOrderBy, Transaction} from "./firestore.ts"; | ||
import {where} from "firebase/firestore"; | ||
|
||
export async function getCurrentBalance(user: User): Promise<number> { | ||
const transactions = await getTransactions(user); | ||
let balance = 0; | ||
transactions.forEach(transaction => {balance += transaction.amount;}); | ||
return Math.round(balance * 100) / 100; | ||
} | ||
|
||
const MONTH_MILLIS = 2.628e+9; | ||
|
||
export async function getLastMonthTransaction(user: User): Promise<Transaction[]> { | ||
return await getTransactionsFilterOrderBy(user, where("dateTime", ">", Date.now() - MONTH_MILLIS)); | ||
} | ||
|
||
const WEEK_MILLIS = 6.048e+8; | ||
|
||
export async function getLastWeekTransaction(user: User): Promise<Transaction[]> { | ||
return await getTransactionsFilterOrderBy(user, where("dateTime", ">", Date.now() - WEEK_MILLIS)); | ||
} | ||
|
||
const DAY_MILLIS = 8.64e+7; | ||
|
||
export async function getLastDayTransaction(user: User): Promise<Transaction[]> { | ||
return await getTransactionsFilterOrderBy(user, where("dateTime", ">", Date.now() - DAY_MILLIS)); | ||
} |