customer.resolver.ts 812 B

123456789101112131415161718192021222324
  1. import { Query, ResolveProperty, Resolver } from '@nestjs/graphql';
  2. import { Address } from '../../entity/address/address.entity';
  3. import { Customer } from '../../entity/customer/customer.entity';
  4. import { CustomerService } from '../../service/customer.service';
  5. @Resolver('Customer')
  6. export class CustomerResolver {
  7. constructor(private customerService: CustomerService) {}
  8. @Query('customers')
  9. customers(): Promise<Customer[]> {
  10. return this.customerService.findAll();
  11. }
  12. @Query('customer')
  13. customer(obj, args): Promise<Customer | undefined> {
  14. return this.customerService.findOne(args.id);
  15. }
  16. @ResolveProperty('addresses')
  17. addresses(customer: Customer): Promise<Address[]> {
  18. return this.customerService.findAddressesByCustomerId(customer.id);
  19. }
  20. }