вот так делал если че, все пишут, фиг пойми кто кому)))
await queryRunner.manager
.getRepository<ContentType>(ContentType)
.save(plainToClass(ContentType, { name: 'permission', title: 'Permission' }))
@Entity({ name: 'content_types' })
export class ContentType {
@PrimaryGeneratedColumn()
id: number = undefined;
@Column({ length: 100 })
@IsNotEmpty()
@MaxLength(100)
name: string = undefined;
@Column({ length: 255 })
@IsNotEmpty()
@MaxLength(255)
title: string = undefined;
@OneToMany(type => Permission, permission => permission.contentType)
permissions: Permission[];
@BeforeInsert()
doBeforeInsertion() {
const errors = validateSync(this, { validationError: { target: false } });
if (errors.length > 0) {
throw new CustomValidationError(errors);
}
}
@BeforeUpdate()
doBeforeUpdate() {
const errors = validateSync(this, { validationError: { target: false } });
if (errors.length > 0) {
throw new CustomValidationError(errors);
}
}
}
ну или вызывать после сериализации валидацию validateSync
короче на входе в функцию