Feature/improve date validation in activity endpoints (#3489)
* Improve date validation * Update changelog
This commit is contained in:
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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 ?? []),
|
||||
|
@ -157,7 +157,12 @@
|
||||
<div class="mb-3">
|
||||
<mat-form-field appearance="outline" class="w-100">
|
||||
<mat-label i18n>Date</mat-label>
|
||||
<input formControlName="date" matInput [matDatepicker]="date" />
|
||||
<input
|
||||
formControlName="date"
|
||||
matInput
|
||||
[matDatepicker]="date"
|
||||
[matDatepickerFilter]="dateFilter"
|
||||
/>
|
||||
<mat-datepicker-toggle class="mr-2" matSuffix [for]="date">
|
||||
<ion-icon
|
||||
class="text-muted"
|
||||
|
Reference in New Issue
Block a user