Browse Source

docs(core): Fix example for `TransactionalConnection.withTransaction()`

Michael Bromley 3 years ago
parent
commit
82d3339496
1 changed files with 5 additions and 5 deletions
  1. 5 5
      packages/core/src/connection/transactional-connection.ts

+ 5 - 5
packages/core/src/connection/transactional-connection.ts

@@ -113,18 +113,18 @@ export class TransactionalConnection {
      * @example
      * ```TypeScript
      * private async transferCredit(outerCtx: RequestContext, fromId: ID, toId: ID, amount: number) {
-     *   await this.connection.withTransaction(outerCtx, ctx => {
-     *     await this.giftCardService.updateCustomerCredit(fromId, -amount);
-     *
-     *     // Note you must not use outerCtx here, instead use ctx. Otherwise this query
+     *   await this.connection.withTransaction(outerCtx, async ctx => {
+     *     // Note you must not use `outerCtx` here, instead use `ctx`. Otherwise, this query
      *     // will be executed outside of transaction
+     *     await this.giftCardService.updateCustomerCredit(ctx, fromId, -amount);
+     *
      *     await this.connection.getRepository(ctx, GiftCard).update(fromId, { transferred: true })
      *
      *     // If some intermediate logic here throws an Error,
      *     // then all DB transactions will be rolled back and neither Customer's
      *     // credit balance will have changed.
      *
-     *     await this.giftCardService.updateCustomerCredit(toId, amount);
+     *     await this.giftCardService.updateCustomerCredit(ctx, toId, amount);
      *   })
      * }
      * ```