Browse Source

refactor: dto, variable names & order

pull/1940/head
visrut 2 years ago
parent
commit
3b15c67cbc
  1. 27
      apps/api/src/app/import/import.service.ts
  2. 53
      apps/api/src/app/order/create-order.dto.ts
  3. 15
      libs/ui/src/lib/activities-table/activities-table.component.html

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

@ -2,7 +2,7 @@ import { AccountService } from '@ghostfolio/api/app/account/account.service';
import { CreateAccountDto } from '@ghostfolio/api/app/account/create-account.dto';
import {
CreateOrderDto,
OrderDto
OrderResponseDto
} from '@ghostfolio/api/app/order/create-order.dto';
import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface';
import { OrderService } from '@ghostfolio/api/app/order/order.service';
@ -87,6 +87,7 @@ export class ImportService {
feeInBaseCurrency: 0,
id: assetProfile.id,
isDraft: false,
isDuplicate: false, // TODO: Use evaluated state
SymbolProfile: <SymbolProfile>(<unknown>assetProfile),
symbolProfileId: assetProfile.id,
type: 'DIVIDEND',
@ -97,8 +98,7 @@ export class ImportService {
value,
assetProfile.currency,
userCurrency
),
isDuplicate: false
)
};
});
} catch {
@ -208,7 +208,7 @@ export class ImportService {
userId
});
const activitiesDtoWithDuplication = await this.labelDuplicateActivities({
const activitiesDtoWithDuplication = await this.markActivitiesAsDuplicates({
activitiesDto,
userId
});
@ -234,11 +234,11 @@ export class ImportService {
dataSource,
date: dateString,
fee,
isDuplicate,
quantity,
symbol,
type,
unitPrice,
isDuplicate
unitPrice
} of activitiesDtoWithDuplication) {
const date = parseISO(<string>(<unknown>dateString));
const validatedAccount = accounts.find(({ id }) => {
@ -326,6 +326,7 @@ export class ImportService {
//@ts-ignore
activities.push({
...order,
isDuplicate,
value,
feeInBaseCurrency: this.exchangeRateDataService.toCurrency(
fee,
@ -336,28 +337,26 @@ export class ImportService {
value,
currency,
userCurrency
),
isDuplicate
)
});
}
console.log(activities);
return activities;
}
private async labelDuplicateActivities({
private async markActivitiesAsDuplicates({
activitiesDto,
userId
}: {
activitiesDto: Partial<CreateOrderDto>[];
userId: string;
}): Promise<Partial<OrderDto>[]> {
}): Promise<Partial<OrderResponseDto>[]> {
const existingActivities = await this.orderService.orders({
include: { SymbolProfile: true },
orderBy: { date: 'desc' },
where: { userId }
});
const activitiesDtoWithDuplication: Partial<OrderDto>[] = [];
const activitiesDtoWithDuplication: Partial<OrderResponseDto>[] = [];
for (const activitiesDtoEntry of activitiesDto) {
const {
@ -371,7 +370,7 @@ export class ImportService {
unitPrice
} = activitiesDtoEntry;
const duplicateActivity = existingActivities.find((activity) => {
const isDuplicate = existingActivities.find((activity) => {
return (
activity.SymbolProfile.currency === currency &&
activity.SymbolProfile.dataSource === dataSource &&
@ -384,7 +383,7 @@ export class ImportService {
);
});
if (duplicateActivity) {
if (isDuplicate) {
activitiesDtoWithDuplication.push({
...activitiesDtoEntry,
isDuplicate: true

53
apps/api/src/app/order/create-order.dto.ts

@ -8,7 +8,6 @@ import {
import { Transform, TransformFnParams } from 'class-transformer';
import {
IsArray,
IsBoolean,
IsEnum,
IsISO8601,
IsNumber,
@ -16,7 +15,6 @@ import {
IsString
} from 'class-validator';
import { isString } from 'lodash';
import { CreateAccessDto } from '../access/create-access.dto';
export class CreateOrderDto {
@IsOptional()
@ -68,55 +66,6 @@ export class CreateOrderDto {
unitPrice: number;
}
export class OrderDto {
@IsOptional()
@IsString()
accountId?: string;
@IsOptional()
@IsEnum(AssetClass, { each: true })
assetClass?: AssetClass;
@IsOptional()
@IsEnum(AssetSubClass, { each: true })
assetSubClass?: AssetSubClass;
@IsOptional()
@IsString()
@Transform(({ value }: TransformFnParams) =>
isString(value) ? value.trim() : value
)
comment?: string;
@IsString()
currency: string;
@IsOptional()
@IsEnum(DataSource, { each: true })
dataSource?: DataSource;
@IsISO8601()
date: string;
@IsNumber()
fee: number;
@IsNumber()
quantity: number;
@IsString()
symbol: string;
@IsArray()
@IsOptional()
tags?: Tag[];
@IsEnum(Type, { each: true })
type: Type;
@IsNumber()
unitPrice: number;
@IsBoolean()
export class OrderResponseDto extends CreateOrderDto {
isDuplicate: boolean;
}

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

@ -85,22 +85,15 @@
</th>
<td *matCellDef="let element" class="px-1" mat-cell>
<mat-checkbox
*ngIf="!element.isDuplicate"
class="mt-2"
color="primary"
[checked]="selectedRows.isSelected(element)"
[checked]="
element.isDuplicate ? false : selectedRows.isSelected(element)
"
[disabled]="element.isDuplicate"
(change)="$event ? selectedRows.toggle(element) : null"
(click)="$event.stopPropagation()"
></mat-checkbox>
<mat-checkbox
*ngIf="element.isDuplicate"
class="mt-2"
color="primary"
[checked]="false"
[disabled]="true"
(change)="(null)"
(click)="(null)"
></mat-checkbox>
</td>
<td *matFooterCellDef class="px-1" mat-footer-cell></td>
</ng-container>

Loading…
Cancel
Save