|
|
@ -1,7 +1,17 @@ |
|
|
import { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms'; |
|
|
import { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms'; |
|
|
import { FormGroup } from '@angular/forms'; |
|
|
import { FormGroup } from '@angular/forms'; |
|
|
import { plainToInstance } from 'class-transformer'; |
|
|
import { plainToInstance } from 'class-transformer'; |
|
|
import { validate } from 'class-validator'; |
|
|
import { isJSON, validate } from 'class-validator'; |
|
|
|
|
|
|
|
|
|
|
|
export function jsonValidator(): ValidatorFn { |
|
|
|
|
|
return (control: AbstractControl): ValidationErrors | null => { |
|
|
|
|
|
if (!isJSON(control.value)) { |
|
|
|
|
|
return { invalidJson: true }; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
export async function validateObjectForForm<T>({ |
|
|
export async function validateObjectForForm<T>({ |
|
|
classDto, |
|
|
classDto, |
|
|
@ -45,17 +55,3 @@ export async function validateObjectForForm<T>({ |
|
|
|
|
|
|
|
|
return Promise.reject(nonIgnoredErrors); |
|
|
return Promise.reject(nonIgnoredErrors); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export function jsonValidator(): ValidatorFn { |
|
|
|
|
|
return (control: AbstractControl): ValidationErrors | null => { |
|
|
|
|
|
if (!control.value) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
JSON.parse(control.value); |
|
|
|
|
|
} catch { |
|
|
|
|
|
return { invalidJson: true }; |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|