Skip to content

Commit

Permalink
feat(core): Update TypeORM to v0.3.20
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 901c7a8
Author: Michael Bromley <michael@michaelbromley.co.uk>
Date:   Fri Mar 8 13:07:51 2024 +0100

    fix(core): Fix handling of customPropertyMap in ListQueryBuilder

commit 0c82208
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Wed Mar 6 17:09:46 2024 +0100

    feat(core): Improve joinTreeRelationsDynamically function

commit b6b6663
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Wed Mar 6 16:01:44 2024 +0100

    feat(core): Add unjoined translation relations and fix alias for filters

commit 3801422
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Wed Mar 6 12:39:13 2024 +0100

    feat(core): Refactoring for list-query-builder.ts and add missed relations

commit 2219b44
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Mon Mar 4 12:27:22 2024 +0100

    feat(core): Fix test case because we have only 2 variants of product

commit 752e31a
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Mon Mar 4 10:03:40 2024 +0100

    chore(core): Clean up code

commit ce7be86
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Mon Mar 4 09:46:25 2024 +0100

    feat(core): Add missing reverse relations

commit 47add43
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Sun Mar 3 16:23:23 2024 +0100

    chore(core): Clean up code

commit 0d8fec0
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Sun Mar 3 15:42:22 2024 +0100

    chore(core): Clean up code

commit f9f5260
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Sun Mar 3 15:02:52 2024 +0100

    feat(core): Fix for un-joined relations or joined with wrong alias

commit 32e0df7
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Sun Mar 3 13:11:21 2024 +0100

    feat(core): Refactoring and extending the `tree` join function

commit 2c37221
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Fri Mar 1 18:11:34 2024 +0100

    feat(chore): Fix comment for relationLoadStrategy

commit e9762ed
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Fri Mar 1 18:10:24 2024 +0100

    feat(core): Backward compatibility and ability to use old logic to work around bugs in collections

commit ddaaaf2
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Fri Mar 1 17:22:07 2024 +0100

    feat(core): Refactoring for a problem with Tree collection due to a bug in Typeorm

commit 42764b4
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Fri Mar 1 11:59:26 2024 +0100

    feat(core): Update inverse relations and filter for entities

commit 4a9e082
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Wed Feb 21 11:39:32 2024 +0100

    feat(core): Update expression for product-variant.entity.ts

commit ae6d95d
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Wed Feb 21 10:43:45 2024 +0100

    feat(core): Update translationsAlias and clean up code from comments

commit 937d4de
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Tue Feb 20 19:35:40 2024 +0100

    feat(core): Fixed alias from NamingStrategy due to difference `_{relation}` -> `__{relation}`

commit dd30d22
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Tue Feb 20 18:00:10 2024 +0100

    feat(core): Added relations from queries and removed optimization methods

commit 6ebbcfc
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Tue Feb 20 14:45:29 2024 +0100

    feat(core): Change removed method eagerJoinRelationAlias to joinTableColumnName

commit e9b1169
Author: Eugene Nitsenko <nitsenko94@gmail.com>
Date:   Tue Feb 20 14:36:40 2024 +0100

    feat(core): Upgrade typeorm version from v0.3.11 to v0.3.20
  • Loading branch information
michaelbromley committed Mar 8, 2024
1 parent 04dcaab commit 0afc94e
Show file tree
Hide file tree
Showing 22 changed files with 352 additions and 278 deletions.
4 changes: 2 additions & 2 deletions packages/core/e2e/fixtures/test-plugins/list-query-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class CustomFieldRelationTestEntity extends VendureEntity {
@Column()
data: string;

@ManyToOne(() => TestEntity)
@ManyToOne(() => TestEntity, testEntity => testEntity.customFields.relation)
parent: Relation<TestEntity>;
}

