Browse Source

Refactor data model

pull/666/head
Thomas 3 years ago
parent
commit
dac1b01995
  1. 31
      apps/api/src/app/order/order.service.ts
  2. 6
      libs/ui/src/lib/activities-table/activities-table.component.ts

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

@ -8,6 +8,7 @@ import { Injectable } from '@nestjs/common';
import { DataSource, Order, Prisma, Type as TypeOfOrder } from '@prisma/client';
import Big from 'big.js';
import { endOfToday, isAfter } from 'date-fns';
import { v4 as uuidv4 } from 'uuid';
import { Activity } from './interfaces/activities.interface';
@ -67,24 +68,39 @@ export class OrderService {
}
};
const isDraft = isAfter(data.date as Date, endOfToday());
if (data.type === 'ITEM') {
const currency = data.currency;
const id = uuidv4();
const name = data.SymbolProfile.connectOrCreate.create.symbol;
data.id = id;
data.symbol = null;
data.SymbolProfile.connectOrCreate.create.currency = currency;
data.SymbolProfile.connectOrCreate.create.name = name;
data.SymbolProfile.connectOrCreate.create.symbol = id;
} else {
data.SymbolProfile.connectOrCreate.create.symbol =
data.SymbolProfile.connectOrCreate.create.symbol.toUpperCase();
}
// Convert the symbol to uppercase to avoid case-sensitive duplicates
const symbol = data.symbol.toUpperCase();
const isDraft = isAfter(data.date as Date, endOfToday());
if (!isDraft) {
// Gather symbol data of order in the background, if not draft
this.dataGatheringService.gatherSymbols([
{
symbol,
dataSource: data.dataSource,
date: <Date>data.date
date: <Date>data.date,
symbol: data.SymbolProfile.connectOrCreate.create.symbol
}
]);
}
this.dataGatheringService.gatherProfileData([
{ symbol, dataSource: data.dataSource }
{
dataSource: data.dataSource,
symbol: data.SymbolProfile.connectOrCreate.create.symbol
}
]);
await this.cacheService.flush();
@ -98,8 +114,7 @@ export class OrderService {
data: {
...orderData,
Account,
isDraft,
symbol
isDraft
}
});
}

6
libs/ui/src/lib/activities-table/activities-table.component.ts

@ -271,11 +271,11 @@ export class ActivitiesTableComponent implements OnChanges, OnDestroy {
activity: OrderWithAccount,
fieldValues: Set<string> = new Set<string>()
): string[] {
fieldValues.add(activity.currency);
fieldValues.add(activity.symbol);
fieldValues.add(activity.type);
fieldValues.add(activity.Account?.name);
fieldValues.add(activity.Account?.Platform?.name);
fieldValues.add(activity.SymbolProfile.currency);
fieldValues.add(activity.SymbolProfile.symbol);
fieldValues.add(activity.type);
fieldValues.add(format(activity.date, 'yyyy'));
return [...fieldValues].filter((item) => {

Loading…
Cancel
Save