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

feat(core): TaxCategories query now returns PaginatedList

BREAKING CHANGE: The `taxCategories` mutation now returns a PaginatedList rather than
a simple array of TaxCategory objects.
Michael Bromley пре 2 година
родитељ
комит
ddcd0fcfd1

+ 38 - 1
packages/asset-server-plugin/e2e/graphql/generated-e2e-asset-server-plugin-types.ts

@@ -4483,7 +4483,7 @@ export type Query = {
     stockLocations: StockLocationList;
     tag: Tag;
     tags: TagList;
-    taxCategories: Array<TaxCategory>;
+    taxCategories: TaxCategoryList;
     taxCategory?: Maybe<TaxCategory>;
     taxRate?: Maybe<TaxRate>;
     taxRates: TaxRateList;
@@ -4689,6 +4689,10 @@ export type QueryTagsArgs = {
     options?: InputMaybe<TagListOptions>;
 };
 
+export type QueryTaxCategoriesArgs = {
+    options?: InputMaybe<TaxCategoryListOptions>;
+};
+
 export type QueryTaxCategoryArgs = {
     id: Scalars['ID'];
 };
@@ -5379,6 +5383,39 @@ export type TaxCategory = Node & {
     updatedAt: Scalars['DateTime'];
 };
 
+export type TaxCategoryFilterParameter = {
+    createdAt?: InputMaybe<DateOperators>;
+    id?: InputMaybe<IdOperators>;
+    isDefault?: InputMaybe<BooleanOperators>;
+    name?: InputMaybe<StringOperators>;
+    updatedAt?: InputMaybe<DateOperators>;
+};
+
+export type TaxCategoryList = PaginatedList & {
+    items: Array<TaxCategory>;
+    totalItems: Scalars['Int'];
+};
+
+export type TaxCategoryListOptions = {
+    /** Allows the results to be filtered */
+    filter?: InputMaybe<TaxCategoryFilterParameter>;
+    /** Specifies whether multiple "filter" arguments should be combines with a logical AND or OR operation. Defaults to AND. */
+    filterOperator?: InputMaybe<LogicalOperator>;
+    /** Skips the first n results, for use in pagination */
+    skip?: InputMaybe<Scalars['Int']>;
+    /** Specifies which properties to sort the results by */
+    sort?: InputMaybe<TaxCategorySortParameter>;
+    /** Takes n results, for use in pagination */
+    take?: InputMaybe<Scalars['Int']>;
+};
+
+export type TaxCategorySortParameter = {
+    createdAt?: InputMaybe<SortOrder>;
+    id?: InputMaybe<SortOrder>;
+    name?: InputMaybe<SortOrder>;
+    updatedAt?: InputMaybe<SortOrder>;
+};
+
 export type TaxLine = {
     description: Scalars['String'];
     taxRate: Scalars['Float'];

+ 40 - 1
packages/common/src/generated-types.ts

@@ -4712,7 +4712,7 @@ export type Query = {
   stockLocations: StockLocationList;
   tag: Tag;
   tags: TagList;
-  taxCategories: Array<TaxCategory>;
+  taxCategories: TaxCategoryList;
   taxCategory?: Maybe<TaxCategory>;
   taxRate?: Maybe<TaxRate>;
   taxRates: TaxRateList;
@@ -4967,6 +4967,11 @@ export type QueryTagsArgs = {
 };
 
 
+export type QueryTaxCategoriesArgs = {
+  options?: InputMaybe<TaxCategoryListOptions>;
+};
+
+
 export type QueryTaxCategoryArgs = {
   id: Scalars['ID'];
 };
@@ -5679,6 +5684,40 @@ export type TaxCategory = Node & {
   updatedAt: Scalars['DateTime'];
 };
 
+export type TaxCategoryFilterParameter = {
+  createdAt?: InputMaybe<DateOperators>;
+  id?: InputMaybe<IdOperators>;
+  isDefault?: InputMaybe<BooleanOperators>;
+  name?: InputMaybe<StringOperators>;
+  updatedAt?: InputMaybe<DateOperators>;
+};
+
+export type TaxCategoryList = PaginatedList & {
+  __typename?: 'TaxCategoryList';
+  items: Array<TaxCategory>;
+  totalItems: Scalars['Int'];
+};
+
+export type TaxCategoryListOptions = {
+  /** Allows the results to be filtered */
+  filter?: InputMaybe<TaxCategoryFilterParameter>;
+  /** Specifies whether multiple "filter" arguments should be combines with a logical AND or OR operation. Defaults to AND. */
+  filterOperator?: InputMaybe<LogicalOperator>;
+  /** Skips the first n results, for use in pagination */
+  skip?: InputMaybe<Scalars['Int']>;
+  /** Specifies which properties to sort the results by */
+  sort?: InputMaybe<TaxCategorySortParameter>;
+  /** Takes n results, for use in pagination */
+  take?: InputMaybe<Scalars['Int']>;
+};
+
+export type TaxCategorySortParameter = {
+  createdAt?: InputMaybe<SortOrder>;
+  id?: InputMaybe<SortOrder>;
+  name?: InputMaybe<SortOrder>;
+  updatedAt?: InputMaybe<SortOrder>;
+};
+
 export type TaxLine = {
   __typename?: 'TaxLine';
   description: Scalars['String'];

+ 39 - 2
packages/core/e2e/graphql/generated-e2e-admin-types.ts

@@ -4483,7 +4483,7 @@ export type Query = {
     stockLocations: StockLocationList;
     tag: Tag;
     tags: TagList;
-    taxCategories: Array<TaxCategory>;
+    taxCategories: TaxCategoryList;
     taxCategory?: Maybe<TaxCategory>;
     taxRate?: Maybe<TaxRate>;
     taxRates: TaxRateList;
@@ -4689,6 +4689,10 @@ export type QueryTagsArgs = {
     options?: InputMaybe<TagListOptions>;
 };
 
+export type QueryTaxCategoriesArgs = {
+    options?: InputMaybe<TaxCategoryListOptions>;
+};
+
 export type QueryTaxCategoryArgs = {
     id: Scalars['ID'];
 };
@@ -5379,6 +5383,39 @@ export type TaxCategory = Node & {
     updatedAt: Scalars['DateTime'];
 };
 
+export type TaxCategoryFilterParameter = {
+    createdAt?: InputMaybe<DateOperators>;
+    id?: InputMaybe<IdOperators>;
+    isDefault?: InputMaybe<BooleanOperators>;
+    name?: InputMaybe<StringOperators>;
+    updatedAt?: InputMaybe<DateOperators>;
+};
+
+export type TaxCategoryList = PaginatedList & {
+    items: Array<TaxCategory>;
+    totalItems: Scalars['Int'];
+};
+
+export type TaxCategoryListOptions = {
+    /** Allows the results to be filtered */
+    filter?: InputMaybe<TaxCategoryFilterParameter>;
+    /** Specifies whether multiple "filter" arguments should be combines with a logical AND or OR operation. Defaults to AND. */
+    filterOperator?: InputMaybe<LogicalOperator>;
+    /** Skips the first n results, for use in pagination */
+    skip?: InputMaybe<Scalars['Int']>;
+    /** Specifies which properties to sort the results by */
+    sort?: InputMaybe<TaxCategorySortParameter>;
+    /** Takes n results, for use in pagination */
+    take?: InputMaybe<Scalars['Int']>;
+};
+
+export type TaxCategorySortParameter = {
+    createdAt?: InputMaybe<SortOrder>;
+    id?: InputMaybe<SortOrder>;
+    name?: InputMaybe<SortOrder>;
+    updatedAt?: InputMaybe<SortOrder>;
+};
+
 export type TaxLine = {
     description: Scalars['String'];
     taxRate: Scalars['Float'];
@@ -11231,7 +11268,7 @@ export type DeleteTagMutation = { deleteTag: { message?: string | null; result:
 export type GetTaxCategoryListQueryVariables = Exact<{ [key: string]: never }>;
 
 export type GetTaxCategoryListQuery = {
-    taxCategories: Array<{ id: string; name: string; isDefault: boolean }>;
+    taxCategories: { items: Array<{ id: string; name: string; isDefault: boolean }> };
 };
 
 export type GetTaxCategoryQueryVariables = Exact<{

+ 5 - 3
packages/core/e2e/tax-category.e2e-spec.ts

@@ -185,9 +185,11 @@ describe('TaxCategory resolver', () => {
 const GET_TAX_CATEGORY_LIST = gql`
     query GetTaxCategoryList {
         taxCategories {
-            id
-            name
-            isDefault
+            items {
+                id
+                name
+                isDefault
+            }
         }
     }
 `;

+ 7 - 2
packages/core/src/api/resolvers/admin/tax-category.resolver.ts

@@ -5,8 +5,10 @@ import {
     MutationDeleteTaxCategoryArgs,
     MutationUpdateTaxCategoryArgs,
     Permission,
+    QueryTaxCategoriesArgs,
     QueryTaxCategoryArgs,
 } from '@vendure/common/lib/generated-types';
+import { PaginatedList } from '@vendure/common/lib/shared-types';
 
 import { TaxCategory } from '../../../entity/tax-category/tax-category.entity';
 import { TaxCategoryService } from '../../../service/services/tax-category.service';
@@ -26,8 +28,11 @@ export class TaxCategoryResolver {
         Permission.ReadProduct,
         Permission.ReadTaxCategory,
     )
-    async taxCategories(@Ctx() ctx: RequestContext): Promise<TaxCategory[]> {
-        return this.taxCategoryService.findAll(ctx);
+    async taxCategories(
+        @Ctx() ctx: RequestContext,
+        @Args() args: QueryTaxCategoriesArgs,
+    ): Promise<PaginatedList<TaxCategory>> {
+        return this.taxCategoryService.findAll(ctx, args.options || undefined);
     }
 
     @Query()

+ 8 - 1
packages/core/src/api/schema/admin-api/tax-category.api.graphql

@@ -1,8 +1,15 @@
 type Query {
-    taxCategories: [TaxCategory!]!
+    taxCategories(options: TaxCategoryListOptions): TaxCategoryList!
     taxCategory(id: ID!): TaxCategory
 }
 
+type TaxCategoryList implements PaginatedList {
+    items: [TaxCategory!]!
+    totalItems: Int!
+}
+
+input TaxCategoryListOptions
+
 type Mutation {
     "Create a new TaxCategory"
     createTaxCategory(input: CreateTaxCategoryInput!): TaxCategory!

+ 1 - 1
packages/core/src/data-import/providers/importer/importer.ts

@@ -260,7 +260,7 @@ export class Importer {
                     featuredAssetId: variantAssets.length ? variantAssets[0].id : undefined,
                     assetIds: variantAssets.map(a => a.id),
                     sku: variant.sku,
-                    taxCategoryId: this.getMatchingTaxCategoryId(variant.taxCategory, taxCategories),
+                    taxCategoryId: this.getMatchingTaxCategoryId(variant.taxCategory, taxCategories.items),
                     stockOnHand: variant.stockOnHand,
                     trackInventory: variant.trackInventory,
                     optionIds,

+ 1 - 1
packages/core/src/service/services/product-variant.service.ts

@@ -796,7 +796,7 @@ export class ProductVariantService {
             taxCategory = await this.connection.getEntityOrThrow(ctx, TaxCategory, taxCategoryId);
         } else {
             const taxCategories = await this.taxCategoryService.findAll(ctx);
-            taxCategory = taxCategories.find(t => t.isDefault === true) ?? taxCategories[0];
+            taxCategory = taxCategories.items.find(t => t.isDefault === true) ?? taxCategories.items[0];
         }
         if (!taxCategory) {
             // there is no TaxCategory set up, so create a default

+ 20 - 4
packages/core/src/service/services/tax-category.service.ts

@@ -5,16 +5,19 @@ import {
     DeletionResult,
     UpdateTaxCategoryInput,
 } from '@vendure/common/lib/generated-types';
-import { ID } from '@vendure/common/lib/shared-types';
+import { ID, PaginatedList } from '@vendure/common/lib/shared-types';
 
 import { RequestContext } from '../../api/common/request-context';
 import { EntityNotFoundError } from '../../common/error/errors';
+import { ListQueryOptions } from '../../common/index';
 import { assertFound } from '../../common/utils';
 import { TransactionalConnection } from '../../connection/transactional-connection';
+import { Tag } from '../../entity/index';
 import { TaxCategory } from '../../entity/tax-category/tax-category.entity';
 import { TaxRate } from '../../entity/tax-rate/tax-rate.entity';
 import { EventBus } from '../../event-bus';
 import { TaxCategoryEvent } from '../../event-bus/events/tax-category-event';
+import { ListQueryBuilder } from '../helpers/list-query-builder/list-query-builder';
 import { patchEntity } from '../helpers/utils/patch-entity';
 
 /**
@@ -25,10 +28,23 @@ import { patchEntity } from '../helpers/utils/patch-entity';
  */
 @Injectable()
 export class TaxCategoryService {
-    constructor(private connection: TransactionalConnection, private eventBus: EventBus) {}
+    constructor(
+        private connection: TransactionalConnection,
+        private eventBus: EventBus,
+        private listQueryBuilder: ListQueryBuilder,
+    ) {}
 
-    findAll(ctx: RequestContext): Promise<TaxCategory[]> {
-        return this.connection.getRepository(ctx, TaxCategory).find();
+    findAll(
+        ctx: RequestContext,
+        options?: ListQueryOptions<TaxCategory>,
+    ): Promise<PaginatedList<TaxCategory>> {
+        return this.listQueryBuilder
+            .build(TaxCategory, options, { ctx })
+            .getManyAndCount()
+            .then(([items, totalItems]) => ({
+                items,
+                totalItems,
+            }));
     }
 
     findOne(ctx: RequestContext, taxCategoryId: ID): Promise<TaxCategory | undefined> {

+ 38 - 1
packages/elasticsearch-plugin/e2e/graphql/generated-e2e-elasticsearch-plugin-types.ts

@@ -4483,7 +4483,7 @@ export type Query = {
     stockLocations: StockLocationList;
     tag: Tag;
     tags: TagList;
-    taxCategories: Array<TaxCategory>;
+    taxCategories: TaxCategoryList;
     taxCategory?: Maybe<TaxCategory>;
     taxRate?: Maybe<TaxRate>;
     taxRates: TaxRateList;
@@ -4689,6 +4689,10 @@ export type QueryTagsArgs = {
     options?: InputMaybe<TagListOptions>;
 };
 
+export type QueryTaxCategoriesArgs = {
+    options?: InputMaybe<TaxCategoryListOptions>;
+};
+
 export type QueryTaxCategoryArgs = {
     id: Scalars['ID'];
 };
@@ -5379,6 +5383,39 @@ export type TaxCategory = Node & {
     updatedAt: Scalars['DateTime'];
 };
 
+export type TaxCategoryFilterParameter = {
+    createdAt?: InputMaybe<DateOperators>;
+    id?: InputMaybe<IdOperators>;
+    isDefault?: InputMaybe<BooleanOperators>;
+    name?: InputMaybe<StringOperators>;
+    updatedAt?: InputMaybe<DateOperators>;
+};
+
+export type TaxCategoryList = PaginatedList & {
+    items: Array<TaxCategory>;
+    totalItems: Scalars['Int'];
+};
+
+export type TaxCategoryListOptions = {
+    /** Allows the results to be filtered */
+    filter?: InputMaybe<TaxCategoryFilterParameter>;
+    /** Specifies whether multiple "filter" arguments should be combines with a logical AND or OR operation. Defaults to AND. */
+    filterOperator?: InputMaybe<LogicalOperator>;
+    /** Skips the first n results, for use in pagination */
+    skip?: InputMaybe<Scalars['Int']>;
+    /** Specifies which properties to sort the results by */
+    sort?: InputMaybe<TaxCategorySortParameter>;
+    /** Takes n results, for use in pagination */
+    take?: InputMaybe<Scalars['Int']>;
+};
+
+export type TaxCategorySortParameter = {
+    createdAt?: InputMaybe<SortOrder>;
+    id?: InputMaybe<SortOrder>;
+    name?: InputMaybe<SortOrder>;
+    updatedAt?: InputMaybe<SortOrder>;
+};
+
 export type TaxLine = {
     description: Scalars['String'];
     taxRate: Scalars['Float'];

+ 38 - 1
packages/payments-plugin/e2e/graphql/generated-admin-types.ts

@@ -4483,7 +4483,7 @@ export type Query = {
     stockLocations: StockLocationList;
     tag: Tag;
     tags: TagList;
-    taxCategories: Array<TaxCategory>;
+    taxCategories: TaxCategoryList;
     taxCategory?: Maybe<TaxCategory>;
     taxRate?: Maybe<TaxRate>;
     taxRates: TaxRateList;
@@ -4689,6 +4689,10 @@ export type QueryTagsArgs = {
     options?: InputMaybe<TagListOptions>;
 };
 
+export type QueryTaxCategoriesArgs = {
+    options?: InputMaybe<TaxCategoryListOptions>;
+};
+
 export type QueryTaxCategoryArgs = {
     id: Scalars['ID'];
 };
@@ -5379,6 +5383,39 @@ export type TaxCategory = Node & {
     updatedAt: Scalars['DateTime'];
 };
 
+export type TaxCategoryFilterParameter = {
+    createdAt?: InputMaybe<DateOperators>;
+    id?: InputMaybe<IdOperators>;
+    isDefault?: InputMaybe<BooleanOperators>;
+    name?: InputMaybe<StringOperators>;
+    updatedAt?: InputMaybe<DateOperators>;
+};
+
+export type TaxCategoryList = PaginatedList & {
+    items: Array<TaxCategory>;
+    totalItems: Scalars['Int'];
+};
+
+export type TaxCategoryListOptions = {
+    /** Allows the results to be filtered */
+    filter?: InputMaybe<TaxCategoryFilterParameter>;
+    /** Specifies whether multiple "filter" arguments should be combines with a logical AND or OR operation. Defaults to AND. */
+    filterOperator?: InputMaybe<LogicalOperator>;
+    /** Skips the first n results, for use in pagination */
+    skip?: InputMaybe<Scalars['Int']>;
+    /** Specifies which properties to sort the results by */
+    sort?: InputMaybe<TaxCategorySortParameter>;
+    /** Takes n results, for use in pagination */
+    take?: InputMaybe<Scalars['Int']>;
+};
+
+export type TaxCategorySortParameter = {
+    createdAt?: InputMaybe<SortOrder>;
+    id?: InputMaybe<SortOrder>;
+    name?: InputMaybe<SortOrder>;
+    updatedAt?: InputMaybe<SortOrder>;
+};
+
 export type TaxLine = {
     description: Scalars['String'];
     taxRate: Scalars['Float'];

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


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