Expand All @@ -48,7 +48,7 @@ export class CustomFieldOtherRelationTestEntity extends VendureEntity {
@Column()
data: string;

@ManyToOne(() => TestEntity)
@ManyToOne(() => TestEntity, testEntity => testEntity.customFields.otherRelation)
parent: Relation<TestEntity>;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/e2e/money-strategy.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('Custom MoneyStrategy', () => {
cheapVariantId = productVariants.items[0].id;
expensiveVariantId = productVariants.items[1].id;

expect(CustomMoneyStrategy.transformerFromSpy).toHaveBeenCalledTimes(6);
expect(CustomMoneyStrategy.transformerFromSpy).toHaveBeenCalledTimes(2);
});

// https://github.com/vendure-ecommerce/vendure/issues/838
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"progress": "^2.0.3",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"typeorm": "0.3.11"
"typeorm": "0.3.20"
},
"devDependencies": {
"@types/bcrypt": "^5.0.0",
Expand Down
14 changes: 13 additions & 1 deletion packages/core/src/entity/asset/asset.entity.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { AssetType } from '@vendure/common/lib/generated-types';
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, Taggable } 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 { Collection } from '../collection/collection.entity';
import { CustomAssetFields } from '../custom-entity-fields';
import { Product } from '../product/product.entity';
import { ProductVariant } from '../product-variant/product-variant.entity';
import { Tag } from '../tag/tag.entity';

/**
Expand Down Expand Up @@ -49,6 +52,15 @@ export class Asset extends VendureEntity implements Taggable, ChannelAware, HasC
@JoinTable()
channels: Channel[];

@OneToMany(type => Collection, collection => collection.featuredAsset)
featuredInCollections?: Collection[];

@OneToMany(type => ProductVariant, productVariant => productVariant.featuredAsset)
featuredInVariants?: ProductVariant[];

@OneToMany(type => Product, product => product.featuredAsset)
featuredInProducts?: Product[];

@Column(type => CustomAssetFields)
customFields: CustomAssetFields;
}
22 changes: 21 additions & 1 deletion packages/core/src/entity/channel/channel.entity.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { CurrencyCode, LanguageCode } from '@vendure/common/lib/generated-types';
import { DeepPartial, ID } from '@vendure/common/lib/shared-types';
import { Column, Entity, Index, ManyToOne } from 'typeorm';
import { Column, Entity, Index, ManyToMany, ManyToOne } from 'typeorm';

import { VendureEntity } from '../base/base.entity';
import { Collection } from '../collection/collection.entity';
import { CustomChannelFields } from '../custom-entity-fields';
import { EntityId } from '../entity-id.decorator';
import { Facet } from '../facet/facet.entity';
import { FacetValue } from '../facet-value/facet-value.entity';
import { Product } from '../product/product.entity';
import { ProductVariant } from '../product-variant/product-variant.entity';
import { Seller } from '../seller/seller.entity';
import { Zone } from '../zone/zone.entity';

Expand Down Expand Up @@ -103,6 +108,21 @@ export class Channel extends VendureEntity {

@Column() pricesIncludeTax: boolean;

@ManyToMany(type => Product, product => product.channels)
products: Product[];

@ManyToMany(type => ProductVariant, productVariant => productVariant.channels)
productVariants: ProductVariant[];

@ManyToMany(type => FacetValue, facetValue => facetValue.channels)
facetValues: FacetValue[];

@ManyToMany(type => Facet, facet => facet.channels)
facets: Facet[];

@ManyToMany(type => Collection, collection => collection.channels)
collections: Collection[];

private generateToken(): string {
const randomString = () => Math.random().toString(36).substr(3, 10);
return `${randomString()}${randomString()}`;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/entity/collection/collection.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Collection
translations: Array<Translation<Collection>>;

@Index()
@ManyToOne(type => Asset, { onDelete: 'SET NULL' })
@ManyToOne(type => Asset, asset => asset.featuredInCollections, { onDelete: 'SET NULL' })
featuredAsset: Asset;

@OneToMany(type => CollectionAsset, collectionAsset => collectionAsset.collection)
Expand Down Expand Up @@ -90,7 +90,7 @@ export class Collection
@EntityId({ nullable: true })
parentId: ID;

@ManyToMany(type => Channel)
@ManyToMany(type => Channel, channel => channel.collections)
@JoinTable()
channels: Channel[];
}
10 changes: 9 additions & 1 deletion packages/core/src/entity/facet-value/facet-value.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Channel } from '../channel/channel.entity';
import { CustomFacetValueFields } from '../custom-entity-fields';
import { EntityId } from '../entity-id.decorator';
import { Facet } from '../facet/facet.entity';
import { Product } from '../product/product.entity';
import { ProductVariant } from '../product-variant/product-variant.entity';

import { FacetValueTranslation } from './facet-value-translation.entity';

Expand Down Expand Up @@ -40,7 +42,13 @@ export class FacetValue extends VendureEntity implements Translatable, HasCustom
@Column(type => CustomFacetValueFields)
customFields: CustomFacetValueFields;

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

@ManyToMany(() => Product, product => product.facetValues)
products: Product[];

@ManyToMany(type => ProductVariant, productVariant => productVariant.facetValues)
productVariants: ProductVariant[];
}
6 changes: 5 additions & 1 deletion packages/core/src/entity/fulfillment/fulfillment.entity.ts
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, OneToMany } from 'typeorm';
import { Column, Entity, ManyToMany, OneToMany } from 'typeorm';

import { HasCustomFields } from '../../config/custom-field/custom-field-types';
import { FulfillmentState } from '../../service/helpers/fulfillment-state-machine/fulfillment-state';
import { VendureEntity } from '../base/base.entity';
import { CustomFulfillmentFields } from '../custom-entity-fields';
import { Order } from '../order/order.entity';
import { FulfillmentLine } from '../order-line-reference/fulfillment-line.entity';

/**
Expand Down Expand Up @@ -34,6 +35,9 @@ export class Fulfillment extends VendureEntity implements HasCustomFields {
@OneToMany(type => FulfillmentLine, fulfillmentLine => fulfillmentLine.fulfillment)
lines: FulfillmentLine[];

@ManyToMany(type => Order, order => order.fulfillments)
orders: Order[];

@Column(type => CustomFulfillmentFields)
customFields: CustomFulfillmentFields;
}
6 changes: 3 additions & 3 deletions packages/core/src/entity/order/order.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class Order extends VendureEntity implements ChannelAware, HasCustomField
orderPlacedAt?: Date;

@Index()
@ManyToOne(type => Customer)
@ManyToOne(type => Customer, customer => customer.orders)
customer?: Customer;

@EntityId({ nullable: true })
Expand Down Expand Up @@ -122,7 +122,7 @@ export class Order extends VendureEntity implements ChannelAware, HasCustomField
* Promotions applied to the order. Only gets populated after the payment process has completed,
* i.e. the Order is no longer active.
*/
@ManyToMany(type => Promotion)
@ManyToMany(type => Promotion, promotion => promotion.orders)
@JoinTable()
promotions: Promotion[];

