-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Implement Refund lines fields resolver
Fixes #2406
- Loading branch information
1 parent
4539de3
commit 6b4da6c
Showing
1 changed file
with
15 additions
and
3 deletions.
There are no files selected for viewing
18 changes: 15 additions & 3 deletions
18
packages/core/src/api/resolvers/entity/refund-entity.resolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
import { Resolver } from '@nestjs/graphql'; | ||
import { Parent, ResolveField, Resolver } from '@nestjs/graphql'; | ||
|
||
import { idsAreEqual } from '../../../common/index'; | ||
import { Refund } from '../../../entity/refund/refund.entity'; | ||
import { OrderService } from '../../../service/services/order.service'; | ||
import { PaymentService } from '../../../service/index'; | ||
import { RequestContext } from '../../common/request-context'; | ||
import { Ctx } from '../../decorators/request-context.decorator'; | ||
|
||
@Resolver('Refund') | ||
export class RefundEntityResolver { | ||
constructor(private orderService: OrderService) {} | ||
constructor(private paymentService: PaymentService) {} | ||
|
||
@ResolveField() | ||
async lines(@Ctx() ctx: RequestContext, @Parent() refund: Refund) { | ||
if (refund.lines) { | ||
return refund.lines; | ||
} | ||
const payment = await this.paymentService.findOneOrThrow(ctx, refund.paymentId, ['refunds.lines']); | ||
return payment.refunds.find(r => idsAreEqual(r.id, refund.id))?.lines ?? []; | ||
} | ||
} |