10.0.1 • Published 2 months ago

@hodfords/nestjs-transaction v10.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 months ago

nestjs-transaction

Description

Nest transaction help you easily work with transaction more than ever!

Installation 🤖

npm install @hodfords/nestjs-transaction --save-dev

Usage ⚡

You need to extend the TransactionService imported from library in your Service first and then call your service with this withTransaction method in the callback of transaction you are using.

Code demo:

// your-service.service.ts
@Injectable()
export class YourService extends TransactionService {
    public constructor(
        @InjectRepository(YourRepository) private repository: Repository<Entity>,
        private yourCustomRepository: CustomRepository,
        private yourService: Service,
        // Let's say you don't want to rebuild this service in the transaction
        private yourCacheService: CacheService,
        @Inject(forwardRef(() => ForwardService)) private yourForwardService: ForwardService
    ) {
        super();
    }

    async theMethodWillUseTransaction(payload: SomePayload) {
        // logic code here
    }
}
// your-controller.controller.ts
@Controller()
export class SomeController {
    constructor(
        private readonly yourService: YourService,
        private connection: Connection
    ) {}

    async method(payload: SomePayload): Promise<SomeResponse> {
        return this.connection.transaction(async (entityManager) => {
            return await this.yourService
                .withTransaction(entityManager, { excluded: [CacheService] })
                .theMethodWillUseTransaction(payload);
        });
    }
}
10.0.1

2 months ago

10.0.0

2 months ago

8.0.0

4 months ago

1.0.10

8 months ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago