Nestjs 包含TypeForm中方法的实体的种子数据库
我正在使用typeorm和nestjs 我有一个实体,看起来像这样,但有额外的属性:Nestjs 包含TypeForm中方法的实体的种子数据库,nestjs,typeorm,Nestjs,Typeorm,我正在使用typeorm和nestjs 我有一个实体,看起来像这样,但有额外的属性: export class User extends BaseEntity { @ApiModelProperty({ uniqueItems: true, example: 'myuser', description: 'User login' }) @Column({ unique: true }) login: string; @ApiModelProperty({ example:
export class User extends BaseEntity {
@ApiModelProperty({ uniqueItems: true, example: 'myuser', description: 'User login' })
@Column({ unique: true })
login: string;
@ApiModelProperty({ example: 'MyUser', description: 'User first name' })
@Column()
firstName: string;
@ApiModelProperty({ example: 'myuser', description: 'User password' })
@Column()
password: string;
@BeforeInsert()
private async hashPassword() {
this.password = bcrypt.hashSync(this.password, 10);
}
}
我通过创建模拟对象为数据库设定种子,例如:
user1: User = {
login: 'system',
password: 'system',
firstName: 'System',
lastName: 'System',
email: 'system@localhost.it',
imageUrl: '',
activated: true,
langKey: 'en',
createdBy: 'system',
lastModifiedBy: 'system',
phone: '0565659562',
verifiedPhone: false,
referal: '',
referedBy: '',
miniBio: ''
};
&获取此错误:
src/domain/user.entity.ts:49:17
49 private async hashPassword() {
~~~~~~~~~~~~
'hashPassword' is declared here.
src/migrations/1570200490072-SeedUsersRoles.ts:64:3 - error TS2741: Property 'hashPassword' is missing in type '{ login: string; password: string; firstName: string; lastName: string; email: string; imageUrl: string; activated: true; langKey: string; createdBy: string; lastModifiedBy: string; phone: string; verifiedPhone: false; referal: string; referedBy: string; miniBio: string; }' but required in type 'User'.
在对象构造中是否有装饰器装饰方法并忽略它们?尝试在模拟负载之后添加
作为用户。您介意共享迁移代码吗?