Преглед изворни кода

feat(core): Add `topLevelOnly` filter to collection list query

Michael Bromley пре 2 година
родитељ
комит
66b8c75393

+ 4 - 0
packages/asset-server-plugin/e2e/graphql/generated-e2e-asset-server-plugin-types.ts

@@ -432,6 +432,7 @@ export type Collection = Node & {
     languageCode?: Maybe<LanguageCode>;
     name: Scalars['String'];
     parent?: Maybe<Collection>;
+    parentId: Scalars['ID'];
     position: Scalars['Int'];
     productVariants: ProductVariantList;
     slug: Scalars['String'];
@@ -457,6 +458,7 @@ export type CollectionFilterParameter = {
     isPrivate?: InputMaybe<BooleanOperators>;
     languageCode?: InputMaybe<StringOperators>;
     name?: InputMaybe<StringOperators>;
+    parentId?: InputMaybe<IdOperators>;
     position?: InputMaybe<NumberOperators>;
     slug?: InputMaybe<StringOperators>;
     updatedAt?: InputMaybe<DateOperators>;
@@ -478,6 +480,7 @@ export type CollectionListOptions = {
     sort?: InputMaybe<CollectionSortParameter>;
     /** Takes n results, for use in pagination */
     take?: InputMaybe<Scalars['Int']>;
+    topLevelOnly?: InputMaybe<Scalars['Boolean']>;
 };
 
 /**
@@ -494,6 +497,7 @@ export type CollectionSortParameter = {
     description?: InputMaybe<SortOrder>;
     id?: InputMaybe<SortOrder>;
     name?: InputMaybe<SortOrder>;
+    parentId?: InputMaybe<SortOrder>;
     position?: InputMaybe<SortOrder>;
     slug?: InputMaybe<SortOrder>;
     updatedAt?: InputMaybe<SortOrder>;

Разлика између датотеке није приказан због своје велике величине
+ 652 - 631
packages/common/src/generated-shop-types.ts


+ 4 - 0
packages/common/src/generated-types.ts

@@ -430,6 +430,7 @@ export type Collection = Node & {
   languageCode?: Maybe<LanguageCode>;
   name: Scalars['String'];
   parent?: Maybe<Collection>;
+  parentId: Scalars['ID'];
   position: Scalars['Int'];
   productVariants: ProductVariantList;
   slug: Scalars['String'];
@@ -457,6 +458,7 @@ export type CollectionFilterParameter = {
   isPrivate?: InputMaybe<BooleanOperators>;
   languageCode?: InputMaybe<StringOperators>;
   name?: InputMaybe<StringOperators>;
+  parentId?: InputMaybe<IdOperators>;
   position?: InputMaybe<NumberOperators>;
   slug?: InputMaybe<StringOperators>;
   updatedAt?: InputMaybe<DateOperators>;
@@ -479,6 +481,7 @@ export type CollectionListOptions = {
   sort?: InputMaybe<CollectionSortParameter>;
   /** Takes n results, for use in pagination */
   take?: InputMaybe<Scalars['Int']>;
+  topLevelOnly?: InputMaybe<Scalars['Boolean']>;
 };
 
 /**
@@ -496,6 +499,7 @@ export type CollectionSortParameter = {
   description?: InputMaybe<SortOrder>;
   id?: InputMaybe<SortOrder>;
   name?: InputMaybe<SortOrder>;
+  parentId?: InputMaybe<SortOrder>;
   position?: InputMaybe<SortOrder>;
   slug?: InputMaybe<SortOrder>;
   updatedAt?: InputMaybe<SortOrder>;

+ 4 - 0
packages/core/e2e/graphql/generated-e2e-admin-types.ts

@@ -432,6 +432,7 @@ export type Collection = Node & {
     languageCode?: Maybe<LanguageCode>;
     name: Scalars['String'];
     parent?: Maybe<Collection>;
+    parentId: Scalars['ID'];
     position: Scalars['Int'];
     productVariants: ProductVariantList;
     slug: Scalars['String'];
@@ -457,6 +458,7 @@ export type CollectionFilterParameter = {
     isPrivate?: InputMaybe<BooleanOperators>;
     languageCode?: InputMaybe<StringOperators>;
     name?: InputMaybe<StringOperators>;
+    parentId?: InputMaybe<IdOperators>;
     position?: InputMaybe<NumberOperators>;
     slug?: InputMaybe<StringOperators>;
     updatedAt?: InputMaybe<DateOperators>;
@@ -478,6 +480,7 @@ export type CollectionListOptions = {
     sort?: InputMaybe<CollectionSortParameter>;
     /** Takes n results, for use in pagination */
     take?: InputMaybe<Scalars['Int']>;
+    topLevelOnly?: InputMaybe<Scalars['Boolean']>;
 };
 
 /**
@@ -494,6 +497,7 @@ export type CollectionSortParameter = {
     description?: InputMaybe<SortOrder>;
     id?: InputMaybe<SortOrder>;
     name?: InputMaybe<SortOrder>;
+    parentId?: InputMaybe<SortOrder>;
     position?: InputMaybe<SortOrder>;
     slug?: InputMaybe<SortOrder>;
     updatedAt?: InputMaybe<SortOrder>;

Разлика између датотеке није приказан због своје велике величине
+ 624 - 603
packages/core/e2e/graphql/generated-e2e-shop-types.ts


+ 3 - 1
packages/core/src/api/schema/admin-api/collection.api.graphql

@@ -31,7 +31,9 @@ type Mutation {
 }
 
 # generated by generateListOptions function
-input CollectionListOptions
+input CollectionListOptions {
+    topLevelOnly: Boolean
+}
 
 input MoveCollectionInput {
     collectionId: ID!

+ 1 - 0
packages/core/src/api/schema/common/collection.type.graphql

@@ -11,6 +11,7 @@ type Collection implements Node {
     featuredAsset: Asset
     assets: [Asset!]!
     parent: Collection
+    parentId: ID!
     children: [Collection!]
     filters: [ConfigurableOperation!]!
     translations: [CollectionTranslation!]!

+ 5 - 1
packages/core/src/entity/collection/collection.entity.ts

@@ -1,5 +1,5 @@
 import { ConfigurableOperation } from '@vendure/common/lib/generated-types';
-import { DeepPartial } from '@vendure/common/lib/shared-types';
+import { DeepPartial, ID } from '@vendure/common/lib/shared-types';
 import {
     Column,
     Entity,
@@ -20,6 +20,7 @@ import { Asset } from '../asset/asset.entity';
 import { VendureEntity } from '../base/base.entity';
 import { Channel } from '../channel/channel.entity';
 import { CustomCollectionFields } from '../custom-entity-fields';
+import { EntityId } from '../entity-id.decorator';
 import { ProductVariant } from '../product-variant/product-variant.entity';
 
 import { CollectionAsset } from './collection-asset.entity';
@@ -86,6 +87,9 @@ export class Collection
     @TreeParent()
     parent: Collection;
 
+    @EntityId({ nullable: true })
+    parentId: ID;
+
     @ManyToMany(type => Channel)
     @JoinTable()
     channels: Channel[];

+ 23 - 19
packages/core/src/service/services/collection.service.ts

@@ -153,27 +153,31 @@ export class CollectionService implements OnModuleInit {
 
     async findAll(
         ctx: RequestContext,
-        options?: ListQueryOptions<Collection>,
+        options?: ListQueryOptions<Collection> & { topLevelOnly?: boolean },
         relations?: RelationPaths<Collection>,
     ): Promise<PaginatedList<Translated<Collection>>> {
-        return this.listQueryBuilder
-            .build(Collection, options, {
-                relations: relations ?? ['featuredAsset', 'parent', 'channels'],
-                channelId: ctx.channelId,
-                where: { isRoot: false },
-                orderBy: { position: 'ASC' },
-                ctx,
-            })
-            .getManyAndCount()
-            .then(async ([collections, totalItems]) => {
-                const items = collections.map(collection =>
-                    this.translator.translate(collection, ctx, ['parent']),
-                );
-                return {
-                    items,
-                    totalItems,
-                };
-            });
+        const qb = this.listQueryBuilder.build(Collection, options, {
+            relations: relations ?? ['featuredAsset', 'parent', 'channels'],
+            channelId: ctx.channelId,
+            where: { isRoot: false },
+            orderBy: { position: 'ASC' },
+            ctx,
+        });
+
+        if (options?.topLevelOnly === true) {
+            qb.leftJoin('collection.parent', 'parent');
+            qb.andWhere('parent.isRoot = :isRoot', { isRoot: true });
+        }
+
+        return qb.getManyAndCount().then(async ([collections, totalItems]) => {
+            const items = collections.map(collection =>
+                this.translator.translate(collection, ctx, ['parent']),
+            );
+            return {
+                items,
+                totalItems,
+            };
+        });
     }
 
     async findOne(

+ 4 - 0
packages/elasticsearch-plugin/e2e/graphql/generated-e2e-elasticsearch-plugin-types.ts

@@ -432,6 +432,7 @@ export type Collection = Node & {
     languageCode?: Maybe<LanguageCode>;
     name: Scalars['String'];
     parent?: Maybe<Collection>;
+    parentId: Scalars['ID'];
     position: Scalars['Int'];
     productVariants: ProductVariantList;
     slug: Scalars['String'];
@@ -457,6 +458,7 @@ export type CollectionFilterParameter = {
     isPrivate?: InputMaybe<BooleanOperators>;
     languageCode?: InputMaybe<StringOperators>;
     name?: InputMaybe<StringOperators>;
+    parentId?: InputMaybe<IdOperators>;
     position?: InputMaybe<NumberOperators>;
     slug?: InputMaybe<StringOperators>;
     updatedAt?: InputMaybe<DateOperators>;
@@ -478,6 +480,7 @@ export type CollectionListOptions = {
     sort?: InputMaybe<CollectionSortParameter>;
     /** Takes n results, for use in pagination */
     take?: InputMaybe<Scalars['Int']>;
