customer.entity.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Column, Entity, JoinColumn, JoinTable, ManyToMany, OneToMany, OneToOne } from 'typeorm';
  2. import { DeepPartial } from '../../../../shared/shared-types';
  3. import { HasCustomFields } from '../../../../shared/shared-types';
  4. import { SoftDeletable } from '../../common/types/common-types';
  5. import { Address } from '../address/address.entity';
  6. import { VendureEntity } from '../base/base.entity';
  7. import { CustomCustomerFields } from '../custom-entity-fields';
  8. import { CustomerGroup } from '../customer-group/customer-group.entity';
  9. import { Order } from '../order/order.entity';
  10. import { User } from '../user/user.entity';
  11. /**
  12. * @description
  13. * This entity represents a customer of the store, typically an individual person. A Customer can be
  14. * a guest, in which case it has no associated {@link User}. Customers with registered account will
  15. * have an associated User entity.
  16. *
  17. * @docsCategory entities
  18. */
  19. @Entity()
  20. export class Customer extends VendureEntity implements HasCustomFields, SoftDeletable {
  21. constructor(input?: DeepPartial<Customer>) {
  22. super(input);
  23. }
  24. @Column({ type: Date, nullable: true, default: null })
  25. deletedAt: Date | null;
  26. @Column({ nullable: true })
  27. title: string;
  28. @Column() firstName: string;
  29. @Column() lastName: string;
  30. @Column({ nullable: true })
  31. phoneNumber: string;
  32. @Column({ unique: true })
  33. emailAddress: string;
  34. @ManyToMany(type => CustomerGroup)
  35. @JoinTable()
  36. groups: CustomerGroup[];
  37. @OneToMany(type => Address, address => address.customer)
  38. addresses: Address[];
  39. @OneToMany(type => Order, order => order.customer)
  40. orders: Order[];
  41. @OneToOne(type => User, { eager: true })
  42. @JoinColumn()
  43. user?: User;
  44. @Column(type => CustomCustomerFields)
  45. customFields: CustomCustomerFields;
  46. }