Browse Source

Feature/add comment to activity (#1097)

* Add comment to activity

* Update changelog
pull/1098/head
Thomas Kaul 3 years ago
committed by GitHub
parent
commit
81217b35ef
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      CHANGELOG.md
  2. 3
      apps/api/src/app/export/export.service.ts
  3. 2
      apps/api/src/app/import/import.service.ts
  4. 17
      apps/api/src/app/order/create-order.dto.ts
  5. 11
      apps/api/src/app/order/order.service.ts
  6. 9
      apps/api/src/app/order/update-order.dto.ts
  7. 2
      apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.component.ts
  8. 12
      apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.html
  9. 9
      libs/ui/src/lib/activities-table/activities-table.component.html
  10. 4
      libs/ui/src/lib/activities-table/activities-table.component.ts
  11. 2
      prisma/migrations/20220725155238_added_comment_to_order/migration.sql
  12. 1
      prisma/schema.prisma

10
CHANGELOG.md

@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Added
- Support a note for activities
### Todo
- Apply data migration (`yarn database:migrate`)
## 1.173.0 - 23.07.2022 ## 1.173.0 - 23.07.2022
### Fixed ### Fixed

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

@ -18,6 +18,7 @@ export class ExportService {
orderBy: { date: 'desc' }, orderBy: { date: 'desc' },
select: { select: {
accountId: true, accountId: true,
comment: true,
date: true, date: true,
fee: true, fee: true,
id: true, id: true,
@ -40,6 +41,7 @@ export class ExportService {
activities: activities.map( activities: activities.map(
({ ({
accountId, accountId,
comment,
date, date,
fee, fee,
id, id,
@ -50,6 +52,7 @@ export class ExportService {
}) => { }) => {
return { return {
accountId, accountId,
comment,
fee, fee,
id, id,
quantity, quantity,

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

@ -48,6 +48,7 @@ export class ImportService {
for (const { for (const {
accountId, accountId,
comment,
currency, currency,
dataSource, dataSource,
date, date,
@ -58,6 +59,7 @@ export class ImportService {
unitPrice unitPrice
} of activities) { } of activities) {
await this.orderService.createOrder({ await this.orderService.createOrder({
comment,
fee, fee,
quantity, quantity,
type, type,

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

@ -5,6 +5,7 @@ import {
Tag, Tag,
Type Type
} from '@prisma/client'; } from '@prisma/client';
import { Transform, TransformFnParams } from 'class-transformer';
import { import {
IsArray, IsArray,
IsEnum, IsEnum,
@ -13,25 +14,33 @@ import {
IsOptional, IsOptional,
IsString IsString
} from 'class-validator'; } from 'class-validator';
import { isString } from 'lodash';
export class CreateOrderDto { export class CreateOrderDto {
@IsString()
@IsOptional() @IsOptional()
@IsString()
accountId?: string; accountId?: string;
@IsEnum(AssetClass, { each: true })
@IsOptional() @IsOptional()
@IsEnum(AssetClass, { each: true })
assetClass?: AssetClass; assetClass?: AssetClass;
@IsEnum(AssetSubClass, { each: true })
@IsOptional() @IsOptional()
@IsEnum(AssetSubClass, { each: true })
assetSubClass?: AssetSubClass; assetSubClass?: AssetSubClass;
@IsOptional()
@IsString()
@Transform(({ value }: TransformFnParams) =>
isString(value) ? value.trim() : value
)
comment?: string;
@IsString() @IsString()
currency: string; currency: string;
@IsEnum(DataSource, { each: true })
@IsOptional() @IsOptional()
@IsEnum(DataSource, { each: true })
dataSource?: DataSource; dataSource?: DataSource;
@IsISO8601() @IsISO8601()

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

@ -21,7 +21,7 @@ import {
} from '@prisma/client'; } from '@prisma/client';
import Big from 'big.js'; import Big from 'big.js';
import { endOfToday, isAfter } from 'date-fns'; import { endOfToday, isAfter } from 'date-fns';
import { groupBy } from 'lodash'; import { groupBy, isString } from 'lodash';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { Activity } from './interfaces/activities.interface'; import { Activity } from './interfaces/activities.interface';
@ -143,6 +143,11 @@ export class OrderService {
delete data.accountId; delete data.accountId;
delete data.assetClass; delete data.assetClass;
delete data.assetSubClass; delete data.assetSubClass;
if (!data.comment) {
delete data.comment;
}
delete data.currency; delete data.currency;
delete data.dataSource; delete data.dataSource;
delete data.symbol; delete data.symbol;
@ -316,6 +321,10 @@ export class OrderService {
delete data.Account; delete data.Account;
} }
if (!data.comment) {
data.comment = null;
}
const tags = data.tags ?? []; const tags = data.tags ?? [];
let isDraft = false; let isDraft = false;

9
apps/api/src/app/order/update-order.dto.ts

@ -5,6 +5,7 @@ import {
Tag, Tag,
Type Type
} from '@prisma/client'; } from '@prisma/client';
import { Transform, TransformFnParams } from 'class-transformer';
import { import {
IsArray, IsArray,
IsEnum, IsEnum,
@ -13,6 +14,7 @@ import {
IsOptional, IsOptional,
IsString IsString
} from 'class-validator'; } from 'class-validator';
import { isString } from 'lodash';
export class UpdateOrderDto { export class UpdateOrderDto {
@IsOptional() @IsOptional()
@ -27,6 +29,13 @@ export class UpdateOrderDto {
@IsOptional() @IsOptional()
assetSubClass?: AssetSubClass; assetSubClass?: AssetSubClass;
@IsOptional()
@IsString()
@Transform(({ value }: TransformFnParams) =>
isString(value) ? value.trim() : value
)
comment?: string;
@IsString() @IsString()
currency: string; currency: string;

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

@ -76,6 +76,7 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
accountId: [this.data.activity?.accountId, Validators.required], accountId: [this.data.activity?.accountId, Validators.required],
assetClass: [this.data.activity?.SymbolProfile?.assetClass], assetClass: [this.data.activity?.SymbolProfile?.assetClass],
assetSubClass: [this.data.activity?.SymbolProfile?.assetSubClass], assetSubClass: [this.data.activity?.SymbolProfile?.assetSubClass],
comment: [this.data.activity?.comment],
currency: [ currency: [
this.data.activity?.SymbolProfile?.currency, this.data.activity?.SymbolProfile?.currency,
Validators.required Validators.required
@ -245,6 +246,7 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
accountId: this.activityForm.controls['accountId'].value, accountId: this.activityForm.controls['accountId'].value,
assetClass: this.activityForm.controls['assetClass'].value, assetClass: this.activityForm.controls['assetClass'].value,
assetSubClass: this.activityForm.controls['assetSubClass'].value, assetSubClass: this.activityForm.controls['assetSubClass'].value,
comment: this.activityForm.controls['comment'].value,
currency: this.activityForm.controls['currency'].value, currency: this.activityForm.controls['currency'].value,
date: this.activityForm.controls['date'].value, date: this.activityForm.controls['date'].value,
dataSource: this.activityForm.controls['dataSource'].value, dataSource: this.activityForm.controls['dataSource'].value,

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

@ -135,6 +135,18 @@
> >
</mat-form-field> </mat-form-field>
</div> </div>
<div>
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Note</mat-label>
<textarea
cdkAutosizeMinRows="2"
cdkTextareaAutosize
formControlName="comment"
matInput
(keyup.enter)="$event.stopPropagation()"
></textarea>
</mat-form-field>
</div>
<div <div
[ngClass]="{ 'd-none': activityForm.controls['type']?.value !== 'ITEM' }" [ngClass]="{ 'd-none': activityForm.controls['type']?.value !== 'ITEM' }"
> >

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

@ -347,6 +347,15 @@
</mat-menu> </mat-menu>
</th> </th>
<td *matCellDef="let element" class="px-1 text-center" mat-cell> <td *matCellDef="let element" class="px-1 text-center" mat-cell>
<button
*ngIf="element.comment && !this.showActions"
class="mx-1 no-min-width px-2"
mat-button
title="Note"
(click)="onOpenComment(element.comment)"
>
<ion-icon name="document-text-outline"></ion-icon>
</button>
<button <button
*ngIf="this.showActions" *ngIf="this.showActions"
class="mx-1 no-min-width px-2" class="mx-1 no-min-width px-2"

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

@ -171,6 +171,10 @@ export class ActivitiesTableComponent implements OnChanges, OnDestroy {
this.import.emit(); this.import.emit();
} }
public onOpenComment(aComment: string) {
alert(aComment);
}
public onOpenPositionDialog({ dataSource, symbol }: UniqueAsset): void { public onOpenPositionDialog({ dataSource, symbol }: UniqueAsset): void {
this.router.navigate([], { this.router.navigate([], {
queryParams: { dataSource, symbol, positionDetailDialog: true } queryParams: { dataSource, symbol, positionDetailDialog: true }

2
prisma/migrations/20220725155238_added_comment_to_order/migration.sql

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Order" ADD COLUMN "comment" TEXT;

1
prisma/schema.prisma

@ -71,6 +71,7 @@ model Order {
Account Account? @relation(fields: [accountId, accountUserId], references: [id, userId]) Account Account? @relation(fields: [accountId, accountUserId], references: [id, userId])
accountId String? accountId String?
accountUserId String? accountUserId String?
comment String?
createdAt DateTime @default(now()) createdAt DateTime @default(now())
date DateTime date DateTime
fee Float fee Float

Loading…
Cancel
Save