|
|
@@ -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 ?? [];
|
|
|
+ }
|
|
|
}
|