From 6b4da6c5c918d5e4c523278c392ef54000ed98bd Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Wed, 27 Sep 2023 09:25:05 +0200 Subject: [PATCH] fix(core): Implement Refund lines fields resolver Fixes #2406 --- .../resolvers/entity/refund-entity.resolver.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/core/src/api/resolvers/entity/refund-entity.resolver.ts b/packages/core/src/api/resolvers/entity/refund-entity.resolver.ts index 79654787f3..53414e5301 100644 --- a/packages/core/src/api/resolvers/entity/refund-entity.resolver.ts +++ b/packages/core/src/api/resolvers/entity/refund-entity.resolver.ts @@ -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 ?? []; + } }