@ -160,7 +160,7 @@ export class AssetProfilesService {
} ) ,
} ) ,
this . prismaService . symbolProfile . count ( { where } )
this . prismaService . symbolProfile . count ( { where } )
] ) ;
] ) ;
const asset Profiles = symbolProfileResult [ 0 ] ;
const symbol Profiles = symbolProfileResult [ 0 ] ;
let count = symbolProfileResult [ 1 ] ;
let count = symbolProfileResult [ 1 ] ;
const lastMarketPrices = await this . prismaService . marketData . findMany ( {
const lastMarketPrices = await this . prismaService . marketData . findMany ( {
@ -173,12 +173,12 @@ export class AssetProfilesService {
} ,
} ,
where : {
where : {
dataSource : {
dataSource : {
in : asset Profiles. map ( ( { dataSource } ) = > {
in : symbol Profiles. map ( ( { dataSource } ) = > {
return dataSource ;
return dataSource ;
} )
} )
} ,
} ,
symbol : {
symbol : {
in : asset Profiles. map ( ( { symbol } ) = > {
in : symbol Profiles. map ( ( { symbol } ) = > {
return symbol ;
return symbol ;
} )
} )
}
}
@ -194,8 +194,8 @@ export class AssetProfilesService {
) ;
) ;
}
}
let marketData : AssetProfileItem [ ] = await Promise . all (
let assetProfiles : AssetProfileItem [ ] = await Promise . all (
asset Profiles. map ( async ( assetProfile ) = > {
symbol Profiles. map ( async ( assetProfile ) = > {
const {
const {
_count ,
_count ,
activities ,
activities ,
@ -239,8 +239,8 @@ export class AssetProfilesService {
currency ,
currency ,
dataSource ,
dataSource ,
id ,
id ,
isin ,
isActive ,
isActive ,
isin ,
lastMarketPrice ,
lastMarketPrice ,
marketDataItemCount ,
marketDataItemCount ,
name ,
name ,
@ -256,21 +256,21 @@ export class AssetProfilesService {
if ( presetId ) {
if ( presetId ) {
if ( presetId === 'ETF_WITHOUT_COUNTRIES' ) {
if ( presetId === 'ETF_WITHOUT_COUNTRIES' ) {
marketData = marketData . filter ( ( { countriesCount } ) = > {
assetProfiles = assetProfiles . filter ( ( { countriesCount } ) = > {
return countriesCount === 0 ;
return countriesCount === 0 ;
} ) ;
} ) ;
} else if ( presetId === 'ETF_WITHOUT_SECTORS' ) {
} else if ( presetId === 'ETF_WITHOUT_SECTORS' ) {
marketData = marketData . filter ( ( { sectorsCount } ) = > {
assetProfiles = assetProfiles . filter ( ( { sectorsCount } ) = > {
return sectorsCount === 0 ;
return sectorsCount === 0 ;
} ) ;
} ) ;
}
}
count = marketData . length ;
count = assetProfiles . length ;
}
}
return {
return {
count ,
assetProfiles ,
marketData
count
} ;
} ;
}
}
@ -348,50 +348,6 @@ export class AssetProfilesService {
return data ;
return data ;
}
}
private getExtendedPrismaClient() {
const symbolProfileExtension = Prisma . defineExtension ( ( client ) = > {
return client . $extends ( {
result : {
symbolProfile : {
isUsedByUsersWithSubscription : {
compute : async ( { id } ) = > {
const { _count } =
await this . prismaService . symbolProfile . findUnique ( {
select : {
_count : {
select : {
activities : {
where : {
user : {
subscriptions : {
some : {
expiresAt : {
gt : new Date ( )
}
}
}
}
}
}
}
}
} ,
where : {
id
}
} ) ;
return _count . activities > 0 ;
}
}
}
}
} ) ;
} ) ;
return this . prismaService . $extends ( symbolProfileExtension ) ;
}
private async getAssetProfilesForCurrencies ( ) : Promise < AssetProfilesResponse > {
private async getAssetProfilesForCurrencies ( ) : Promise < AssetProfilesResponse > {
const currencyPairs = this . exchangeRateDataService . getCurrencyPairs ( ) ;
const currencyPairs = this . exchangeRateDataService . getCurrencyPairs ( ) ;
@ -432,7 +388,7 @@ export class AssetProfilesService {
) ;
) ;
}
}
const marketDataPromise : Promise < AssetProfileItem > [ ] = currencyPairs . map (
const assetProfilePromises : Promise < AssetProfileItem > [ ] = currencyPairs . map (
async ( { dataSource , symbol } ) = > {
async ( { dataSource , symbol } ) = > {
let activitiesCount : EnhancedSymbolProfile [ 'activitiesCount' ] = 0 ;
let activitiesCount : EnhancedSymbolProfile [ 'activitiesCount' ] = 0 ;
let currency : EnhancedSymbolProfile [ 'currency' ] = '-' ;
let currency : EnhancedSymbolProfile [ 'currency' ] = '-' ;
@ -458,26 +414,71 @@ export class AssetProfilesService {
return {
return {
activitiesCount ,
activitiesCount ,
currency ,
dataSource ,
isin : null ,
lastMarketPrice ,
marketDataItemCount ,
symbol ,
assetClass : AssetClass.LIQUIDITY ,
assetClass : AssetClass.LIQUIDITY ,
assetSubClass : AssetSubClass.CASH ,
assetSubClass : AssetSubClass.CASH ,
comment : null ,
countriesCount : 0 ,
countriesCount : 0 ,
currency ,
dataSource ,
date : dateOfFirstActivity ,
date : dateOfFirstActivity ,
id : undefined ,
id : undefined ,
isActive : true ,
isActive : true ,
isin : null ,
lastMarketPrice ,
marketDataItemCount ,
name : symbol ,
name : symbol ,
sectorsCount : 0 ,
sectorsCount : 0 ,
symbol ,
watchedByCount : 0
watchedByCount : 0
} ;
} ;
}
}
) ;
) ;
const marketData = await Promise . all ( marketDataPromise ) ;
const assetProfiles = await Promise . all ( assetProfilePromises ) ;
return { marketData , count : marketData.length } ;
return { assetProfiles , count : assetProfiles.length } ;
}
private getExtendedPrismaClient() {
const symbolProfileExtension = Prisma . defineExtension ( ( client ) = > {
return client . $extends ( {
result : {
symbolProfile : {
isUsedByUsersWithSubscription : {
compute : async ( { id } ) = > {
const { _count } =
await this . prismaService . symbolProfile . findUnique ( {
select : {
_count : {
select : {
activities : {
where : {
user : {
subscriptions : {
some : {
expiresAt : {
gt : new Date ( )
}
}
}
}
}
}
}
}
} ,
where : {
id
}
} ) ;
return _count . activities > 0 ;
}
}
}
}
} ) ;
} ) ;
return this . prismaService . $extends ( symbolProfileExtension ) ;
}
}
}
}