admin管理员组文章数量:1406926
When adding a sequelize-typescript's decorator to the model field, which should check that the field is not empty, validation does not work and allows you to create a record without passing this field. DB is Postgres
Create function in client.repository.ts:
async create(values) {
return this.model.create(values, {
validate: true,
...options,
});
}
Client model:
import {
Table,
Column,
Model,
DataType,
PrimaryKey,
ForeignKey,
BelongsTo,
HasMany,
Unique,
IsEmail,
Length,
NotEmpty,
} from 'sequelize-typescript';
import { nanoid } from 'nanoid';
import { Company } from './company.model';
import { Invoice } from './invoice.model';
@Table
export class Client extends Model {
@PrimaryKey
@Column({
type: DataType.STRING,
defaultValue: nanoid,
})
id!: string;
@Unique
@NotEmpty
@IsEmail
@Column
email!: string;
@NotEmpty
@Length({ min: 3, max: 30 })
@Column
firstName!: string;
@NotEmpty
@Length({ min: 3, max: 30 })
@Column
lastName!: string;
@ForeignKey(() => Company)
@NotEmpty
@Column({
type: DataType.STRING,
})
companyId!: string;
@BelongsTo(() => Company)
company!: Company;
@HasMany(() => Invoice)
invoices?: Invoice[];
}
Why walidation doesn't work? P.S. If I send the firstName (for example) with a string length from 1 to 2 units, then the @Length({min: 3, max:30 }) validation works and an error is received.
本文标签: sequelizejssequelizetypescript validationStack Overflow
版权声明:本文标题:sequelize.js - sequelize-typescript validation - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744979751a2635742.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论