+    topLevelOnly?: InputMaybe<Scalars['Boolean']>;
 };
 
 /**
@@ -494,6 +497,7 @@ export type CollectionSortParameter = {
     description?: InputMaybe<SortOrder>;
     id?: InputMaybe<SortOrder>;
     name?: InputMaybe<SortOrder>;
+    parentId?: InputMaybe<SortOrder>;
     position?: InputMaybe<SortOrder>;
     slug?: InputMaybe<SortOrder>;
     updatedAt?: InputMaybe<SortOrder>;

+ 4 - 0
packages/payments-plugin/e2e/graphql/generated-admin-types.ts

@@ -432,6 +432,7 @@ export type Collection = Node & {
     languageCode?: Maybe<LanguageCode>;
     name: Scalars['String'];
     parent?: Maybe<Collection>;
+    parentId: Scalars['ID'];
     position: Scalars['Int'];
     productVariants: ProductVariantList;
     slug: Scalars['String'];
@@ -457,6 +458,7 @@ export type CollectionFilterParameter = {
     isPrivate?: InputMaybe<BooleanOperators>;
     languageCode?: InputMaybe<StringOperators>;
     name?: InputMaybe<StringOperators>;
+    parentId?: InputMaybe<IdOperators>;
     position?: InputMaybe<NumberOperators>;
     slug?: InputMaybe<StringOperators>;
     updatedAt?: InputMaybe<DateOperators>;
@@ -478,6 +480,7 @@ export type CollectionListOptions = {
     sort?: InputMaybe<CollectionSortParameter>;
     /** Takes n results, for use in pagination */
     take?: InputMaybe<Scalars['Int']>;
+    topLevelOnly?: InputMaybe<Scalars['Boolean']>;
 };
 
 /**
@@ -494,6 +497,7 @@ export type CollectionSortParameter = {
     description?: InputMaybe<SortOrder>;
     id?: InputMaybe<SortOrder>;
     name?: InputMaybe<SortOrder>;
+    parentId?: InputMaybe<SortOrder>;
     position?: InputMaybe<SortOrder>;
     slug?: InputMaybe<SortOrder>;
     updatedAt?: InputMaybe<SortOrder>;

Разлика између датотеке није приказан због своје велике величине
+ 624 - 603
packages/payments-plugin/e2e/graphql/generated-shop-types.ts


Разлика између датотеке није приказан због своје велике величине
+ 656 - 635
packages/payments-plugin/src/mollie/graphql/generated-shop-types.ts


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
schema-admin.json


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
schema-shop.json


Неке датотеке нису приказане због велике количине промена