|
@ -237,71 +237,59 @@ export class ImportService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!isDryRun && assetProfilesWithMarketDataDto?.length) { |
|
|
if (!isDryRun && assetProfilesWithMarketDataDto?.length) { |
|
|
// Filter out not custom asset profiles
|
|
|
const existingAssetProfiles = |
|
|
assetProfilesWithMarketDataDto = assetProfilesWithMarketDataDto.filter( |
|
|
await this.symbolProfileService.getSymbolProfiles( |
|
|
({ dataSource }) => { |
|
|
assetProfilesWithMarketDataDto.map(({ dataSource, symbol }) => { |
|
|
return dataSource === DataSource.MANUAL; |
|
|
return { dataSource, symbol }; |
|
|
} |
|
|
}) |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
if (assetProfilesWithMarketDataDto.length) { |
|
|
for (const assetProfileWithMarketData of assetProfilesWithMarketDataDto) { |
|
|
const existingAssetProfiles = |
|
|
// Check if there is any existing asset profile
|
|
|
await this.symbolProfileService.getSymbolProfiles( |
|
|
const existingAssetProfile = existingAssetProfiles.find( |
|
|
assetProfilesWithMarketDataDto.map(({ dataSource, symbol }) => { |
|
|
({ dataSource, symbol }) => { |
|
|
return { dataSource, symbol }; |
|
|
return ( |
|
|
}) |
|
|
dataSource === assetProfileWithMarketData.dataSource && |
|
|
); |
|
|
symbol === assetProfileWithMarketData.symbol |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
for (const assetProfileWithMarketData of assetProfilesWithMarketDataDto) { |
|
|
// If there is no asset profile or if the asset profile belongs to a different user, then create a new asset profile
|
|
|
// Check if there is any existing asset profile
|
|
|
if (!existingAssetProfile || existingAssetProfile.userId !== user.id) { |
|
|
const existingAssetProfile = existingAssetProfiles.find( |
|
|
const assetProfile: CreateAssetProfileDto = omit( |
|
|
({ dataSource, symbol }) => { |
|
|
assetProfileWithMarketData, |
|
|
return ( |
|
|
'marketData' |
|
|
dataSource === assetProfileWithMarketData.dataSource && |
|
|
|
|
|
symbol === assetProfileWithMarketData.symbol |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
// If there is no asset profile or if the asset profile belongs to a different user, then create a new asset profile
|
|
|
// Asset profile belongs to a different user
|
|
|
if ( |
|
|
if (existingAssetProfile) { |
|
|
!existingAssetProfile || |
|
|
const symbol = uuidv4(); |
|
|
existingAssetProfile.userId !== user.id |
|
|
assetProfileSymbolMapping[assetProfile.symbol] = symbol; |
|
|
) { |
|
|
assetProfile.symbol = symbol; |
|
|
const assetProfile: CreateAssetProfileDto = omit( |
|
|
} |
|
|
assetProfileWithMarketData, |
|
|
|
|
|
'marketData' |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// Asset profile belongs to a different user
|
|
|
// Create a new asset profile
|
|
|
if (existingAssetProfile) { |
|
|
const assetProfileObject: Prisma.SymbolProfileCreateInput = { |
|
|
const symbol = uuidv4(); // Generate a new symbol for the asset profile
|
|
|
...assetProfile, |
|
|
assetProfileSymbolMapping[assetProfile.symbol] = symbol; |
|
|
user: { connect: { id: user.id } } |
|
|
assetProfile.symbol = symbol; |
|
|
}; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Create a new asset profile
|
|
|
await this.symbolProfileService.add(assetProfileObject); |
|
|
const assetProfileObject: Prisma.SymbolProfileCreateInput = { |
|
|
} |
|
|
...assetProfile, |
|
|
|
|
|
user: { connect: { id: user.id } } |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
await this.symbolProfileService.add(assetProfileObject); |
|
|
// Insert or update market data
|
|
|
|
|
|
const marketDataObjects = assetProfileWithMarketData.marketData.map( |
|
|
|
|
|
(marketData) => { |
|
|
|
|
|
return { |
|
|
|
|
|
...marketData, |
|
|
|
|
|
dataSource: assetProfileWithMarketData.dataSource, |
|
|
|
|
|
symbol: assetProfileWithMarketData.symbol |
|
|
|
|
|
} as Prisma.MarketDataUpdateInput; |
|
|
} |
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
// Insert or update market data
|
|
|
await this.marketDataService.updateMany({ data: marketDataObjects }); |
|
|
const marketDataObjects = assetProfileWithMarketData.marketData.map( |
|
|
|
|
|
(marketData) => { |
|
|
|
|
|
return { |
|
|
|
|
|
...marketData, |
|
|
|
|
|
dataSource: assetProfileWithMarketData.dataSource, |
|
|
|
|
|
symbol: assetProfileWithMarketData.symbol |
|
|
|
|
|
} as Prisma.MarketDataUpdateInput; |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await this.marketDataService.updateMany({ data: marketDataObjects }); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|