Expand All @@ -133,7 +133,7 @@ export class Order extends VendureEntity implements ChannelAware, HasCustomField
@OneToMany(type => Payment, payment => payment.order)
payments: Payment[];

@ManyToMany(type => Fulfillment)
@ManyToMany(type => Fulfillment, fulfillment => fulfillment.orders)
@JoinTable()
fulfillments: Fulfillment[];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class ProductOptionGroup
options: ProductOption[];

@Index()
@ManyToOne(type => Product)
@ManyToOne(type => Product, product => product.optionGroups)
product: Product;

@Column(type => CustomProductOptionGroupFields)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeepPartial, ID } from '@vendure/common/lib/shared-types';
import { Column, Entity, Index, ManyToOne, OneToMany } from 'typeorm';
import { Column, Entity, Index, ManyToMany, ManyToOne, OneToMany } from 'typeorm';

import { SoftDeletable } from '../../common/types/common-types';
import { LocaleString, Translatable, Translation } from '../../common/types/locale-types';
Expand All @@ -8,6 +8,7 @@ import { VendureEntity } from '../base/base.entity';
import { CustomProductOptionFields } from '../custom-entity-fields';
import { EntityId } from '../entity-id.decorator';
import { ProductOptionGroup } from '../product-option-group/product-option-group.entity';
import { ProductVariant } from '../product-variant/product-variant.entity';

import { ProductOptionTranslation } from './product-option-translation.entity';

Expand Down Expand Up @@ -39,6 +40,9 @@ export class ProductOption extends VendureEntity implements Translatable, HasCus
@EntityId()
groupId: ID;

@ManyToMany(type => ProductVariant, variant => variant.options)
productVariants: ProductVariant[];

@Column(type => CustomProductOptionFields)
customFields: CustomProductOptionFields;
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class ProductVariant
currencyCode: CurrencyCode;

