1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-10 07:55:21 +02:00

rollback more stuff

This commit is contained in:
Tyler Myracle 2024-01-19 19:34:34 -06:00
parent 18562477bf
commit 187b84e1c5
4 changed files with 271 additions and 262 deletions

View file

@ -99,21 +99,7 @@ export async function createTestInvestmentAccount(
(s) => s.date === it.date && s.ticker === it.ticker (s) => s.date === it.date && s.ticker === it.ticker
)?.price )?.price
function getTransactionCategory(type: string) { const isCashFlow = it.type === 'DEPOSIT' || it.type === 'WITHDRAW'
switch (type) {
case 'BUY':
return 'buy'
case 'SELL':
return 'sell'
case 'DIVIDEND':
return 'dividend'
case 'DEPOSIT':
case 'WITHDRAW':
return 'transfer'
default:
return undefined
}
}
return { return {
securityId: securities.find((s) => it.ticker === s.symbol)?.id, securityId: securities.find((s) => it.ticker === s.symbol)?.id,
@ -122,7 +108,26 @@ export async function createTestInvestmentAccount(
amount: price ? new Prisma.Decimal(price).times(it.qty) : it.qty, amount: price ? new Prisma.Decimal(price).times(it.qty) : it.qty,
quantity: price ? it.qty : 0, quantity: price ? it.qty : 0,
price: price ?? 0, price: price ?? 0,
category: getTransactionCategory(it.type), plaidType:
isCashFlow || it.type === 'DIVIDEND'
? 'cash'
: it.type === 'BUY'
? 'buy'
: it.type === 'SELL'
? 'sell'
: undefined,
plaidSubtype:
it.type === 'DEPOSIT'
? 'deposit'
: it.type === 'WITHDRAW'
? 'withdrawal'
: it.type === 'DIVIDEND'
? 'dividend'
: it.type === 'BUY'
? 'buy'
: it.type === 'SELL'
? 'sell'
: undefined,
} }
}), }),
}, },

View file

@ -70,7 +70,8 @@ export class InvestmentTransactionBalanceSyncStrategy extends BalanceSyncStrateg
it.account_id = ${pAccountId} it.account_id = ${pAccountId}
AND it.date BETWEEN ${pStart} AND now() AND it.date BETWEEN ${pStart} AND now()
AND ( -- filter for transactions that modify a position AND ( -- filter for transactions that modify a position
it.category IN ('buy', 'sell', 'transfer') it.plaid_type IN ('buy', 'sell', 'transfer')
OR it.finicity_transaction_id IS NOT NULL
) )
GROUP BY GROUP BY
1, 2 1, 2

View file

@ -243,7 +243,10 @@ export class AccountQueryService implements IAccountQueryService {
AND it.date BETWEEN sd.start_date AND ${pEnd} AND it.date BETWEEN sd.start_date AND ${pEnd}
-- filter for investment_transactions that represent external flows -- filter for investment_transactions that represent external flows
AND ( AND (
it.category = 'transfer' (it.plaid_type = 'cash' AND it.plaid_subtype IN ('contribution', 'deposit', 'withdrawal'))
OR (it.plaid_type = 'transfer' AND it.plaid_subtype IN ('transfer'))
OR (it.plaid_type = 'buy' AND it.plaid_subtype IN ('contribution'))
OR (it.finicity_transaction_id IS NOT NULL AND it.finicity_investment_transaction_type IN ('contribution', 'deposit', 'transfer'))
) )
GROUP BY GROUP BY
1, 2 1, 2

View file

@ -315,9 +315,6 @@ export class InsightService implements IInsightService {
{ {
finicityInvestmentTransactionType: 'dividend', finicityInvestmentTransactionType: 'dividend',
}, },
{
category: 'dividend',
},
], ],
}, },
}), }),
@ -750,7 +747,10 @@ export class InsightService implements IInsightService {
WHERE WHERE
it.account_id = ${accountId} it.account_id = ${accountId}
AND ( AND (
it.category = 'transfer' (it.plaid_type = 'cash' AND it.plaid_subtype IN ('contribution', 'deposit', 'withdrawal'))
OR (it.plaid_type = 'transfer' AND it.plaid_subtype IN ('transfer', 'send', 'request'))
OR (it.plaid_type = 'buy' AND it.plaid_subtype IN ('contribution'))
OR (it.finicity_transaction_id IS NOT NULL AND it.finicity_investment_transaction_type IN ('contribution', 'deposit', 'transfer'))
) )
-- Exclude any contributions made prior to the start date since balances will be 0 -- Exclude any contributions made prior to the start date since balances will be 0
AND (a.start_date is NULL OR it.date >= a.start_date) AND (a.start_date is NULL OR it.date >= a.start_date)