Browse Source

Eliminate data source from order model

pull/730/head
Thomas 3 years ago
parent
commit
3d110915c2
  1. 1
      apps/api/src/app/import/import.service.ts
  2. 8
      apps/api/src/app/order/order.service.ts
  3. 8
      apps/api/src/interceptors/transform-data-source-in-response.interceptor.ts
  4. 12
      apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.component.ts
  5. 2
      libs/ui/src/lib/activities-table/activities-table.component.html
  6. 2
      prisma/migrations/20220302184222_removed_data_source_from_order/migration.sql
  7. 1
      prisma/schema.prisma
  8. 8
      prisma/seed.js

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

@ -53,7 +53,6 @@ export class ImportService {
} of orders) {
await this.orderService.createOrder({
currency,
dataSource,
fee,
quantity,
symbol,

8
apps/api/src/app/order/order.service.ts

@ -55,7 +55,7 @@ export class OrderService {
public async createOrder(
data: Prisma.OrderCreateInput & {
accountId?: string;
dataSource: DataSource;
dataSource?: DataSource;
userId: string;
}
): Promise<Order> {
@ -81,7 +81,6 @@ export class OrderService {
const name = data.SymbolProfile.connectOrCreate.create.symbol;
Account = undefined;
data.dataSource = dataSource;
data.id = id;
data.symbol = null;
data.SymbolProfile.connectOrCreate.create.currency = currency;
@ -99,7 +98,7 @@ export class OrderService {
await this.dataGatheringService.gatherProfileData([
{
dataSource: data.dataSource,
dataSource: data.SymbolProfile.connectOrCreate.create.dataSource,
symbol: data.SymbolProfile.connectOrCreate.create.symbol
}
]);
@ -110,7 +109,7 @@ export class OrderService {
// Gather symbol data of order in the background, if not draft
this.dataGatheringService.gatherSymbols([
{
dataSource: data.dataSource,
dataSource: data.SymbolProfile.connectOrCreate.create.dataSource,
date: <Date>data.date,
symbol: data.SymbolProfile.connectOrCreate.create.symbol
}
@ -120,6 +119,7 @@ export class OrderService {
await this.cacheService.flush();
delete data.accountId;
delete data.dataSource;
delete data.userId;
const orderData: Prisma.OrderCreateInput = data;

8
apps/api/src/interceptors/transform-data-source-in-response.interceptor.ts

@ -32,7 +32,6 @@ export class TransformDataSourceInResponseInterceptor<T>
activity.SymbolProfile.dataSource = encodeDataSource(
activity.SymbolProfile.dataSource
);
activity.dataSource = encodeDataSource(activity.dataSource);
return activity;
});
}
@ -66,13 +65,6 @@ export class TransformDataSourceInResponseInterceptor<T>
});
}
if (data.orders) {
data.orders.map((order) => {
order.dataSource = encodeDataSource(order.dataSource);
return order;
});
}
if (data.positions) {
data.positions.map((position) => {
position.dataSource = encodeDataSource(position.dataSource);

12
apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.component.ts

@ -161,8 +161,8 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
if (this.data.activity?.symbol) {
this.dataService
.fetchSymbolItem({
dataSource: this.data.activity?.dataSource,
symbol: this.data.activity?.symbol
dataSource: this.data.activity?.SymbolProfile?.dataSource,
symbol: this.data.activity?.SymbolProfile?.symbol
})
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe(({ marketPrice }) => {
@ -196,9 +196,7 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
} else {
this.activityForm.controls['searchSymbol'].setErrors({ incorrect: true });
this.data.activity.currency = null;
this.data.activity.dataSource = null;
this.data.activity.symbol = null;
this.data.activity.SymbolProfile = null;
}
this.changeDetectorRef.markForCheck();
@ -259,9 +257,7 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
})
.pipe(
catchError(() => {
this.data.activity.currency = null;
this.data.activity.dataSource = null;
this.data.activity.unitPrice = null;
this.data.activity.SymbolProfile = null;
this.isLoading = false;

2
libs/ui/src/lib/activities-table/activities-table.component.html

@ -362,7 +362,7 @@
!row.isDraft &&
row.type !== 'ITEM' &&
onOpenPositionDialog({
dataSource: row.dataSource,
dataSource: row.SymbolProfile.dataSource,
symbol: row.SymbolProfile.symbol
})
"

2
prisma/migrations/20220302184222_removed_data_source_from_order/migration.sql

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Order" DROP COLUMN "dataSource";

1
prisma/schema.prisma

@ -74,7 +74,6 @@ model Order {
accountId String?
accountUserId String?
createdAt DateTime @default(now())
currency String?
date DateTime
fee Float
id String @default(uuid())

8
prisma/seed.js

@ -193,7 +193,6 @@ async function main() {
accountId: '65cfb79d-b6c7-4591-9d46-73426bc62094',
accountUserId: userDemo.id,
currency: 'USD',
dataSource: DataSource.YAHOO,
date: new Date(Date.UTC(2017, 0, 3, 0, 0, 0)),
fee: 30,
id: 'cf7c0418-8535-4089-ae3d-5dbfa0aec2e1',
@ -208,7 +207,6 @@ async function main() {
accountId: 'd804de69-0429-42dc-b6ca-b308fd7dd926',
accountUserId: userDemo.id,
currency: 'USD',
dataSource: DataSource.YAHOO,
date: new Date(Date.UTC(2017, 7, 16, 0, 0, 0)),
fee: 29.9,
id: 'a1c5d73a-8631-44e5-ac44-356827a5212c',
@ -223,7 +221,6 @@ async function main() {
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
accountUserId: userDemo.id,
currency: 'USD',
dataSource: DataSource.YAHOO,
date: new Date(Date.UTC(2018, 9, 1, 0, 0, 0)),
fee: 80.79,
id: '71c08e2a-4a86-44ae-a890-c337de5d5f9b',
@ -238,7 +235,6 @@ async function main() {
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
accountUserId: userDemo.id,
currency: 'USD',
dataSource: DataSource.YAHOO,
date: new Date(Date.UTC(2019, 2, 1, 0, 0, 0)),
fee: 19.9,
id: '385f2c2c-d53e-4937-b0e5-e92ef6020d4e',
@ -253,7 +249,6 @@ async function main() {
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
accountUserId: userDemo.id,
currency: 'USD',
dataSource: DataSource.YAHOO,
date: new Date(Date.UTC(2019, 8, 3, 0, 0, 0)),
fee: 19.9,
id: '185f2c2c-d53e-4937-b0e5-a93ef6020d4e',
@ -268,7 +263,6 @@ async function main() {
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
accountUserId: userDemo.id,
currency: 'USD',
dataSource: DataSource.YAHOO,
date: new Date(Date.UTC(2020, 2, 2, 0, 0, 0)),
fee: 19.9,
id: '347b0430-a84f-4031-a0f9-390399066ad6',
@ -283,7 +277,6 @@ async function main() {
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
accountUserId: userDemo.id,
currency: 'USD',
dataSource: DataSource.YAHOO,
date: new Date(Date.UTC(2020, 8, 1, 0, 0, 0)),
fee: 19.9,
id: '67ec3f47-3189-4b63-ba05-60d3a06b302f',
@ -298,7 +291,6 @@ async function main() {
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
accountUserId: userDemo.id,
currency: 'USD',
dataSource: DataSource.YAHOO,
date: new Date(Date.UTC(2020, 2, 1, 0, 0, 0)),
fee: 19.9,
id: 'd01c6fbc-fa8d-47e6-8e80-66f882d2bfd2',

Loading…
Cancel
Save