diff --git a/packages/core/src/entity/channel/channel.entity.ts b/packages/core/src/entity/channel/channel.entity.ts index 1b39699bf9..6c1c2208b9 100644 --- a/packages/core/src/entity/channel/channel.entity.ts +++ b/packages/core/src/entity/channel/channel.entity.ts @@ -2,6 +2,7 @@ import { CurrencyCode, LanguageCode } from '@vendure/common/lib/generated-types' import { DeepPartial, ID } from '@vendure/common/lib/shared-types'; import { Column, Entity, Index, ManyToMany, ManyToOne } from 'typeorm'; +import { Customer, PaymentMethod, Promotion, Role, ShippingMethod, StockLocation } from '..'; import { VendureEntity } from '../base/base.entity'; import { Collection } from '../collection/collection.entity'; import { CustomChannelFields } from '../custom-entity-fields'; @@ -61,7 +62,7 @@ export class Channel extends VendureEntity { description: string; @Index() - @ManyToOne(type => Seller) + @ManyToOne(type => Seller, seller => seller.channels) seller?: Seller; @EntityId({ nullable: true }) @@ -73,11 +74,11 @@ export class Channel extends VendureEntity { availableLanguageCodes: LanguageCode[]; @Index() - @ManyToOne(type => Zone) + @ManyToOne(type => Zone, zone => zone.defaultTaxZoneChannels) defaultTaxZone: Zone; @Index() - @ManyToOne(type => Zone) + @ManyToOne(type => Zone, zone => zone.defaultShippingZoneChannels) defaultShippingZone: Zone; @Column('varchar') @@ -123,6 +124,24 @@ export class Channel extends VendureEntity { @ManyToMany(type => Collection, collection => collection.channels, { onDelete: 'CASCADE' }) collections: Collection[]; + @ManyToMany(type => Promotion, promotion => promotion.channels, { onDelete: 'CASCADE' }) + promotions: Promotion[]; + + @ManyToMany(type => PaymentMethod, paymentMethod => paymentMethod.channels, { onDelete: 'CASCADE' }) + paymentMethods: PaymentMethod[]; + + @ManyToMany(type => ShippingMethod, shippingMethod => shippingMethod.channels, { onDelete: 'CASCADE' }) + shippingMethods: ShippingMethod[]; + + @ManyToMany(type => Customer, customer => customer.channels, { onDelete: 'CASCADE' }) + customers: Customer[]; + + @ManyToMany(type => Role, role => role.channels, { onDelete: 'CASCADE' }) + roles: Role[]; + + @ManyToMany(type => StockLocation, stockLocation => stockLocation.channels, { onDelete: 'CASCADE' }) + stockLocations: StockLocation[]; + private generateToken(): string { const randomString = () => Math.random().toString(36).substr(3, 10); return `${randomString()}${randomString()}`; diff --git a/packages/core/src/entity/customer-group/customer-group.entity.ts b/packages/core/src/entity/customer-group/customer-group.entity.ts index 318ada7f11..c853b0f18e 100644 --- a/packages/core/src/entity/customer-group/customer-group.entity.ts +++ b/packages/core/src/entity/customer-group/customer-group.entity.ts @@ -1,10 +1,11 @@ import { DeepPartial } from '@vendure/common/lib/shared-types'; -import { Column, Entity, ManyToMany } from 'typeorm'; +import { Column, Entity, ManyToMany, OneToMany } from 'typeorm'; import { HasCustomFields } from '../../config/custom-field/custom-field-types'; import { VendureEntity } from '../base/base.entity'; import { CustomCustomerGroupFields } from '../custom-entity-fields'; import { Customer } from '../customer/customer.entity'; +import { TaxRate } from '../tax-rate/tax-rate.entity'; /** * @description @@ -26,4 +27,7 @@ export class CustomerGroup extends VendureEntity implements HasCustomFields { @Column(type => CustomCustomerGroupFields) customFields: CustomCustomerGroupFields; + + @OneToMany(type => TaxRate, taxRate => taxRate.zone) + taxRates: TaxRate[]; } diff --git a/packages/core/src/entity/customer/customer.entity.ts b/packages/core/src/entity/customer/customer.entity.ts index bf8f7c06eb..076fbd5fce 100644 --- a/packages/core/src/entity/customer/customer.entity.ts +++ b/packages/core/src/entity/customer/customer.entity.ts @@ -58,7 +58,7 @@ export class Customer extends VendureEntity implements ChannelAware, HasCustomFi @Column(type => CustomCustomerFields) customFields: CustomCustomerFields; - @ManyToMany(type => Channel) + @ManyToMany(type => Channel, channel => channel.customers) @JoinTable() channels: Channel[]; } diff --git a/packages/core/src/entity/facet/facet.entity.ts b/packages/core/src/entity/facet/facet.entity.ts index ef61652b89..ec6e3c5ab4 100644 --- a/packages/core/src/entity/facet/facet.entity.ts +++ b/packages/core/src/entity/facet/facet.entity.ts @@ -45,7 +45,7 @@ export class Facet extends VendureEntity implements Translatable, HasCustomField @Column(type => CustomFacetFields) customFields: CustomFacetFields; - @ManyToMany(type => Channel) + @ManyToMany(type => Channel, channel => channel.facets) @JoinTable() channels: Channel[]; } diff --git a/packages/core/src/entity/order-line-reference/order-line-reference.entity.ts b/packages/core/src/entity/order-line-reference/order-line-reference.entity.ts index ec5efa18e1..2a4cc96e8a 100644 --- a/packages/core/src/entity/order-line-reference/order-line-reference.entity.ts +++ b/packages/core/src/entity/order-line-reference/order-line-reference.entity.ts @@ -19,7 +19,7 @@ export abstract class OrderLineReference extends VendureEntity { quantity: number; @Index() - @ManyToOne(type => OrderLine, { onDelete: 'CASCADE' }) + @ManyToOne(type => OrderLine, line => line.linesReferences, { onDelete: 'CASCADE' }) orderLine: OrderLine; @EntityId() diff --git a/packages/core/src/entity/order-line/order-line.entity.ts b/packages/core/src/entity/order-line/order-line.entity.ts index 990d01e03b..a9c44fc229 100644 --- a/packages/core/src/entity/order-line/order-line.entity.ts +++ b/packages/core/src/entity/order-line/order-line.entity.ts @@ -1,7 +1,7 @@ import { Adjustment, AdjustmentType, Discount, TaxLine } from '@vendure/common/lib/generated-types'; import { DeepPartial, ID } from '@vendure/common/lib/shared-types'; import { summate } from '@vendure/common/lib/shared-utils'; -import { Column, Entity, Index, ManyToOne, OneToOne } from 'typeorm'; +import { Column, Entity, Index, ManyToOne, OneToMany, OneToOne } from 'typeorm'; import { Calculated } from '../../common/calculated-decorator'; import { roundMoney } from '../../common/round-money'; @@ -14,9 +14,12 @@ import { CustomOrderLineFields } from '../custom-entity-fields'; import { EntityId } from '../entity-id.decorator'; import { Money } from '../money.decorator'; import { Order } from '../order/order.entity'; +import { OrderLineReference } from '../order-line-reference/order-line-reference.entity'; import { ProductVariant } from '../product-variant/product-variant.entity'; import { ShippingLine } from '../shipping-line/shipping-line.entity'; +import { Allocation } from '../stock-movement/allocation.entity'; import { Cancellation } from '../stock-movement/cancellation.entity'; +import { Sale } from '../stock-movement/sale.entity'; import { TaxCategory } from '../tax-category/tax-category.entity'; /** @@ -49,7 +52,10 @@ export class OrderLine extends VendureEntity implements HasCustomFields { * This is determined by the configured {@link ShippingLineAssignmentStrategy}. */ @Index() - @ManyToOne(type => ShippingLine, { nullable: true, onDelete: 'SET NULL' }) + @ManyToOne(type => ShippingLine, shippingLine => shippingLine.orderLines, { + nullable: true, + onDelete: 'SET NULL', + }) shippingLine?: ShippingLine; @EntityId({ nullable: true }) @@ -60,7 +66,7 @@ export class OrderLine extends VendureEntity implements HasCustomFields { * The {@link ProductVariant} which is being ordered. */ @Index() - @ManyToOne(type => ProductVariant) + @ManyToOne(type => ProductVariant, productVariant => productVariant.lines, { onDelete: 'CASCADE' }) productVariant: ProductVariant; @EntityId() @@ -71,13 +77,19 @@ export class OrderLine extends VendureEntity implements HasCustomFields { taxCategory: TaxCategory; @Index() - @ManyToOne(type => Asset) + @ManyToOne(type => Asset, asset => asset.featuredInVariants, { onDelete: 'SET NULL' }) featuredAsset: Asset; @Index() @ManyToOne(type => Order, order => order.lines, { onDelete: 'CASCADE' }) order: Order; + @OneToMany(type => OrderLineReference, lineRef => lineRef.orderLine) + linesReferences: OrderLineReference[]; + + @OneToMany(type => Sale, sale => sale.orderLine) + sales: Sale[]; + @Column() quantity: number; @@ -118,8 +130,11 @@ export class OrderLine extends VendureEntity implements HasCustomFields { @Column('simple-json') taxLines: TaxLine[]; - @OneToOne(type => Cancellation, cancellation => cancellation.orderLine) - cancellation: Cancellation; + @OneToMany(type => Cancellation, cancellation => cancellation.orderLine) + cancellations: Cancellation[]; + + @OneToMany(type => Allocation, allocation => allocation.orderLine) + allocations: Allocation[]; @Column(type => CustomOrderLineFields) customFields: CustomOrderLineFields; diff --git a/packages/core/src/entity/payment-method/payment-method.entity.ts b/packages/core/src/entity/payment-method/payment-method.entity.ts index 62cabcc3cd..c1f8eb1bb6 100644 --- a/packages/core/src/entity/payment-method/payment-method.entity.ts +++ b/packages/core/src/entity/payment-method/payment-method.entity.ts @@ -39,7 +39,7 @@ export class PaymentMethod extends VendureEntity implements Translatable, Channe @Column('simple-json') handler: ConfigurableOperation; - @ManyToMany(type => Channel) + @ManyToMany(type => Channel, channel => channel.paymentMethods) @JoinTable() channels: Channel[]; diff --git a/packages/core/src/entity/product-variant/product-variant.entity.ts b/packages/core/src/entity/product-variant/product-variant.entity.ts index 370c422683..91226f07ff 100644 --- a/packages/core/src/entity/product-variant/product-variant.entity.ts +++ b/packages/core/src/entity/product-variant/product-variant.entity.ts @@ -14,6 +14,7 @@ import { Collection } from '../collection/collection.entity'; import { CustomProductVariantFields } from '../custom-entity-fields'; import { EntityId } from '../entity-id.decorator'; import { FacetValue } from '../facet-value/facet-value.entity'; +import { OrderLine } from '../order-line/order-line.entity'; import { Product } from '../product/product.entity'; import { ProductOption } from '../product-option/product-option.entity'; import { StockLevel } from '../stock-level/stock-level.entity'; @@ -170,4 +171,7 @@ export class ProductVariant @ManyToMany(type => Channel, channel => channel.productVariants) @JoinTable() channels: Channel[]; + + @OneToMany(type => OrderLine, orderLine => orderLine.productVariant) + lines: OrderLine[]; } diff --git a/packages/core/src/entity/product/product.entity.ts b/packages/core/src/entity/product/product.entity.ts index 6e06f2895f..82968bcdf9 100644 --- a/packages/core/src/entity/product/product.entity.ts +++ b/packages/core/src/entity/product/product.entity.ts @@ -63,7 +63,7 @@ export class Product @JoinTable() facetValues: FacetValue[]; - @ManyToMany(type => Channel) + @ManyToMany(type => Channel, channel => channel.products) @JoinTable() channels: Channel[]; diff --git a/packages/core/src/entity/promotion/promotion.entity.ts b/packages/core/src/entity/promotion/promotion.entity.ts index 7b3ef182f5..d7a44f2a8d 100644 --- a/packages/core/src/entity/promotion/promotion.entity.ts +++ b/packages/core/src/entity/promotion/promotion.entity.ts @@ -20,7 +20,6 @@ import { Channel } from '../channel/channel.entity'; import { CustomPromotionFields } from '../custom-entity-fields'; import { Order } from '../order/order.entity'; import { OrderLine } from '../order-line/order-line.entity'; -import { PaymentMethodTranslation } from '../payment-method/payment-method-translation.entity'; import { ShippingLine } from '../shipping-line/shipping-line.entity'; import { PromotionTranslation } from './promotion-translation.entity'; @@ -107,7 +106,7 @@ export class Promotion @Column() enabled: boolean; - @ManyToMany(type => Channel) + @ManyToMany(type => Channel, channel => channel.promotions) @JoinTable() channels: Channel[]; diff --git a/packages/core/src/entity/refund/refund.entity.ts b/packages/core/src/entity/refund/refund.entity.ts index db9fb80f25..fefa0b88ff 100644 --- a/packages/core/src/entity/refund/refund.entity.ts +++ b/packages/core/src/entity/refund/refund.entity.ts @@ -48,7 +48,7 @@ export class Refund extends VendureEntity { lines: RefundLine[]; @Index() - @ManyToOne(type => Payment) + @ManyToOne(type => Payment, payment => payment.refunds) @JoinColumn() payment: Payment; diff --git a/packages/core/src/entity/role/role.entity.ts b/packages/core/src/entity/role/role.entity.ts index 067756532d..f552111c16 100644 --- a/packages/core/src/entity/role/role.entity.ts +++ b/packages/core/src/entity/role/role.entity.ts @@ -25,7 +25,7 @@ export class Role extends VendureEntity implements ChannelAware { @Column('simple-array') permissions: Permission[]; - @ManyToMany(type => Channel) + @ManyToMany(type => Channel, channel => channel.roles) @JoinTable() channels: Channel[]; } diff --git a/packages/core/src/entity/seller/seller.entity.ts b/packages/core/src/entity/seller/seller.entity.ts index e014b96eed..c6708e01ea 100644 --- a/packages/core/src/entity/seller/seller.entity.ts +++ b/packages/core/src/entity/seller/seller.entity.ts @@ -1,6 +1,7 @@ import { DeepPartial } from '@vendure/common/lib/shared-types'; -import { Column, Entity } from 'typeorm'; +import { Column, Entity, OneToMany } from 'typeorm'; +import { Channel } from '..'; import { SoftDeletable } from '../../common/types/common-types'; import { HasCustomFields } from '../../config/custom-field/custom-field-types'; import { VendureEntity } from '../base/base.entity'; @@ -26,4 +27,7 @@ export class Seller extends VendureEntity implements SoftDeletable, HasCustomFie @Column(type => CustomSellerFields) customFields: CustomSellerFields; + + @OneToMany(type => Channel, channel => channel.seller) + channels: Channel[]; } diff --git a/packages/core/src/entity/session/authenticated-session.entity.ts b/packages/core/src/entity/session/authenticated-session.entity.ts index cd386de544..32d207be25 100644 --- a/packages/core/src/entity/session/authenticated-session.entity.ts +++ b/packages/core/src/entity/session/authenticated-session.entity.ts @@ -22,7 +22,7 @@ export class AuthenticatedSession extends Session { * The {@link User} who has authenticated to create this session. */ @Index() - @ManyToOne(type => User) + @ManyToOne(type => User, user => user.sessions) user: User; /** diff --git a/packages/core/src/entity/shipping-line/shipping-line.entity.ts b/packages/core/src/entity/shipping-line/shipping-line.entity.ts index b11f7d7fcc..4d60366605 100644 --- a/packages/core/src/entity/shipping-line/shipping-line.entity.ts +++ b/packages/core/src/entity/shipping-line/shipping-line.entity.ts @@ -1,8 +1,9 @@ import { Adjustment, AdjustmentType, Discount, TaxLine } from '@vendure/common/lib/generated-types'; import { DeepPartial, ID } from '@vendure/common/lib/shared-types'; import { summate } from '@vendure/common/lib/shared-utils'; -import { Column, Entity, Index, ManyToOne } from 'typeorm'; +import { Column, Entity, Index, ManyToOne, OneToMany } from 'typeorm'; +import { OrderLine } from '..'; import { Calculated } from '../../common/calculated-decorator'; import { roundMoney } from '../../common/round-money'; import { grossPriceOf, netPriceOf } from '../../common/tax-utils'; @@ -49,6 +50,9 @@ export class ShippingLine extends VendureEntity { @Column('simple-json') taxLines: TaxLine[]; + @OneToMany(type => OrderLine, orderLine => orderLine.shippingLine) + orderLines: OrderLine[]; + @Calculated() get price(): number { return this.listPriceIncludesTax ? netPriceOf(this.listPrice, this.taxRate) : this.listPrice; diff --git a/packages/core/src/entity/shipping-method/shipping-method.entity.ts b/packages/core/src/entity/shipping-method/shipping-method.entity.ts index 646fada42e..ef04b89b5f 100644 --- a/packages/core/src/entity/shipping-method/shipping-method.entity.ts +++ b/packages/core/src/entity/shipping-method/shipping-method.entity.ts @@ -62,7 +62,7 @@ export class ShippingMethod @Column() fulfillmentHandlerCode: string; - @ManyToMany(type => Channel) + @ManyToMany(type => Channel, channel => channel.shippingMethods) @JoinTable() channels: Channel[]; diff --git a/packages/core/src/entity/stock-location/stock-location.entity.ts b/packages/core/src/entity/stock-location/stock-location.entity.ts index d55c10546a..595b4a3210 100644 --- a/packages/core/src/entity/stock-location/stock-location.entity.ts +++ b/packages/core/src/entity/stock-location/stock-location.entity.ts @@ -1,11 +1,12 @@ import { DeepPartial } from '@vendure/common/lib/shared-types'; -import { Column, Entity, JoinTable, ManyToMany } from 'typeorm'; +import { Column, Entity, JoinTable, ManyToMany, OneToMany } from 'typeorm'; import { ChannelAware } from '../../common/types/common-types'; import { HasCustomFields } from '../../config/custom-field/custom-field-types'; import { VendureEntity } from '../base/base.entity'; import { Channel } from '../channel/channel.entity'; import { CustomStockLocationFields } from '../custom-entity-fields'; +import { StockMovement } from '../stock-movement/stock-movement.entity'; /** * @description @@ -32,7 +33,10 @@ export class StockLocation extends VendureEntity implements HasCustomFields, Cha @Column(type => CustomStockLocationFields) customFields: CustomStockLocationFields; - @ManyToMany(type => Channel) + @ManyToMany(type => Channel, channel => channel.stockLocations) @JoinTable() channels: Channel[]; + + @OneToMany(type => StockMovement, movement => movement.stockLocation) + stockMovements: StockMovement[]; } diff --git a/packages/core/src/entity/stock-movement/allocation.entity.ts b/packages/core/src/entity/stock-movement/allocation.entity.ts index 39311ea65a..0de2851e7f 100644 --- a/packages/core/src/entity/stock-movement/allocation.entity.ts +++ b/packages/core/src/entity/stock-movement/allocation.entity.ts @@ -23,6 +23,6 @@ export class Allocation extends StockMovement { } @Index() - @ManyToOne(type => OrderLine) + @ManyToOne(type => OrderLine, orderLine => orderLine.allocations) orderLine: OrderLine; } diff --git a/packages/core/src/entity/stock-movement/cancellation.entity.ts b/packages/core/src/entity/stock-movement/cancellation.entity.ts index 8f130536cf..7f8df054b9 100644 --- a/packages/core/src/entity/stock-movement/cancellation.entity.ts +++ b/packages/core/src/entity/stock-movement/cancellation.entity.ts @@ -22,6 +22,6 @@ export class Cancellation extends StockMovement { } // @Index() omitted as it would conflict with the orderLineId index from the Allocation entity - @ManyToOne(type => OrderLine) + @ManyToOne(type => OrderLine, orderLine => orderLine.cancellations) orderLine: OrderLine; } diff --git a/packages/core/src/entity/stock-movement/sale.entity.ts b/packages/core/src/entity/stock-movement/sale.entity.ts index b05b182bed..145c4eed13 100644 --- a/packages/core/src/entity/stock-movement/sale.entity.ts +++ b/packages/core/src/entity/stock-movement/sale.entity.ts @@ -22,6 +22,6 @@ export class Sale extends StockMovement { } // @Index() omitted as it would conflict with the orderLineId index from the Allocation entity - @ManyToOne(type => OrderLine) + @ManyToOne(type => OrderLine, line => line.sales) orderLine: OrderLine; } diff --git a/packages/core/src/entity/stock-movement/stock-movement.entity.ts b/packages/core/src/entity/stock-movement/stock-movement.entity.ts index b9c25aa1a2..3d3efb1269 100644 --- a/packages/core/src/entity/stock-movement/stock-movement.entity.ts +++ b/packages/core/src/entity/stock-movement/stock-movement.entity.ts @@ -27,7 +27,7 @@ export abstract class StockMovement extends VendureEntity { productVariant: ProductVariant; @Index() - @ManyToOne(type => StockLocation, { onDelete: 'CASCADE' }) + @ManyToOne(type => StockLocation, stockLocation => stockLocation.stockMovements, { onDelete: 'CASCADE' }) stockLocation: StockLocation; @EntityId() diff --git a/packages/core/src/entity/tax-category/tax-category.entity.ts b/packages/core/src/entity/tax-category/tax-category.entity.ts index 3dab28038f..607eb05a81 100644 --- a/packages/core/src/entity/tax-category/tax-category.entity.ts +++ b/packages/core/src/entity/tax-category/tax-category.entity.ts @@ -1,6 +1,7 @@ import { DeepPartial } from '@vendure/common/lib/shared-types'; import { Column, Entity, OneToMany } from 'typeorm'; +import { TaxRate } from '..'; import { HasCustomFields } from '../../config/custom-field/custom-field-types'; import { VendureEntity } from '../base/base.entity'; import { CustomTaxCategoryFields } from '../custom-entity-fields'; @@ -27,4 +28,7 @@ export class TaxCategory extends VendureEntity implements HasCustomFields { @OneToMany(type => ProductVariant, productVariant => productVariant.taxCategory) productVariants: ProductVariant[]; + + @OneToMany(type => TaxRate, taxRate => taxRate.category) + taxRates: TaxRate[]; } diff --git a/packages/core/src/entity/tax-rate/tax-rate.entity.ts b/packages/core/src/entity/tax-rate/tax-rate.entity.ts index 2d9889356a..eeb2ea433a 100644 --- a/packages/core/src/entity/tax-rate/tax-rate.entity.ts +++ b/packages/core/src/entity/tax-rate/tax-rate.entity.ts @@ -35,15 +35,15 @@ export class TaxRate extends VendureEntity implements HasCustomFields { @Column({ type: 'decimal', precision: 5, scale: 2, transformer: new DecimalTransformer() }) value: number; @Index() - @ManyToOne(type => TaxCategory) + @ManyToOne(type => TaxCategory, taxCategory => taxCategory.taxRates) category: TaxCategory; @Index() - @ManyToOne(type => Zone) + @ManyToOne(type => Zone, zone => zone.taxRates) zone: Zone; @Index() - @ManyToOne(type => CustomerGroup, { nullable: true }) + @ManyToOne(type => CustomerGroup, customerGroup => customerGroup.taxRates, { nullable: true }) customerGroup?: CustomerGroup; @Column(type => CustomTaxRateFields) diff --git a/packages/core/src/entity/user/user.entity.ts b/packages/core/src/entity/user/user.entity.ts index 929629cd19..0a031f7c1c 100644 --- a/packages/core/src/entity/user/user.entity.ts +++ b/packages/core/src/entity/user/user.entity.ts @@ -9,6 +9,7 @@ import { NativeAuthenticationMethod } from '../authentication-method/native-auth import { VendureEntity } from '../base/base.entity'; import { CustomUserFields } from '../custom-entity-fields'; import { Role } from '../role/role.entity'; +import { AuthenticatedSession } from '../session/authenticated-session.entity'; /** * @description @@ -45,6 +46,9 @@ export class User extends VendureEntity implements HasCustomFields, SoftDeletabl @Column(type => CustomUserFields) customFields: CustomUserFields; + @OneToMany(type => AuthenticatedSession, session => session.user) + sessions: AuthenticatedSession[]; + getNativeAuthenticationMethod(): NativeAuthenticationMethod; getNativeAuthenticationMethod(strict?: boolean): NativeAuthenticationMethod | undefined; diff --git a/packages/core/src/entity/zone/zone.entity.ts b/packages/core/src/entity/zone/zone.entity.ts index 5b57dd8801..670616943f 100644 --- a/packages/core/src/entity/zone/zone.entity.ts +++ b/packages/core/src/entity/zone/zone.entity.ts @@ -1,11 +1,13 @@ import { DeepPartial } from '@vendure/common/lib/shared-types'; -import { Column, Entity, JoinTable, ManyToMany } from 'typeorm'; +import { Column, Entity, JoinTable, ManyToMany, OneToMany } from 'typeorm'; import { HasCustomFields } from '../../config/custom-field/custom-field-types'; import { VendureEntity } from '../base/base.entity'; +import { Channel } from '../channel/channel.entity'; import { CustomZoneFields } from '../custom-entity-fields'; import { Country } from '../region/country.entity'; import { Region } from '../region/region.entity'; +import { TaxRate } from '../tax-rate/tax-rate.entity'; /** * @description @@ -28,4 +30,13 @@ export class Zone extends VendureEntity implements HasCustomFields { @Column(type => CustomZoneFields) customFields: CustomZoneFields; + + @OneToMany(type => Channel, country => country.defaultShippingZone) + defaultShippingZoneChannels: Channel[]; + + @OneToMany(type => Channel, country => country.defaultTaxZone) + defaultTaxZoneChannels: Channel[]; + + @OneToMany(type => TaxRate, taxRate => taxRate.zone) + taxRates: TaxRate[]; }