How could a repository provider be injected in a plain entity class in NestJS?
In the following code, this.customerRepository is not injected by NestJS, is undefined.
export class UserAggregateEntity {
@Inject()
public customerRepository: CustomerRepository;
private customer: CustomerEntity;
constructor(private user: UserEntity) {}
async createCustomer(customer: CustomerEntity): Promise<string> {
customer.user = this.root.id;
// here error Cannot read property 'create' of undefined
const savedCustomer = await this.customerRepository.create(customer);
this.customer = savedCustomer;
return customer.id;
}
}
UserAggregateEntity class is called by something like...
const userAggregate = new UserAggregateEntity(user);
await userAggregate.createCustomer(customer);
CustomerRepository cannot be instantiated in the createCustomer method because it has to be injected with a DAO and other providers.
CustomerRepository is @Injectable(), defined as provider in the module, and used elsewhere successfully.
Thanks