【发布时间】:2020-06-02 20:46:25
【问题描述】:
让我们简化 TypeORM 实体User:
@Entity()
export class User extends BaseDatabaseEntity {
@Column({
length: 255,
})
public firstName!: string;
@Column({ length: 60 })
@Exclude()
public password: string;
@BeforeUpdate()
@BeforeInsert()
private hashPassword(): void {
const tmpPassword = hashSync(
this.password + 'config.auth.password.secret',
genSaltSync(),
);
this.password = tmpPassword;
}
}
}
我需要用 NestJS 的配置(来自 ConfigService 的命名空间)替换 config.auth.password.secret:
export default registerAs('app', () => {
return {
password: {
secret: process.env.AUTH_PASSWORD_SECRET,
}
};
});
,但实体不是 NestJS 结构的一部分,所以我不能像往常一样注入它。
如何在 TypeORM 实体中实现 NestJS 配置?
【问题讨论】:
标签: typescript nestjs typeorm nestjs-config