Browse Source
			
			
			Feature/add comment to activity (#1097)
			
				* Add comment to activity
* Update changelog
			
			
				pull/1098/head
			
			
		 
		
			
				
					
						 Thomas Kaul
					
					3 years ago
						Thomas Kaul
					
					3 years ago
					
						
							committed by
							
								 GitHub
								GitHub
							
						 
					
				 
				
			 
		 
		
			
				
					
					No known key found for this signature in database
					
						
							GPG Key ID: 4AEE18F83AFDEB23
						
					
				
			
		
		
		
	
		
			
				 12 changed files with 
77 additions and 
5 deletions
			 
			
		 
		
			
				- 
					
					
					 
					CHANGELOG.md
				
- 
					
					
					 
					apps/api/src/app/export/export.service.ts
				
- 
					
					
					 
					apps/api/src/app/import/import.service.ts
				
- 
					
					
					 
					apps/api/src/app/order/create-order.dto.ts
				
- 
					
					
					 
					apps/api/src/app/order/order.service.ts
				
- 
					
					
					 
					apps/api/src/app/order/update-order.dto.ts
				
- 
					
					
					 
					apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.component.ts
				
- 
					
					
					 
					apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.html
				
- 
					
					
					 
					libs/ui/src/lib/activities-table/activities-table.component.html
				
- 
					
					
					 
					libs/ui/src/lib/activities-table/activities-table.component.ts
				
- 
					
					
					 
					prisma/migrations/20220725155238_added_comment_to_order/migration.sql
				
- 
					
					
					 
					prisma/schema.prisma
				
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -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/), | 
			
		
	
		
			
				
					|  |  |  | 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 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | ### Fixed | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -18,6 +18,7 @@ export class ExportService { | 
			
		
	
		
			
				
					|  |  |  |       orderBy: { date: 'desc' }, | 
			
		
	
		
			
				
					|  |  |  |       select: { | 
			
		
	
		
			
				
					|  |  |  |         accountId: true, | 
			
		
	
		
			
				
					|  |  |  |         comment: true, | 
			
		
	
		
			
				
					|  |  |  |         date: true, | 
			
		
	
		
			
				
					|  |  |  |         fee: true, | 
			
		
	
		
			
				
					|  |  |  |         id: true, | 
			
		
	
	
		
			
				
					|  |  | @ -40,6 +41,7 @@ export class ExportService { | 
			
		
	
		
			
				
					|  |  |  |       activities: activities.map( | 
			
		
	
		
			
				
					|  |  |  |         ({ | 
			
		
	
		
			
				
					|  |  |  |           accountId, | 
			
		
	
		
			
				
					|  |  |  |           comment, | 
			
		
	
		
			
				
					|  |  |  |           date, | 
			
		
	
		
			
				
					|  |  |  |           fee, | 
			
		
	
		
			
				
					|  |  |  |           id, | 
			
		
	
	
		
			
				
					|  |  | @ -50,6 +52,7 @@ export class ExportService { | 
			
		
	
		
			
				
					|  |  |  |         }) => { | 
			
		
	
		
			
				
					|  |  |  |           return { | 
			
		
	
		
			
				
					|  |  |  |             accountId, | 
			
		
	
		
			
				
					|  |  |  |             comment, | 
			
		
	
		
			
				
					|  |  |  |             fee, | 
			
		
	
		
			
				
					|  |  |  |             id, | 
			
		
	
		
			
				
					|  |  |  |             quantity, | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -48,6 +48,7 @@ export class ImportService { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     for (const { | 
			
		
	
		
			
				
					|  |  |  |       accountId, | 
			
		
	
		
			
				
					|  |  |  |       comment, | 
			
		
	
		
			
				
					|  |  |  |       currency, | 
			
		
	
		
			
				
					|  |  |  |       dataSource, | 
			
		
	
		
			
				
					|  |  |  |       date, | 
			
		
	
	
		
			
				
					|  |  | @ -58,6 +59,7 @@ export class ImportService { | 
			
		
	
		
			
				
					|  |  |  |       unitPrice | 
			
		
	
		
			
				
					|  |  |  |     } of activities) { | 
			
		
	
		
			
				
					|  |  |  |       await this.orderService.createOrder({ | 
			
		
	
		
			
				
					|  |  |  |         comment, | 
			
		
	
		
			
				
					|  |  |  |         fee, | 
			
		
	
		
			
				
					|  |  |  |         quantity, | 
			
		
	
		
			
				
					|  |  |  |         type, | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -5,6 +5,7 @@ import { | 
			
		
	
		
			
				
					|  |  |  |   Tag, | 
			
		
	
		
			
				
					|  |  |  |   Type | 
			
		
	
		
			
				
					|  |  |  | } from '@prisma/client'; | 
			
		
	
		
			
				
					|  |  |  | import { Transform, TransformFnParams } from 'class-transformer'; | 
			
		
	
		
			
				
					|  |  |  | import { | 
			
		
	
		
			
				
					|  |  |  |   IsArray, | 
			
		
	
		
			
				
					|  |  |  |   IsEnum, | 
			
		
	
	
		
			
				
					|  |  | @ -13,25 +14,33 @@ import { | 
			
		
	
		
			
				
					|  |  |  |   IsOptional, | 
			
		
	
		
			
				
					|  |  |  |   IsString | 
			
		
	
		
			
				
					|  |  |  | } from 'class-validator'; | 
			
		
	
		
			
				
					|  |  |  | import { isString } from 'lodash'; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | export class CreateOrderDto { | 
			
		
	
		
			
				
					|  |  |  |   @IsString() | 
			
		
	
		
			
				
					|  |  |  |   @IsOptional() | 
			
		
	
		
			
				
					|  |  |  |   @IsString() | 
			
		
	
		
			
				
					|  |  |  |   accountId?: string; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |   @IsEnum(AssetClass, { each: true }) | 
			
		
	
		
			
				
					|  |  |  |   @IsOptional() | 
			
		
	
		
			
				
					|  |  |  |   @IsEnum(AssetClass, { each: true }) | 
			
		
	
		
			
				
					|  |  |  |   assetClass?: AssetClass; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |   @IsEnum(AssetSubClass, { each: true }) | 
			
		
	
		
			
				
					|  |  |  |   @IsOptional() | 
			
		
	
		
			
				
					|  |  |  |   @IsEnum(AssetSubClass, { each: true }) | 
			
		
	
		
			
				
					|  |  |  |   assetSubClass?: AssetSubClass; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |   @IsOptional() | 
			
		
	
		
			
				
					|  |  |  |   @IsString() | 
			
		
	
		
			
				
					|  |  |  |   @Transform(({ value }: TransformFnParams) => | 
			
		
	
		
			
				
					|  |  |  |     isString(value) ? value.trim() : value | 
			
		
	
		
			
				
					|  |  |  |   ) | 
			
		
	
		
			
				
					|  |  |  |   comment?: string; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |   @IsString() | 
			
		
	
		
			
				
					|  |  |  |   currency: string; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |   @IsEnum(DataSource, { each: true }) | 
			
		
	
		
			
				
					|  |  |  |   @IsOptional() | 
			
		
	
		
			
				
					|  |  |  |   @IsEnum(DataSource, { each: true }) | 
			
		
	
		
			
				
					|  |  |  |   dataSource?: DataSource; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |   @IsISO8601() | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -21,7 +21,7 @@ import { | 
			
		
	
		
			
				
					|  |  |  | } from '@prisma/client'; | 
			
		
	
		
			
				
					|  |  |  | import Big from 'big.js'; | 
			
		
	
		
			
				
					|  |  |  | import { endOfToday, isAfter } from 'date-fns'; | 
			
		
	
		
			
				
					|  |  |  | import { groupBy } from 'lodash'; | 
			
		
	
		
			
				
					|  |  |  | import { groupBy, isString } from 'lodash'; | 
			
		
	
		
			
				
					|  |  |  | import { v4 as uuidv4 } from 'uuid'; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import { Activity } from './interfaces/activities.interface'; | 
			
		
	
	
		
			
				
					|  |  | @ -143,6 +143,11 @@ export class OrderService { | 
			
		
	
		
			
				
					|  |  |  |     delete data.accountId; | 
			
		
	
		
			
				
					|  |  |  |     delete data.assetClass; | 
			
		
	
		
			
				
					|  |  |  |     delete data.assetSubClass; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     if (!data.comment) { | 
			
		
	
		
			
				
					|  |  |  |       delete data.comment; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     delete data.currency; | 
			
		
	
		
			
				
					|  |  |  |     delete data.dataSource; | 
			
		
	
		
			
				
					|  |  |  |     delete data.symbol; | 
			
		
	
	
		
			
				
					|  |  | @ -316,6 +321,10 @@ export class OrderService { | 
			
		
	
		
			
				
					|  |  |  |       delete data.Account; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     if (!data.comment) { | 
			
		
	
		
			
				
					|  |  |  |       data.comment = null; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     const tags = data.tags ?? []; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     let isDraft = false; | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -5,6 +5,7 @@ import { | 
			
		
	
		
			
				
					|  |  |  |   Tag, | 
			
		
	
		
			
				
					|  |  |  |   Type | 
			
		
	
		
			
				
					|  |  |  | } from '@prisma/client'; | 
			
		
	
		
			
				
					|  |  |  | import { Transform, TransformFnParams } from 'class-transformer'; | 
			
		
	
		
			
				
					|  |  |  | import { | 
			
		
	
		
			
				
					|  |  |  |   IsArray, | 
			
		
	
		
			
				
					|  |  |  |   IsEnum, | 
			
		
	
	
		
			
				
					|  |  | @ -13,6 +14,7 @@ import { | 
			
		
	
		
			
				
					|  |  |  |   IsOptional, | 
			
		
	
		
			
				
					|  |  |  |   IsString | 
			
		
	
		
			
				
					|  |  |  | } from 'class-validator'; | 
			
		
	
		
			
				
					|  |  |  | import { isString } from 'lodash'; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | export class UpdateOrderDto { | 
			
		
	
		
			
				
					|  |  |  |   @IsOptional() | 
			
		
	
	
		
			
				
					|  |  | @ -27,6 +29,13 @@ export class UpdateOrderDto { | 
			
		
	
		
			
				
					|  |  |  |   @IsOptional() | 
			
		
	
		
			
				
					|  |  |  |   assetSubClass?: AssetSubClass; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |   @IsOptional() | 
			
		
	
		
			
				
					|  |  |  |   @IsString() | 
			
		
	
		
			
				
					|  |  |  |   @Transform(({ value }: TransformFnParams) => | 
			
		
	
		
			
				
					|  |  |  |     isString(value) ? value.trim() : value | 
			
		
	
		
			
				
					|  |  |  |   ) | 
			
		
	
		
			
				
					|  |  |  |   comment?: string; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |   @IsString() | 
			
		
	
		
			
				
					|  |  |  |   currency: string; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -76,6 +76,7 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy { | 
			
		
	
		
			
				
					|  |  |  |       accountId: [this.data.activity?.accountId, Validators.required], | 
			
		
	
		
			
				
					|  |  |  |       assetClass: [this.data.activity?.SymbolProfile?.assetClass], | 
			
		
	
		
			
				
					|  |  |  |       assetSubClass: [this.data.activity?.SymbolProfile?.assetSubClass], | 
			
		
	
		
			
				
					|  |  |  |       comment: [this.data.activity?.comment], | 
			
		
	
		
			
				
					|  |  |  |       currency: [ | 
			
		
	
		
			
				
					|  |  |  |         this.data.activity?.SymbolProfile?.currency, | 
			
		
	
		
			
				
					|  |  |  |         Validators.required | 
			
		
	
	
		
			
				
					|  |  | @ -245,6 +246,7 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy { | 
			
		
	
		
			
				
					|  |  |  |       accountId: this.activityForm.controls['accountId'].value, | 
			
		
	
		
			
				
					|  |  |  |       assetClass: this.activityForm.controls['assetClass'].value, | 
			
		
	
		
			
				
					|  |  |  |       assetSubClass: this.activityForm.controls['assetSubClass'].value, | 
			
		
	
		
			
				
					|  |  |  |       comment: this.activityForm.controls['comment'].value, | 
			
		
	
		
			
				
					|  |  |  |       currency: this.activityForm.controls['currency'].value, | 
			
		
	
		
			
				
					|  |  |  |       date: this.activityForm.controls['date'].value, | 
			
		
	
		
			
				
					|  |  |  |       dataSource: this.activityForm.controls['dataSource'].value, | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -135,6 +135,18 @@ | 
			
		
	
		
			
				
					|  |  |  |         > | 
			
		
	
		
			
				
					|  |  |  |       </mat-form-field> | 
			
		
	
		
			
				
					|  |  |  |     </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 | 
			
		
	
		
			
				
					|  |  |  |       [ngClass]="{ 'd-none': activityForm.controls['type']?.value !== 'ITEM' }" | 
			
		
	
		
			
				
					|  |  |  |     > | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -347,6 +347,15 @@ | 
			
		
	
		
			
				
					|  |  |  |         </mat-menu> | 
			
		
	
		
			
				
					|  |  |  |       </th> | 
			
		
	
		
			
				
					|  |  |  |       <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 | 
			
		
	
		
			
				
					|  |  |  |           *ngIf="this.showActions" | 
			
		
	
		
			
				
					|  |  |  |           class="mx-1 no-min-width px-2" | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -171,6 +171,10 @@ export class ActivitiesTableComponent implements OnChanges, OnDestroy { | 
			
		
	
		
			
				
					|  |  |  |     this.import.emit(); | 
			
		
	
		
			
				
					|  |  |  |   } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |   public onOpenComment(aComment: string) { | 
			
		
	
		
			
				
					|  |  |  |     alert(aComment); | 
			
		
	
		
			
				
					|  |  |  |   } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |   public onOpenPositionDialog({ dataSource, symbol }: UniqueAsset): void { | 
			
		
	
		
			
				
					|  |  |  |     this.router.navigate([], { | 
			
		
	
		
			
				
					|  |  |  |       queryParams: { dataSource, symbol, positionDetailDialog: true } | 
			
		
	
	
		
			
				
					|  |  | 
 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -0,0 +1,2 @@ | 
			
		
	
		
			
				
					|  |  |  | -- AlterTable | 
			
		
	
		
			
				
					|  |  |  | ALTER TABLE "Order" ADD COLUMN "comment" TEXT; | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
			
				
					|  |  | @ -71,6 +71,7 @@ model Order { | 
			
		
	
		
			
				
					|  |  |  |   Account         Account?      @relation(fields: [accountId, accountUserId], references: [id, userId]) | 
			
		
	
		
			
				
					|  |  |  |   accountId       String? | 
			
		
	
		
			
				
					|  |  |  |   accountUserId   String? | 
			
		
	
		
			
				
					|  |  |  |   comment         String? | 
			
		
	
		
			
				
					|  |  |  |   createdAt       DateTime      @default(now()) | 
			
		
	
		
			
				
					|  |  |  |   date            DateTime | 
			
		
	
		
			
				
					|  |  |  |   fee             Float | 
			
		
	
	
		
			
				
					|  |  | 
 |