Skip to content

Commit

Permalink
fix(core): Implement Refund lines fields resolver
Browse files Browse the repository at this point in the history
Fixes #2406
  • Loading branch information
michaelbromley committed Sep 27, 2023
1 parent 4539de3 commit 6b4da6c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/core/src/api/resolvers/entity/refund-entity.resolver.ts
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 ?? [];
}
}

0 comments on commit 6b4da6c

Please sign in to comment.