|
|
|
@ -63,6 +63,43 @@ export class ActivitiesService { |
|
|
|
private readonly symbolProfileService: SymbolProfileService |
|
|
|
) {} |
|
|
|
|
|
|
|
public areCashActivitiesExcludedByFilters(filters: Filter[] = []) { |
|
|
|
const { |
|
|
|
ASSET_CLASS: filtersByAssetClass = [], |
|
|
|
DATA_SOURCE: [filterByDataSource] = [], |
|
|
|
SYMBOL: [filterBySymbol] = [], |
|
|
|
TAG: filtersByTag = [] |
|
|
|
} = groupBy(filters, ({ type }) => { |
|
|
|
return type; |
|
|
|
}); |
|
|
|
|
|
|
|
const isFilteredByAssetClassOtherThanLiquidity = |
|
|
|
filtersByAssetClass.length > 0 && |
|
|
|
!filtersByAssetClass.some(({ id }) => { |
|
|
|
return id === AssetClass.LIQUIDITY; |
|
|
|
}); |
|
|
|
|
|
|
|
const isFilteredByAssetProfile = !!(filterByDataSource || filterBySymbol); |
|
|
|
const isFilteredByTag = filtersByTag.length > 0; |
|
|
|
|
|
|
|
const isFilteredByUnsupportedType = filters.some(({ type }) => { |
|
|
|
return ![ |
|
|
|
'ACCOUNT', |
|
|
|
'ASSET_CLASS', |
|
|
|
'DATA_SOURCE', |
|
|
|
'SYMBOL', |
|
|
|
'TAG' |
|
|
|
].includes(type); |
|
|
|
}); |
|
|
|
|
|
|
|
return ( |
|
|
|
isFilteredByAssetClassOtherThanLiquidity || |
|
|
|
isFilteredByAssetProfile || |
|
|
|
isFilteredByTag || |
|
|
|
isFilteredByUnsupportedType |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
public async assignTags({ |
|
|
|
dataSource, |
|
|
|
symbol, |
|
|
|
@ -393,7 +430,7 @@ export class ActivitiesService { |
|
|
|
userCurrency: string; |
|
|
|
userId: string; |
|
|
|
}): Promise<ActivitiesResponse> { |
|
|
|
if (this.hasNonMatchingFiltersForCashActivities(filters)) { |
|
|
|
if (this.areCashActivitiesExcludedByFilters(filters)) { |
|
|
|
return { |
|
|
|
activities: [], |
|
|
|
count: 0 |
|
|
|
@ -800,7 +837,7 @@ export class ActivitiesService { |
|
|
|
withExcludedAccountsAndActivities: false // TODO
|
|
|
|
}); |
|
|
|
|
|
|
|
if (withCash && !this.hasNonMatchingFiltersForCashActivities(filters)) { |
|
|
|
if (withCash && !this.areCashActivitiesExcludedByFilters(filters)) { |
|
|
|
const cashDetails = await this.accountService.getCashDetails({ |
|
|
|
filters, |
|
|
|
userId, |
|
|
|
@ -935,43 +972,6 @@ export class ActivitiesService { |
|
|
|
return activity; |
|
|
|
} |
|
|
|
|
|
|
|
private hasNonMatchingFiltersForCashActivities(filters: Filter[] = []) { |
|
|
|
const { |
|
|
|
ASSET_CLASS: filtersByAssetClass = [], |
|
|
|
DATA_SOURCE: [filterByDataSource] = [], |
|
|
|
SYMBOL: [filterBySymbol] = [], |
|
|
|
TAG: filtersByTag = [] |
|
|
|
} = groupBy(filters, ({ type }) => { |
|
|
|
return type; |
|
|
|
}); |
|
|
|
|
|
|
|
const isFilteredByAssetClassOtherThanLiquidity = |
|
|
|
filtersByAssetClass.length > 0 && |
|
|
|
!filtersByAssetClass.some(({ id }) => { |
|
|
|
return id === AssetClass.LIQUIDITY; |
|
|
|
}); |
|
|
|
|
|
|
|
const isFilteredByAssetProfile = !!(filterByDataSource || filterBySymbol); |
|
|
|
const isFilteredByTag = filtersByTag.length > 0; |
|
|
|
|
|
|
|
const isFilteredByUnsupportedType = filters.some(({ type }) => { |
|
|
|
return ![ |
|
|
|
'ACCOUNT', |
|
|
|
'ASSET_CLASS', |
|
|
|
'DATA_SOURCE', |
|
|
|
'SYMBOL', |
|
|
|
'TAG' |
|
|
|
].includes(type); |
|
|
|
}); |
|
|
|
|
|
|
|
return ( |
|
|
|
isFilteredByAssetClassOtherThanLiquidity || |
|
|
|
isFilteredByAssetProfile || |
|
|
|
isFilteredByTag || |
|
|
|
isFilteredByUnsupportedType |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
private async orders(params: { |
|
|
|
include?: Prisma.OrderInclude; |
|
|
|
skip?: number; |
|
|
|
|