order-entity.resolver.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import { Parent, ResolveProperty, Resolver } from '@nestjs/graphql';
  2. import { Order } from '../../../entity/order/order.entity';
  3. import { OrderService } from '../../../service/services/order.service';
  4. import { ShippingMethodService } from '../../../service/services/shipping-method.service';
  5. import { IdCodecService } from '../../common/id-codec.service';
  6. @Resolver('Order')
  7. export class OrderEntityResolver {
  8. constructor(
  9. private orderService: OrderService,
  10. private shippingMethodService: ShippingMethodService,
  11. private idCodecService: IdCodecService,
  12. ) {}
  13. @ResolveProperty()
  14. async payments(@Parent() order: Order) {
  15. const orderId = this.idCodecService.decode(order.id);
  16. return this.orderService.getOrderPayments(orderId);
  17. }
  18. @ResolveProperty()
  19. async shippingMethod(@Parent() order: Order) {
  20. if (order.shippingMethodId) {
  21. // Does not need to be decoded because it is an internal property
  22. // which is never exposed to the outside world.
  23. const shippingMethodId = order.shippingMethodId;
  24. return this.shippingMethodService.findOne(shippingMethodId);
  25. } else {
  26. return null;
  27. }
  28. }
  29. }