Browse Source

Eliminate currency from order model

pull/730/head
Thomas 3 years ago
parent
commit
f3e562cb58
  1. 4
      apps/api/src/app/export/export.service.ts
  2. 4
      apps/api/src/app/import/import.service.ts
  3. 1
      apps/api/src/app/order/order.controller.ts
  4. 8
      apps/api/src/app/order/order.service.ts
  5. 18
      apps/api/src/app/portfolio/portfolio.service-new.ts
  6. 18
      apps/api/src/app/portfolio/portfolio.service.ts
  7. 1
      prisma/migrations/20220302191841_removed_currency_from_order/migration.sql
  8. 8
      prisma/seed.js

4
apps/api/src/app/export/export.service.ts

@ -18,7 +18,6 @@ export class ExportService {
orderBy: { date: 'desc' },
select: {
accountId: true,
currency: true,
date: true,
fee: true,
id: true,
@ -41,7 +40,6 @@ export class ExportService {
orders: orders.map(
({
accountId,
currency,
date,
fee,
quantity,
@ -51,12 +49,12 @@ export class ExportService {
}) => {
return {
accountId,
currency,
date,
fee,
quantity,
type,
unitPrice,
currency: SymbolProfile.currency,
dataSource: SymbolProfile.dataSource,
symbol: type === 'ITEM' ? SymbolProfile.name : SymbolProfile.symbol
};

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

@ -52,7 +52,6 @@ export class ImportService {
unitPrice
} of orders) {
await this.orderService.createOrder({
currency,
fee,
quantity,
symbol,
@ -64,6 +63,7 @@ export class ImportService {
SymbolProfile: {
connectOrCreate: {
create: {
currency,
dataSource,
symbol
},
@ -109,7 +109,7 @@ export class ImportService {
] of orders.entries()) {
const duplicateOrder = existingOrders.find((order) => {
return (
order.currency === currency &&
order.SymbolProfile.currency === currency &&
order.SymbolProfile.dataSource === dataSource &&
isSameDay(order.date, parseISO(<string>(<unknown>date))) &&
order.fee === fee &&

1
apps/api/src/app/order/order.controller.ts

@ -114,6 +114,7 @@ export class OrderController {
SymbolProfile: {
connectOrCreate: {
create: {
currency: data.currency,
dataSource: data.dataSource,
symbol: data.symbol
},

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

@ -55,6 +55,7 @@ export class OrderService {
public async createOrder(
data: Prisma.OrderCreateInput & {
accountId?: string;
currency?: string;
dataSource?: DataSource;
userId: string;
}
@ -75,7 +76,7 @@ export class OrderService {
};
if (data.type === 'ITEM') {
const currency = data.currency;
const currency = data.SymbolProfile.connectOrCreate.create.currency;
const dataSource: DataSource = 'MANUAL';
const id = uuidv4();
const name = data.SymbolProfile.connectOrCreate.create.symbol;
@ -119,6 +120,7 @@ export class OrderService {
await this.cacheService.flush();
delete data.accountId;
delete data.currency;
delete data.dataSource;
delete data.userId;
@ -197,12 +199,12 @@ export class OrderService {
value,
feeInBaseCurrency: this.exchangeRateDataService.toCurrency(
order.fee,
order.currency,
order.SymbolProfile.currency,
userCurrency
),
valueInBaseCurrency: this.exchangeRateDataService.toCurrency(
value,
order.currency,
order.SymbolProfile.currency,
userCurrency
)
};

18
apps/api/src/app/portfolio/portfolio.service-new.ts

@ -450,7 +450,7 @@ export class PortfolioServiceNew {
};
}
const positionCurrency = orders[0].currency;
const positionCurrency = orders[0].SymbolProfile.currency;
const [SymbolProfile] = await this.symbolProfileService.getSymbolProfiles([
aSymbol
]);
@ -460,7 +460,7 @@ export class PortfolioServiceNew {
return order.type === 'BUY' || order.type === 'SELL';
})
.map((order) => ({
currency: order.currency,
currency: order.SymbolProfile.currency,
dataSource: order.SymbolProfile.dataSource,
date: format(order.date, DATE_FORMAT),
fee: new Big(order.fee),
@ -1023,7 +1023,7 @@ export class PortfolioServiceNew {
.map((order) => {
return this.exchangeRateDataService.toCurrency(
new Big(order.quantity).mul(order.unitPrice).toNumber(),
order.currency,
order.SymbolProfile.currency,
this.request.user.Settings.currency
);
})
@ -1042,7 +1042,7 @@ export class PortfolioServiceNew {
.map((order) => {
return this.exchangeRateDataService.toCurrency(
order.fee,
order.currency,
order.SymbolProfile.currency,
this.request.user.Settings.currency
);
})
@ -1064,7 +1064,7 @@ export class PortfolioServiceNew {
.map((order) => {
return this.exchangeRateDataService.toCurrency(
new Big(order.quantity).mul(order.unitPrice).toNumber(),
order.currency,
order.SymbolProfile.currency,
this.request.user.Settings.currency
);
})
@ -1117,13 +1117,13 @@ export class PortfolioServiceNew {
}
const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({
currency: order.currency,
currency: order.SymbolProfile.currency,
dataSource: order.SymbolProfile.dataSource,
date: format(order.date, DATE_FORMAT),
fee: new Big(
this.exchangeRateDataService.toCurrency(
order.fee,
order.currency,
order.SymbolProfile.currency,
userCurrency
)
),
@ -1134,7 +1134,7 @@ export class PortfolioServiceNew {
unitPrice: new Big(
this.exchangeRateDataService.toCurrency(
order.unitPrice,
order.currency,
order.SymbolProfile.currency,
userCurrency
)
)
@ -1230,7 +1230,7 @@ export class PortfolioServiceNew {
.map((order) => {
return this.exchangeRateDataService.toCurrency(
order.quantity * order.unitPrice,
order.currency,
order.SymbolProfile.currency,
currency
);
})

18
apps/api/src/app/portfolio/portfolio.service.ts

@ -438,7 +438,7 @@ export class PortfolioService {
};
}
const positionCurrency = orders[0].currency;
const positionCurrency = orders[0].SymbolProfile.currency;
const [SymbolProfile] = await this.symbolProfileService.getSymbolProfiles([
aSymbol
]);
@ -448,7 +448,7 @@ export class PortfolioService {
return order.type === 'BUY' || order.type === 'SELL';
})
.map((order) => ({
currency: order.currency,
currency: order.SymbolProfile.currency,
dataSource: order.SymbolProfile.dataSource,
date: format(order.date, DATE_FORMAT),
fee: new Big(order.fee),
@ -987,7 +987,7 @@ export class PortfolioService {
.map((order) => {
return this.exchangeRateDataService.toCurrency(
new Big(order.quantity).mul(order.unitPrice).toNumber(),
order.currency,
order.SymbolProfile.currency,
this.request.user.Settings.currency
);
})
@ -1006,7 +1006,7 @@ export class PortfolioService {
.map((order) => {
return this.exchangeRateDataService.toCurrency(
order.fee,
order.currency,
order.SymbolProfile.currency,
this.request.user.Settings.currency
);
})
@ -1028,7 +1028,7 @@ export class PortfolioService {
.map((order) => {
return this.exchangeRateDataService.toCurrency(
new Big(order.quantity).mul(order.unitPrice).toNumber(),
order.currency,
order.SymbolProfile.currency,
this.request.user.Settings.currency
);
})
@ -1080,13 +1080,13 @@ export class PortfolioService {
}
const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({
currency: order.currency,
currency: order.SymbolProfile.currency,
dataSource: order.SymbolProfile.dataSource,
date: format(order.date, DATE_FORMAT),
fee: new Big(
this.exchangeRateDataService.toCurrency(
order.fee,
order.currency,
order.SymbolProfile.currency,
userCurrency
)
),
@ -1097,7 +1097,7 @@ export class PortfolioService {
unitPrice: new Big(
this.exchangeRateDataService.toCurrency(
order.unitPrice,
order.currency,
order.SymbolProfile.currency,
userCurrency
)
)
@ -1189,7 +1189,7 @@ export class PortfolioService {
.map((order) => {
return this.exchangeRateDataService.toCurrency(
order.quantity * order.unitPrice,
order.currency,
order.SymbolProfile.currency,
currency
);
})

1
prisma/migrations/20220302191841_removed_currency_from_order/migration.sql

@ -0,0 +1 @@
ALTER TABLE "Order" DROP COLUMN "currency";

8
prisma/seed.js

@ -192,7 +192,6 @@ async function main() {
{
accountId: '65cfb79d-b6c7-4591-9d46-73426bc62094',
accountUserId: userDemo.id,
currency: 'USD',
date: new Date(Date.UTC(2017, 0, 3, 0, 0, 0)),
fee: 30,
id: 'cf7c0418-8535-4089-ae3d-5dbfa0aec2e1',
@ -206,7 +205,6 @@ async function main() {
{
accountId: 'd804de69-0429-42dc-b6ca-b308fd7dd926',
accountUserId: userDemo.id,
currency: 'USD',
date: new Date(Date.UTC(2017, 7, 16, 0, 0, 0)),
fee: 29.9,
id: 'a1c5d73a-8631-44e5-ac44-356827a5212c',
@ -220,7 +218,6 @@ async function main() {
{
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
accountUserId: userDemo.id,
currency: 'USD',
date: new Date(Date.UTC(2018, 9, 1, 0, 0, 0)),
fee: 80.79,
id: '71c08e2a-4a86-44ae-a890-c337de5d5f9b',
@ -234,7 +231,6 @@ async function main() {
{
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
accountUserId: userDemo.id,
currency: 'USD',
date: new Date(Date.UTC(2019, 2, 1, 0, 0, 0)),
fee: 19.9,
id: '385f2c2c-d53e-4937-b0e5-e92ef6020d4e',
@ -248,7 +244,6 @@ async function main() {
{
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
accountUserId: userDemo.id,
currency: 'USD',
date: new Date(Date.UTC(2019, 8, 3, 0, 0, 0)),
fee: 19.9,
id: '185f2c2c-d53e-4937-b0e5-a93ef6020d4e',
@ -262,7 +257,6 @@ async function main() {
{
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
accountUserId: userDemo.id,
currency: 'USD',
date: new Date(Date.UTC(2020, 2, 2, 0, 0, 0)),
fee: 19.9,
id: '347b0430-a84f-4031-a0f9-390399066ad6',
@ -276,7 +270,6 @@ async function main() {
{
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
accountUserId: userDemo.id,
currency: 'USD',
date: new Date(Date.UTC(2020, 8, 1, 0, 0, 0)),
fee: 19.9,
id: '67ec3f47-3189-4b63-ba05-60d3a06b302f',
@ -290,7 +283,6 @@ async function main() {
{
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
accountUserId: userDemo.id,
currency: 'USD',
date: new Date(Date.UTC(2020, 2, 1, 0, 0, 0)),
fee: 19.9,
id: 'd01c6fbc-fa8d-47e6-8e80-66f882d2bfd2',

Loading…
Cancel
Save