11import { inject , singleton } from "@undb/di"
22import { None , Some , type Option } from "@undb/domain"
33import { type IWebhookRepository , type WebhookDo , type WebhookSpecification } from "@undb/webhook"
4+ import { getCurrentTransaction } from "../ctx"
45import type { IQueryBuilder } from "../qb"
56import { injectQueryBuilder } from "../qb.provider"
67import { WebhookFilterVisitor } from "./webhook.filter-visitor"
@@ -17,7 +18,7 @@ export class WebhookRepository implements IWebhookRepository {
1718 ) { }
1819
1920 async findOneById ( id : string ) : Promise < Option < WebhookDo > > {
20- const wb = await this . qb
21+ const wb = await ( getCurrentTransaction ( ) ?? this . qb )
2122 . selectFrom ( "undb_webhook" )
2223 . selectAll ( )
2324 . where ( ( eb ) => eb . eb ( "id" , "=" , id ) )
@@ -31,7 +32,7 @@ export class WebhookRepository implements IWebhookRepository {
3132 }
3233
3334 async find ( spec : WebhookSpecification ) : Promise < WebhookDo [ ] > {
34- const wb = await this . qb
35+ const wb = await ( getCurrentTransaction ( ) ?? this . qb )
3536 . selectFrom ( "undb_webhook" )
3637 . selectAll ( )
3738 . where ( ( eb ) => {
@@ -47,14 +48,14 @@ export class WebhookRepository implements IWebhookRepository {
4748 async insert ( webhook : WebhookDo ) : Promise < void > {
4849 const values = this . mapper . toEntity ( webhook )
4950
50- await this . qb . insertInto ( "undb_webhook" ) . values ( values ) . execute ( )
51+ await ( getCurrentTransaction ( ) ?? this . qb ) . insertInto ( "undb_webhook" ) . values ( values ) . execute ( )
5152 }
5253
5354 async updateOneById ( webhook : WebhookDo , spec : WebhookSpecification ) : Promise < void > {
5455 const visitor = new WebhookMutationVisitor ( )
5556 spec . accept ( visitor )
5657
57- await this . qb
58+ await ( getCurrentTransaction ( ) ?? this . qb )
5859 . updateTable ( "undb_webhook" )
5960 . set ( visitor . data )
6061 . where ( ( eb ) => eb . eb ( "id" , "=" , webhook . id . value ) )
0 commit comments