-
Notifications
You must be signed in to change notification settings - Fork 23
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
Showing
8 changed files
with
320 additions
and
135 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Add accountType to accounts | ||
export default (state) => { | ||
if (!state.accounts) return state | ||
return { | ||
...state, | ||
accounts: { | ||
...state.accounts, | ||
byId: Object.values(state.accounts.byId).reduce((result, account) => ({ | ||
...result, | ||
[account.id]: { ...account, accountType: 'Bank' } | ||
}), {}) | ||
} | ||
} | ||
} |
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,11 @@ | ||
// Cleanup settings (remove snackbarMessage) | ||
export default (state) => { | ||
if (!state.settings) return state | ||
return { | ||
...state, | ||
settings: { | ||
currency: state.settings.currency, | ||
locale: state.settings.locale | ||
} | ||
} | ||
} |
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,21 @@ | ||
// Update transaction amount | ||
// Remove dates array from exchangeRates | ||
export default (state) => { | ||
if (!state.transactions) return state | ||
return { | ||
...state, | ||
transactions: { | ||
list: state.transactions.list.map((transaction) => ({ | ||
...transaction, | ||
amount: { accountCurrency: transaction.amount, localCurrency: null } | ||
})) | ||
}, | ||
exchangeRates: Object.keys(state.exchangeRates).reduce((result, currency) => { | ||
const { dates, ...exchangeRates } = state.exchangeRates[currency] | ||
return { | ||
...result, | ||
[currency]: exchangeRates | ||
} | ||
}, {}) | ||
} | ||
} |
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,62 @@ | ||
import uuid from 'uuid/v4' | ||
|
||
export default (state) => { | ||
if (!('budget' in state)) return state | ||
if (Object.keys(state.budget.rules).length === 0) return state | ||
const { transactions, budget: { rules } } = state | ||
|
||
const existingRules = {} | ||
const newRules = {} | ||
const changes = {} | ||
transactions.list.forEach((transaction) => { | ||
if ( | ||
!transaction.ruleId | ||
&& transaction.categoryId | ||
&& transaction.description in rules | ||
&& rules[transaction.description].categoryId === transaction.categoryId | ||
) { | ||
if (!(transaction.description in existingRules)) { | ||
existingRules[transaction.description] = { } | ||
} | ||
if (!(transaction.accountId in existingRules[transaction.description])) { | ||
existingRules[transaction.description][transaction.accountId] = { | ||
categoryId: transaction.categoryId, | ||
transactions: [] | ||
} | ||
} | ||
existingRules[transaction.description][transaction.accountId].transactions.push(transaction) | ||
} | ||
}) | ||
|
||
Object.keys(existingRules).forEach((match) => { | ||
Object.keys(existingRules[match]).forEach((accountId) => { | ||
const ruleId = uuid() | ||
newRules[ruleId] = { | ||
id: ruleId, | ||
accountId, | ||
attributes: { categoryId: existingRules[match][accountId].categoryId }, | ||
filterBy: { description: { type: 'equals', value: match } } | ||
} | ||
existingRules[match][accountId].transactions.forEach((transaction) => { | ||
changes[transaction.id] = { ...transaction, ruleId } | ||
}) | ||
}) | ||
}) | ||
|
||
return { | ||
...state, | ||
transactions: { | ||
...state.transactions, | ||
list: state.transactions.list.map((transaction) => { | ||
if (transaction.id in changes) return changes[transaction.id] | ||
return transaction | ||
}) | ||
}, | ||
budget: { | ||
...state.budget, | ||
rules: Object.values(state.budget.rules).reduce( | ||
(res, rule) => ('id' in rule ? { ...res, [rule.id]: rule } : res), newRules | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.