diff --git a/CHANGELOG.md b/CHANGELOG.md index 68dab494..51f2f4ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Supported the tags in the create or edit transaction dialog + ### Changed - Removed the alias from the user interface as a preparation to remove it from the `User` database schema diff --git a/apps/api/src/app/order/create-order.dto.ts b/apps/api/src/app/order/create-order.dto.ts index 3211fc4e..ab60248d 100644 --- a/apps/api/src/app/order/create-order.dto.ts +++ b/apps/api/src/app/order/create-order.dto.ts @@ -1,5 +1,12 @@ -import { AssetClass, AssetSubClass, DataSource, Type } from '@prisma/client'; import { + AssetClass, + AssetSubClass, + DataSource, + Tag, + Type +} from '@prisma/client'; +import { + IsArray, IsEnum, IsISO8601, IsNumber, @@ -39,6 +46,10 @@ export class CreateOrderDto { @IsString() symbol: string; + @IsArray() + @IsOptional() + tags?: Tag[]; + @IsEnum(Type, { each: true }) type: Type; diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.ts index 0be1523c..5c85c989 100644 --- a/apps/api/src/app/order/order.service.ts +++ b/apps/api/src/app/order/order.service.ts @@ -16,6 +16,7 @@ import { DataSource, Order, Prisma, + Tag, Type as TypeOfOrder } from '@prisma/client'; import Big from 'big.js'; @@ -71,6 +72,7 @@ export class OrderService { currency?: string; dataSource?: DataSource; symbol?: string; + tags?: Tag[]; userId: string; } ): Promise { @@ -80,6 +82,8 @@ export class OrderService { return account.isDefault === true; }); + const tags = data.tags ?? []; + let Account = { connect: { id_userId: { @@ -142,6 +146,7 @@ export class OrderService { delete data.currency; delete data.dataSource; delete data.symbol; + delete data.tags; delete data.userId; const orderData: Prisma.OrderCreateInput = data; @@ -150,7 +155,12 @@ export class OrderService { data: { ...orderData, Account, - isDraft + isDraft, + tags: { + connect: tags.map(({ id }) => { + return { id }; + }) + } } }); } @@ -298,6 +308,7 @@ export class OrderService { currency?: string; dataSource?: DataSource; symbol?: string; + tags?: Tag[]; }; where: Prisma.OrderWhereUniqueInput; }): Promise { @@ -305,6 +316,8 @@ export class OrderService { delete data.Account; } + const tags = data.tags ?? []; + let isDraft = false; if (data.type === 'ITEM') { @@ -331,11 +344,17 @@ export class OrderService { delete data.currency; delete data.dataSource; delete data.symbol; + delete data.tags; return this.prismaService.order.update({ data: { ...data, - isDraft + isDraft, + tags: { + connect: tags.map(({ id }) => { + return { id }; + }) + } }, where }); diff --git a/apps/api/src/app/order/update-order.dto.ts b/apps/api/src/app/order/update-order.dto.ts index 0ad46180..5f79c63b 100644 --- a/apps/api/src/app/order/update-order.dto.ts +++ b/apps/api/src/app/order/update-order.dto.ts @@ -1,5 +1,12 @@ -import { AssetClass, AssetSubClass, DataSource, Type } from '@prisma/client'; import { + AssetClass, + AssetSubClass, + DataSource, + Tag, + Type +} from '@prisma/client'; +import { + IsArray, IsEnum, IsISO8601, IsNumber, @@ -41,6 +48,10 @@ export class UpdateOrderDto { @IsString() symbol: string; + @IsArray() + @IsOptional() + tags?: Tag[]; + @IsString() type: Type; diff --git a/apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.component.ts b/apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.component.ts index 52fc2f36..f9b0b68c 100644 --- a/apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.component.ts +++ b/apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.component.ts @@ -255,6 +255,7 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy { isUUID(this.activityForm.controls['searchSymbol'].value.symbol) ? this.activityForm.controls['name'].value : this.activityForm.controls['searchSymbol'].value.symbol, + tags: this.activityForm.controls['tags'].value, type: this.activityForm.controls['type'].value, unitPrice: this.activityForm.controls['unitPrice'].value };