Browse Source
Feature/improve export by applying filters on accounts and tags (#4425 )
* Improve export by applying filters on accounts and tags
* Update changelog
---------
Co-authored-by: Thomas Kaul <4159106+dtslvr@users.noreply.github.com>
pull/4462/head^2
csehatt741
4 weeks ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
58 additions and
42 deletions
CHANGELOG.md
apps/api/src/app/export/export.controller.ts
apps/api/src/app/export/export.service.ts
@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Improved the export functionality by applying filters on accounts and tags
- Improved the symbol validation in the _Yahoo Finance_ service (get asset profiles)
- Refactored `lodash.uniq` with `Array.from(new Set(...))`
- Refreshed the cryptocurrencies list
@ -21,10 +21,11 @@ export class ExportController {
@UseGuards ( AuthGuard ( 'jwt' ) , HasPermissionGuard )
public async export (
@Query ( 'accounts' ) filterByAccounts? : string ,
@Query ( 'activityIds' ) activityIds? : string [ ] ,
@Query ( 'activityIds' ) filterByActivityIds? : string ,
@Query ( 'assetClasses' ) filterByAssetClasses? : string ,
@Query ( 'tags' ) filterByTags? : string
) : Promise < Export > {
const activityIds = filterByActivityIds ? . split ( ',' ) ? ? [ ] ;
const filters = this . apiService . buildFiltersFromQueryParams ( {
filterByAccounts ,
filterByAssetClasses ,
@ -28,6 +28,22 @@ export class ExportService {
} ) : Promise < Export > {
const platformsMap : { [ platformId : string ] : Platform } = { } ;
let { activities } = await this . orderService . getOrders ( {
filters ,
userCurrency ,
userId ,
includeDrafts : true ,
sortColumn : 'date' ,
sortDirection : 'asc' ,
withExcludedAccounts : true
} ) ;
if ( activityIds ? . length > 0 ) {
activities = activities . filter ( ( { id } ) = > {
return activityIds . includes ( id ) ;
} ) ;
}
const accounts = (
await this . accountService . accounts ( {
include : {
@ -39,7 +55,15 @@ export class ExportService {
} ,
where : { userId }
} )
) . map (
)
. filter ( ( { id } ) = > {
return activities . length > 0
? activities . some ( ( { accountId } ) = > {
return accountId === id ;
} )
: true ;
} )
. map (
( {
balance ,
balances ,
@ -70,26 +94,16 @@ export class ExportService {
}
) ;
let { activities } = await this . orderService . getOrders ( {
filters ,
userCurrency ,
userId ,
includeDrafts : true ,
sortColumn : 'date' ,
sortDirection : 'asc' ,
withExcludedAccounts : true
} ) ;
if ( activityIds ) {
activities = activities . filter ( ( activity ) = > {
return activityIds . includes ( activity . id ) ;
} ) ;
}
const tags = ( await this . tagService . getTagsForUser ( userId ) )
. filter ( ( { isUsed } ) = > {
return isUsed ;
. filter (
( { id , isUsed } ) = >
isUsed &&
activities . some ( ( activity ) = > {
return activity . tags . some ( ( { id : tagId } ) = > {
return tagId === id ;
} ) ;
} )
)
. map ( ( { id , name } ) = > {
return {
id ,