Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing reverse side relations #2781

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions packages/core/src/entity/channel/channel.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 })
Expand All @@ -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')
Expand Down Expand Up @@ -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()}`;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,4 +27,7 @@ export class CustomerGroup extends VendureEntity implements HasCustomFields {

@Column(type => CustomCustomerGroupFields)
customFields: CustomCustomerGroupFields;

@OneToMany(type => TaxRate, taxRate => taxRate.zone)
taxRates: TaxRate[];
}
2 changes: 1 addition & 1 deletion packages/core/src/entity/customer/customer.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}
2 changes: 1 addition & 1 deletion packages/core/src/entity/facet/facet.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
27 changes: 21 additions & 6 deletions packages/core/src/entity/order-line/order-line.entity.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';

/**
Expand Down Expand Up @@ -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 })
Expand All @@ -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()
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -170,4 +171,7 @@ export class ProductVariant
@ManyToMany(type => Channel, channel => channel.productVariants)
@JoinTable()
channels: Channel[];

@OneToMany(type => OrderLine, orderLine => orderLine.productVariant)
lines: OrderLine[];
}
2 changes: 1 addition & 1 deletion packages/core/src/entity/product/product.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class Product
@JoinTable()
facetValues: FacetValue[];

@ManyToMany(type => Channel)
@ManyToMany(type => Channel, channel => channel.products)
@JoinTable()
channels: Channel[];

Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/entity/promotion/promotion.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -107,7 +106,7 @@ export class Promotion

@Column() enabled: boolean;

@ManyToMany(type => Channel)
@ManyToMany(type => Channel, channel => channel.promotions)
@JoinTable()
channels: Channel[];

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/entity/refund/refund.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class Refund extends VendureEntity {
lines: RefundLine[];

@Index()
@ManyToOne(type => Payment)
@ManyToOne(type => Payment, payment => payment.refunds)
@JoinColumn()
payment: Payment;

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/entity/role/role.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}
6 changes: 5 additions & 1 deletion packages/core/src/entity/seller/seller.entity.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class ShippingMethod
@Column()
fulfillmentHandlerCode: string;

@ManyToMany(type => Channel)
@ManyToMany(type => Channel, channel => channel.shippingMethods)
@JoinTable()
channels: Channel[];

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export class Allocation extends StockMovement {
}

@Index()
@ManyToOne(type => OrderLine)
@ManyToOne(type => OrderLine, orderLine => orderLine.allocations)
orderLine: OrderLine;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion packages/core/src/entity/stock-movement/sale.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/entity/tax-category/tax-category.entity.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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[];
}
Loading
Loading