@Calculated({
expression: 'productvariant_productVariantPrices.price',
expression: 'productvariant__productVariantPrices.price',
})
get price(): number {
if (this.listPrice == null) {
Expand All @@ -86,7 +86,7 @@ export class ProductVariant
// results due to this expression not taking taxes into account. This is because the tax
// rate is calculated at run-time in the application layer based on the current context,
// and is unknown to the database.
expression: 'productvariant_productVariantPrices.price',
expression: 'productvariant__productVariantPrices.price',
})
get priceWithTax(): number {
if (this.listPrice == null) {
Expand All @@ -103,7 +103,7 @@ export class ProductVariant
taxRateApplied: TaxRate;

@Index()
@ManyToOne(type => Asset, { onDelete: 'SET NULL' })
@ManyToOne(type => Asset, asset => asset.featuredInVariants, { onDelete: 'SET NULL' })
featuredAsset: Asset;

@OneToMany(type => ProductVariantAsset, productVariantAsset => productVariantAsset.productVariant, {
Expand All @@ -112,7 +112,7 @@ export class ProductVariant
assets: ProductVariantAsset[];

@Index()
@ManyToOne(type => TaxCategory)
@ManyToOne(type => TaxCategory, taxCategory => taxCategory.productVariants)
taxCategory: TaxCategory;

@OneToMany(type => ProductVariantPrice, price => price.variant, { eager: true })
Expand Down Expand Up @@ -153,11 +153,11 @@ export class ProductVariant
@OneToMany(type => StockMovement, stockMovement => stockMovement.productVariant)
stockMovements: StockMovement[];

@ManyToMany(type => ProductOption)
@ManyToMany(type => ProductOption, productOption => productOption.productVariants)
@JoinTable()
options: ProductOption[];

@ManyToMany(type => FacetValue)
@ManyToMany(type => FacetValue, facetValue => facetValue.productVariants)
@JoinTable()
facetValues: FacetValue[];

Expand All @@ -167,7 +167,7 @@ export class ProductVariant
@ManyToMany(type => Collection, collection => collection.productVariants)
collections: Collection[];

@ManyToMany(type => Channel)
@ManyToMany(type => Channel, channel => channel.productVariants)
@JoinTable()
channels: Channel[];
}
10 changes: 5 additions & 5 deletions packages/core/src/entity/product/product.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Product
enabled: boolean;

@Index()
@ManyToOne(type => Asset, { onDelete: 'SET NULL' })
@ManyToOne(type => Asset, asset => asset.featuredInProducts, { onDelete: 'SET NULL' })
featuredAsset: Asset;

@OneToMany(type => ProductAsset, productAsset => productAsset.product)
Expand All @@ -59,14 +59,14 @@ export class Product
@OneToMany(type => ProductOptionGroup, optionGroup => optionGroup.product)
optionGroups: ProductOptionGroup[];

@ManyToMany(type => FacetValue)
@ManyToMany(type => FacetValue, facetValue => facetValue.products)
@JoinTable()
facetValues: FacetValue[];

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

@ManyToMany(type => Channel)
@JoinTable()
channels: Channel[];

@Column(type => CustomProductFields)
customFields: CustomProductFields;
}
3 changes: 3 additions & 0 deletions packages/core/src/entity/promotion/promotion.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ export class Promotion
@JoinTable()
channels: Channel[];

@ManyToMany(type => Order, order => order.promotions)
orders: Order[];

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

Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/entity/tax-category/tax-category.entity.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { DeepPartial } from '@vendure/common/lib/shared-types';
import { Column, Entity } from 'typeorm';
import { Column, Entity, OneToMany } from 'typeorm';

import { HasCustomFields } from '../../config/custom-field/custom-field-types';
import { VendureEntity } from '../base/base.entity';
import { CustomTaxCategoryFields } from '../custom-entity-fields';
import { ProductVariant } from '../product-variant/product-variant.entity';

/**
* @description
Expand All @@ -23,4 +24,7 @@ export class TaxCategory extends VendureEntity implements HasCustomFields {

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

@OneToMany(type => ProductVariant, productVariant => productVariant.taxCategory)
productVariants: ProductVariant[];
}
Loading

0 comments on commit 0afc94e

Please sign in to comment.