Browse Source

feat(core): Implement tax rate filtering by zoneId, categoryId

Michael Bromley 3 tháng trước cách đây
mục cha
commit
08eb48e66a

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

@@ -6470,12 +6470,14 @@ export type TaxRate = Node & {
 export type TaxRateFilterParameter = {
   _and?: InputMaybe<Array<TaxRateFilterParameter>>;
   _or?: InputMaybe<Array<TaxRateFilterParameter>>;
+  categoryId?: InputMaybe<IdOperators>;
   createdAt?: InputMaybe<DateOperators>;
   enabled?: InputMaybe<BooleanOperators>;
   id?: InputMaybe<IdOperators>;
   name?: InputMaybe<StringOperators>;
   updatedAt?: InputMaybe<DateOperators>;
   value?: InputMaybe<NumberOperators>;
+  zoneId?: InputMaybe<IdOperators>;
 };
 
 export type TaxRateList = PaginatedList & {

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

@@ -6121,12 +6121,14 @@ export type TaxRate = Node & {
 export type TaxRateFilterParameter = {
     _and?: InputMaybe<Array<TaxRateFilterParameter>>;
     _or?: InputMaybe<Array<TaxRateFilterParameter>>;
+    categoryId?: InputMaybe<IdOperators>;
     createdAt?: InputMaybe<DateOperators>;
     enabled?: InputMaybe<BooleanOperators>;
     id?: InputMaybe<IdOperators>;
     name?: InputMaybe<StringOperators>;
     updatedAt?: InputMaybe<DateOperators>;
     value?: InputMaybe<NumberOperators>;
+    zoneId?: InputMaybe<IdOperators>;
 };
 
 export type TaxRateList = PaginatedList & {

+ 5 - 0
packages/core/src/api/schema/admin-api/tax-rate.api.graphql

@@ -14,6 +14,11 @@ type Mutation {
   deleteTaxRates(ids: [ID!]!): [DeletionResponse!]!
 }
 
+input TaxRateFilterParameter {
+    zoneId: IDOperators
+    categoryId: IDOperators
+}
+
 # generated by generateListOptions function
 input TaxRateListOptions
 

+ 24 - 1
packages/core/src/service/services/tax-rate.service.ts

@@ -3,6 +3,7 @@ import {
     CreateTaxRateInput,
     DeletionResponse,
     DeletionResult,
+    TaxRateFilterParameter,
     UpdateTaxRateInput,
 } from '@vendure/common/lib/generated-types';
 import { ID, PaginatedList } from '@vendure/common/lib/shared-types';
@@ -65,8 +66,30 @@ export class TaxRateService {
         options?: ListQueryOptions<TaxRate>,
         relations?: RelationPaths<TaxRate>,
     ): Promise<PaginatedList<TaxRate>> {
+        const effectiveRelations = relations || ['customerGroup'];
+        const customPropertyMap: { [name: string]: string } = {};
+        const hasZoneIdFilter = this.listQueryBuilder.filterObjectHasProperty<TaxRateFilterParameter>(
+            options?.filter,
+            'zoneId',
+        );
+        const hasCategoryIdFilter = this.listQueryBuilder.filterObjectHasProperty<TaxRateFilterParameter>(
+            options?.filter,
+            'categoryId',
+        );
+        if (hasZoneIdFilter) {
+            effectiveRelations.push('zone');
+            customPropertyMap.zoneId = 'zone.id';
+        }
+        if (hasCategoryIdFilter) {
+            effectiveRelations.push('category');
+            customPropertyMap.zoneId = 'category.id';
+        }
         return this.listQueryBuilder
-            .build(TaxRate, options, { relations: relations ?? ['category', 'zone', 'customerGroup'], ctx })
+            .build(TaxRate, options, {
+                relations: effectiveRelations,
+                ctx,
+                customPropertyMap,
+            })
             .getManyAndCount()
             .then(([items, totalItems]) => ({
                 items,

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
schema-admin.json


Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác