diff --git a/CHANGELOG.md b/CHANGELOG.md index ddd17a698..a1db2164f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Improved the date validation in the create, import and update activities endpoints - Improved the language localization for German (`de`) ## 2.88.0 - 2024-06-11 diff --git a/apps/api/src/app/order/create-order.dto.ts b/apps/api/src/app/order/create-order.dto.ts index 6d36f036a..72aba3a3b 100644 --- a/apps/api/src/app/order/create-order.dto.ts +++ b/apps/api/src/app/order/create-order.dto.ts @@ -1,3 +1,5 @@ +import { IsAfter1970Constraint } from '@ghostfolio/common/validator-constraints/is-after-1970'; + import { AssetClass, AssetSubClass, @@ -15,7 +17,8 @@ import { IsNumber, IsOptional, IsString, - Min + Min, + Validate } from 'class-validator'; import { isString } from 'lodash'; @@ -51,6 +54,7 @@ export class CreateOrderDto { dataSource?: DataSource; @IsISO8601() + @Validate(IsAfter1970Constraint) date: string; @IsNumber() diff --git a/apps/api/src/app/order/update-order.dto.ts b/apps/api/src/app/order/update-order.dto.ts index be3c2b6e5..2fd33b743 100644 --- a/apps/api/src/app/order/update-order.dto.ts +++ b/apps/api/src/app/order/update-order.dto.ts @@ -1,3 +1,5 @@ +import { IsAfter1970Constraint } from '@ghostfolio/common/validator-constraints/is-after-1970'; + import { AssetClass, AssetSubClass, @@ -14,7 +16,8 @@ import { IsNumber, IsOptional, IsString, - Min + Min, + Validate } from 'class-validator'; import { isString } from 'lodash'; @@ -49,6 +52,7 @@ export class UpdateOrderDto { dataSource: DataSource; @IsISO8601() + @Validate(IsAfter1970Constraint) date: string; @IsNumber() diff --git a/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts b/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts index 9d3bcc6c9..8ebf936a2 100644 --- a/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts +++ b/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts @@ -21,7 +21,7 @@ import { DateAdapter, MAT_DATE_LOCALE } from '@angular/material/core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { AssetClass, AssetSubClass, Tag, Type } from '@prisma/client'; import { isUUID } from 'class-validator'; -import { isToday } from 'date-fns'; +import { isAfter, isToday } from 'date-fns'; import { EMPTY, Observable, Subject, lastValueFrom, of } from 'rxjs'; import { catchError, delay, map, startWith, takeUntil } from 'rxjs/operators'; @@ -426,6 +426,14 @@ export class CreateOrUpdateActivityDialog implements OnDestroy { }); } + public dateFilter(aDate: Date) { + if (!aDate) { + return true; + } + + return isAfter(aDate, new Date(0)); + } + public onAddTag(event: MatAutocompleteSelectedEvent) { this.activityForm.get('tags').setValue([ ...(this.activityForm.get('tags').value ?? []), diff --git a/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.html b/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.html index f57d63559..a3b960d82 100644 --- a/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.html +++ b/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.html @@ -157,7 +157,12 @@
Date - +