Browse Source

not custom asset profiles filtered out

pull/5243/head
Attila Cseh 4 weeks ago
parent
commit
396ca3a664
  1. 105
      apps/api/src/app/import/import.service.ts

105
apps/api/src/app/import/import.service.ts

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

Loading…
Cancel
Save