odavid / typeorm-transactional-cls-hooked

A Transactional Method Decorator for typeorm that uses cls-hooked to handle and propagate transactions between different repositories and service methods. Inpired by Spring Trasnactional Annotation and Sequelize CLS
MIT License
522 stars 86 forks source link

EntityManager is Undefined #88

Open sgentile opened 3 years ago

sgentile commented 3 years ago

I setup per the documentation, but when this is called entitymanager is undefined:

save<T extends DeepPartial<Entity>>(entityOrEntities: T|T[], options?: SaveOptions): Promise<T|T[]> {
        return this.manager.save<T>(this.metadata.target as any, entityOrEntities as any, options);
    }

my index:

initializeTransactionalContext();
serve();

my respository:

@EntityRepository(User)
export class UserRepository extends BaseRepository<User> {}

my service injecting it

export class UserService {
    constructor(
        private readonly userRepository: UserRepository
    ) {}

lastly the call to save

return await this.userRepository.save(user);