|
|
|
@ -573,10 +573,77 @@ export class AdminService { |
|
|
|
) |
|
|
|
]); |
|
|
|
|
|
|
|
// Apply field updates after renaming
|
|
|
|
const finalDataSource = DataSource[newDataSource.toString()]; |
|
|
|
const symbolProfileOverrides = { |
|
|
|
assetClass: assetClass as AssetClass, |
|
|
|
assetSubClass: assetSubClass as AssetSubClass, |
|
|
|
countries: countries as Prisma.JsonArray, |
|
|
|
name: name as string, |
|
|
|
sectors: sectors as Prisma.JsonArray, |
|
|
|
url: url as string |
|
|
|
}; |
|
|
|
|
|
|
|
// Check if we need to delete SymbolProfileOverrides when converting to MANUAL
|
|
|
|
let deleteOverrides = false; |
|
|
|
if (finalDataSource === 'MANUAL') { |
|
|
|
const renamedProfile = |
|
|
|
await this.prismaService.symbolProfile.findFirst({ |
|
|
|
where: { |
|
|
|
dataSource: finalDataSource, |
|
|
|
symbol: newSymbol as string |
|
|
|
}, |
|
|
|
select: { |
|
|
|
SymbolProfileOverrides: true |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
deleteOverrides = !!renamedProfile?.SymbolProfileOverrides; |
|
|
|
} |
|
|
|
|
|
|
|
const updatedSymbolProfile: Prisma.SymbolProfileUpdateInput = { |
|
|
|
comment, |
|
|
|
currency, |
|
|
|
holdings, |
|
|
|
isActive, |
|
|
|
scraperConfiguration, |
|
|
|
symbolMapping, |
|
|
|
...(finalDataSource === 'MANUAL' |
|
|
|
? { |
|
|
|
assetClass, |
|
|
|
assetSubClass, |
|
|
|
countries, |
|
|
|
name, |
|
|
|
sectors, |
|
|
|
url, |
|
|
|
...(deleteOverrides && { |
|
|
|
SymbolProfileOverrides: { |
|
|
|
delete: true |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
: { |
|
|
|
SymbolProfileOverrides: { |
|
|
|
upsert: { |
|
|
|
create: symbolProfileOverrides, |
|
|
|
update: symbolProfileOverrides |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}; |
|
|
|
|
|
|
|
await this.symbolProfileService.updateSymbolProfile( |
|
|
|
{ |
|
|
|
dataSource: finalDataSource, |
|
|
|
symbol: newSymbol as string |
|
|
|
}, |
|
|
|
updatedSymbolProfile |
|
|
|
); |
|
|
|
|
|
|
|
const [updatedAssetProfile] = |
|
|
|
await this.symbolProfileService.getSymbolProfiles([ |
|
|
|
{ |
|
|
|
dataSource: DataSource[newDataSource.toString()], |
|
|
|
dataSource: finalDataSource, |
|
|
|
symbol: newSymbol as string |
|
|
|
} |
|
|
|
]); |
|
|
|
|