product-review.entity.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { Customer, DeepPartial, LocaleString, Product, ProductVariant, Translatable, Translation, VendureEntity } from '@vendure/core';
  2. import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
  3. import { ReviewState } from '../types';
  4. import { ProductReviewTranslation } from './product-review-translation.entity';
  5. @Entity()
  6. export class ProductReview extends VendureEntity implements Translatable {
  7. constructor(input?: DeepPartial<ProductReview>) {
  8. super(input);
  9. }
  10. @ManyToOne(type => Product)
  11. product: Product;
  12. text: LocaleString;
  13. @ManyToOne(type => ProductVariant)
  14. productVariant: ProductVariant | null;
  15. @Column()
  16. summary: string;
  17. @Column('text')
  18. body: string;
  19. @Column()
  20. rating: number;
  21. @ManyToOne(type => Customer)
  22. author: Customer;
  23. @Column()
  24. authorName: string;
  25. @Column({ nullable: true })
  26. authorLocation: string;
  27. @Column({ default: 0 })
  28. upvotes: number;
  29. @Column({ default: 0 })
  30. downvotes: number;
  31. @Column('varchar')
  32. state: ReviewState;
  33. @Column('text', { nullable: true, default: null })
  34. response: string;
  35. @Column({ nullable: true, default: null })
  36. responseCreatedAt: Date;
  37. @OneToMany(() => ProductReviewTranslation, translation => translation.base, { eager: true })
  38. translations: Array<Translation<ProductReview>>;
  39. }