Eliminate isDraft from schema

pull/187/head
Thomas 4 years ago
parent 50317bf3f2
commit d276567a18

@ -43,7 +43,6 @@ export class ExperimentalService {
date: parseISO(order.date),
fee: 0,
id: undefined,
isDraft: false,
platformId: undefined,
symbolProfileId: undefined,
type: Type.BUY,

@ -22,7 +22,7 @@ import {
import { REQUEST } from '@nestjs/core';
import { AuthGuard } from '@nestjs/passport';
import { Order as OrderModel } from '@prisma/client';
import { endOfToday, isAfter, parseISO } from 'date-fns';
import { parseISO } from 'date-fns';
import { StatusCodes, getReasonPhrase } from 'http-status-codes';
import { CreateOrderDto } from './create-order.dto';
@ -130,8 +130,6 @@ export class OrderController {
const accountId = data.accountId;
delete data.accountId;
const isDraft = isAfter(date, endOfToday());
return this.orderService.createOrder(
{
...data,
@ -141,7 +139,6 @@ export class OrderController {
}
},
date,
isDraft,
SymbolProfile: {
connectOrCreate: {
where: {
@ -196,14 +193,11 @@ export class OrderController {
const accountId = data.accountId;
delete data.accountId;
const isDraft = isAfter(date, endOfToday());
return this.orderService.updateOrder(
{
data: {
...data,
date,
isDraft,
Account: {
connect: {
id_userId: { id: accountId, userId: this.request.user.id }

@ -3,6 +3,7 @@ import { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { OrderWithAccount } from '@ghostfolio/common/types';
import { Injectable } from '@nestjs/common';
import { DataSource, Order, Prisma } from '@prisma/client';
import { endOfToday, isAfter } from 'date-fns';
import { CacheService } from '../cache/cache.service';
import { RedisCacheService } from '../redis-cache/redis-cache.service';
@ -50,8 +51,8 @@ export class OrderService {
): Promise<Order> {
this.redisCacheService.remove(`${aUserId}.portfolio`);
if (!data.isDraft) {
// Gather symbol data of order in the background
if (!isAfter(data.date as Date, endOfToday())) {
// Gather symbol data of order in the background, if not draft
this.dataGatheringService.gatherSymbols([
{
dataSource: data.dataSource,

@ -332,7 +332,7 @@ export class PortfolioService {
const historicalDataArray: HistoricalDataItem[] = [];
for (const [date, { marketPrice, performance }] of Object.entries(
for (const [date, { marketPrice }] of Object.entries(
historicalData[aSymbol]
).reverse()) {
historicalDataArray.push({

@ -1,4 +1,5 @@
import { Account, Currency, Platform, SymbolProfile } from '@prisma/client';
import { Account, Currency, SymbolProfile } from '@prisma/client';
import { endOfToday, isAfter, parseISO } from 'date-fns';
import { v4 as uuidv4 } from 'uuid';
import { IOrder } from '../services/interfaces/interfaces';
@ -10,7 +11,6 @@ export class Order {
private fee: number;
private date: string;
private id: string;
private isDraft: boolean;
private quantity: number;
private symbol: string;
private symbolProfile: SymbolProfile;
@ -24,7 +24,6 @@ export class Order {
this.fee = data.fee;
this.date = data.date;
this.id = data.id || uuidv4();
this.isDraft = data.isDraft ?? false;
this.quantity = data.quantity;
this.symbol = data.symbol;
this.symbolProfile = data.symbolProfile;
@ -55,7 +54,7 @@ export class Order {
}
public getIsDraft() {
return this.isDraft;
return isAfter(parseISO(this.date), endOfToday());
}
public getQuantity() {

@ -188,7 +188,6 @@ describe('Portfolio', () => {
fee: 0,
date: new Date(),
id: '8d999347-dee2-46ee-88e1-26b344e71fcc',
isDraft: false,
quantity: 1,
symbol: 'BTCUSD',
symbolProfileId: null,
@ -292,7 +291,6 @@ describe('Portfolio', () => {
fee: 0,
date: new Date(getUtc('2018-01-05')),
id: '4a5a5c6e-659d-45cc-9fd4-fd6c873b50fb',
isDraft: false,
quantity: 0.2,
symbol: 'ETHUSD',
symbolProfileId: null,
@ -390,7 +388,6 @@ describe('Portfolio', () => {
fee: 0,
date: new Date(getUtc('2018-01-05')),
id: '4a5a5c6e-659d-45cc-9fd4-fd6c873b50fb',
isDraft: false,
quantity: 0.2,
symbol: 'ETHUSD',
symbolProfileId: null,
@ -470,7 +467,6 @@ describe('Portfolio', () => {
date: new Date(getUtc('2017-08-16')),
fee: 2.99,
id: 'd96795b2-6ae6-420e-aa21-fabe5e45d475',
isDraft: false,
quantity: 0.05614682,
symbol: 'BTCUSD',
symbolProfileId: null,
@ -488,7 +484,6 @@ describe('Portfolio', () => {
fee: 2.99,
date: new Date(getUtc('2018-01-05')),
id: '4a5a5c6e-659d-45cc-9fd4-fd6c873b50fb',
isDraft: false,
quantity: 0.2,
symbol: 'ETHUSD',
symbolProfileId: null,
@ -563,7 +558,6 @@ describe('Portfolio', () => {
fee: 1.0,
date: new Date(getUtc('2018-01-05')),
id: '4a5a5c6e-659d-45cc-9fd4-fd6c873b50fb',
isDraft: false,
quantity: 0.2,
symbol: 'ETHUSD',
symbolProfileId: null,
@ -581,7 +575,6 @@ describe('Portfolio', () => {
fee: 1.0,
date: new Date(getUtc('2018-01-28')),
id: '4a5a5c6e-659d-45cc-9fd4-fd6c873b50fc',
isDraft: false,
quantity: 0.1,
symbol: 'ETHUSD',
symbolProfileId: null,
@ -599,7 +592,6 @@ describe('Portfolio', () => {
fee: 1.0,
date: new Date(getUtc('2018-01-31')),
id: '4a5a5c6e-659d-45cc-9fd4-fd6c873b50fc',
isDraft: false,
quantity: 0.2,
symbol: 'ETHUSD',
symbolProfileId: null,

@ -164,7 +164,6 @@ export class Portfolio implements PortfolioInterface {
fee,
date,
id,
isDraft,
quantity,
symbol,
symbolProfile,
@ -178,7 +177,6 @@ export class Portfolio implements PortfolioInterface {
fee,
date,
id,
isDraft,
quantity,
symbol,
symbolProfile,
@ -630,7 +628,6 @@ export class Portfolio implements PortfolioInterface {
currency: order.currency,
date: order.date.toISOString(),
fee: order.fee,
isDraft: order.isDraft,
quantity: order.quantity,
symbol: order.symbol,
symbolProfile: order.SymbolProfile,

@ -8,6 +8,7 @@ import { Injectable } from '@nestjs/common';
import { DataSource } from '@prisma/client';
import {
differenceInHours,
endOfToday,
format,
getDate,
getMonth,
@ -227,7 +228,9 @@ export class DataGatheringService {
orderBy: [{ symbol: 'asc' }],
select: { dataSource: true, symbol: true },
where: {
isDraft: false
date: {
lt: endOfToday() // no draft
}
}
});
@ -286,7 +289,9 @@ export class DataGatheringService {
orderBy: [{ date: 'asc' }],
select: { dataSource: true, date: true, symbol: true },
where: {
isDraft: false
date: {
lt: endOfToday() // no draft
}
}
});

@ -22,7 +22,6 @@ export interface IOrder {
date: string;
fee: number;
id?: string;
isDraft: boolean;
quantity: number;
symbol: string;
symbolProfile: SymbolProfile;

@ -1,2 +0,0 @@
-- AlterTable
ALTER TABLE "Order" ADD COLUMN "isDraft" BOOLEAN NOT NULL DEFAULT false;

@ -79,7 +79,6 @@ model Order {
date DateTime
fee Float
id String @default(uuid())
isDraft Boolean @default(false)
quantity Float
symbol String
SymbolProfile SymbolProfile? @relation(fields: [symbolProfileId], references: [id])

Loading…
Cancel
Save