diff --git a/CHANGELOG.md b/CHANGELOG.md index bd5deaf0b..72fcc5e70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Added a connect or create symbol profile model logic on creating a new transaction + ### Changed - Improved the global heat map to visualize investments by country diff --git a/apps/api/src/app/order/order.controller.ts b/apps/api/src/app/order/order.controller.ts index 379eb4c11..a386898a2 100644 --- a/apps/api/src/app/order/order.controller.ts +++ b/apps/api/src/app/order/order.controller.ts @@ -132,12 +132,26 @@ export class OrderController { return this.orderService.createOrder( { ...data, - date, Account: { connect: { id_userId: { id: accountId, userId: this.request.user.id } } }, + date, + SymbolProfile: { + connectOrCreate: { + where: { + dataSource_symbol: { + dataSource: data.dataSource, + symbol: data.symbol + } + }, + create: { + dataSource: data.dataSource, + symbol: data.symbol + } + } + }, User: { connect: { id: this.request.user.id } } }, this.request.user.id diff --git a/prisma/seed.ts b/prisma/seed.ts index f445a9ade..057698875 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -144,6 +144,12 @@ async function main() { id: '2bd26362-136e-411c-b578-334084b4cdcc', symbol: 'AMZN' }, + { + countries: null, + dataSource: DataSource.YAHOO, + id: 'fdc42ea6-1321-44f5-9fb0-d7f1f2cf9b1e', + symbol: 'BTCUSD' + }, { countries: [{ code: 'US', weight: 1 }], dataSource: DataSource.YAHOO, @@ -191,6 +197,7 @@ async function main() { id: 'a1c5d73a-8631-44e5-ac44-356827a5212c', quantity: 0.5614682, symbol: 'BTCUSD', + symbolProfileId: 'fdc42ea6-1321-44f5-9fb0-d7f1f2cf9b1e', type: Type.BUY, unitPrice: 3562.089535970158, userId: userDemo.id