forked from actualbudget/actual
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maintenance] Migrating util.js and chartTheme.js to typescript (actu…
- Loading branch information
1 parent
98093a9
commit 32e6f67
Showing
4 changed files
with
65 additions
and
46 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { runQuery } from 'loot-core/src/client/query-helpers'; | ||
import type { Query } from 'loot-core/src/shared/query'; | ||
|
||
export function fromDateRepr(date: string): string { | ||
return date.slice(0, 7); | ||
} | ||
|
||
export async function runAll( | ||
queries: Query[], | ||
cb: (data) => void, | ||
): Promise<void> { | ||
const data = await Promise.all( | ||
queries.map(q => { | ||
return runQuery(q).then(({ data }) => data); | ||
}), | ||
); | ||
cb(data); | ||
} | ||
|
||
export function index< | ||
T extends Record<string, string | number>, | ||
K extends keyof T, | ||
>(data: T[], field: K) { | ||
const result: Record<string | number, T> = {}; | ||
data.forEach(item => { | ||
const key = item[field]; | ||
result[key] = item; | ||
}); | ||
return result; | ||
} | ||
|
||
export function indexStack< | ||
T extends Record<string, string | number>, | ||
K extends keyof T, | ||
>(data: T[], fieldName: K, field: K) { | ||
const result: Record<string | number, T[K]> = {}; | ||
data.forEach(item => { | ||
result[item[fieldName]] = item[field]; | ||
}); | ||
return result; | ||
} | ||
|
||
export function indexCashFlow< | ||
T extends { date: string; isTransfer: boolean; amount: number }, | ||
>(data: T[], date: string, isTransfer: string) { | ||
const results = {}; | ||
data.forEach(item => { | ||
const findExisting = results[item.date] | ||
? results[item.date][item.isTransfer] | ||
? results[item.date][item.isTransfer] | ||
: 0 | ||
: 0; | ||
const result = { [item[isTransfer]]: item.amount + findExisting }; | ||
results[item[date]] = { ...results[item[date]], ...result }; | ||
}); | ||
return results; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
category: Maintenance | ||
authors: [ghosetuhin] | ||
--- | ||
|
||
Migrating the util.js and chartTheme.js files to typescript |