customer.service.ts 1.0 KB

12345678910111213141516171819202122232425262728
  1. import { Injectable } from '@nestjs/common';
  2. import { InjectConnection } from '@nestjs/typeorm';
  3. import { Connection } from 'typeorm';
  4. import { AddressEntity } from '../../entity/address/address.entity';
  5. import { Address } from '../../entity/address/address.interface';
  6. import { CustomerEntity } from '../../entity/customer/customer.entity';
  7. import { Customer } from '../../entity/customer/customer.interface';
  8. @Injectable()
  9. export class CustomerService {
  10. constructor(@InjectConnection() private connection: Connection) {}
  11. findAll(): Promise<Customer[]> {
  12. return this.connection.manager.find(CustomerEntity);
  13. }
  14. findOne(userId: number): Promise<Customer> {
  15. return this.connection.manager.findOne(CustomerEntity, userId);
  16. }
  17. findAddressesByCustomerId(customerId: number): Promise<Address[]> {
  18. return this.connection
  19. .getRepository(AddressEntity)
  20. .createQueryBuilder('address')
  21. .where('address.customerId = :id', { id: customerId })
  22. .getMany();
  23. }
  24. }