dynamic-entities-plugin.ts 882 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // product-review.entity.ts
  2. import { DeepPartial } from '@vendure/common/lib/shared-types';
  3. import { VendureEntity, VendurePlugin } from '@vendure/core';
  4. import { Column, Entity } from 'typeorm';
  5. @Entity()
  6. export class TestEntityA extends VendureEntity {
  7. constructor(input?: DeepPartial<TestEntityA>) {
  8. super(input);
  9. }
  10. @Column()
  11. textA: string;
  12. }
  13. @Entity()
  14. export class TestEntityB extends VendureEntity {
  15. constructor(input?: DeepPartial<TestEntityA>) {
  16. super(input);
  17. }
  18. @Column()
  19. textB: string;
  20. }
  21. @VendurePlugin({
  22. entities: () => {
  23. return DynamicEntitiesPlugin.useEntity === 'A' ? [TestEntityA] : [TestEntityB];
  24. },
  25. })
  26. export class DynamicEntitiesPlugin {
  27. static useEntity: 'A' | 'B';
  28. static init(options: { useEntity: 'A' | 'B' }) {
  29. this.useEntity = options.useEntity;
  30. return this;
  31. }
  32. }