Jelajahi Sumber

feat(core): Add bulk facet delete mutation

Relates to #853
Michael Bromley 3 tahun lalu
induk
melakukan
4a1a2f536b

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

@@ -2338,6 +2338,8 @@ export type Mutation = {
   updateFacet: Facet;
   /** Delete an existing Facet */
   deleteFacet: DeletionResponse;
+  /** Delete multiple existing Facets */
+  deleteFacets: Array<DeletionResponse>;
   /** Create one or more FacetValues */
   createFacetValues: Array<FacetValue>;
   /** Update one or more FacetValues */
@@ -2694,6 +2696,12 @@ export type MutationDeleteFacetArgs = {
 };
 
 
+export type MutationDeleteFacetsArgs = {
+  ids: Array<Scalars['ID']>;
+  force?: Maybe<Scalars['Boolean']>;
+};
+
+
 export type MutationCreateFacetValuesArgs = {
   input: Array<CreateFacetValueInput>;
 };

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

@@ -2415,6 +2415,8 @@ export type Mutation = {
   updateFacet: Facet;
   /** Delete an existing Facet */
   deleteFacet: DeletionResponse;
+  /** Delete multiple existing Facets */
+  deleteFacets: Array<DeletionResponse>;
   /** Create one or more FacetValues */
   createFacetValues: Array<FacetValue>;
   /** Update one or more FacetValues */
@@ -2771,6 +2773,12 @@ export type MutationDeleteFacetArgs = {
 };
 
 
+export type MutationDeleteFacetsArgs = {
+  ids: Array<Scalars['ID']>;
+  force?: Maybe<Scalars['Boolean']>;
+};
+
+
 export type MutationCreateFacetValuesArgs = {
   input: Array<CreateFacetValueInput>;
 };

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

@@ -2338,6 +2338,8 @@ export type Mutation = {
   updateFacet: Facet;
   /** Delete an existing Facet */
   deleteFacet: DeletionResponse;
+  /** Delete multiple existing Facets */
+  deleteFacets: Array<DeletionResponse>;
   /** Create one or more FacetValues */
   createFacetValues: Array<FacetValue>;
   /** Update one or more FacetValues */
@@ -2694,6 +2696,12 @@ export type MutationDeleteFacetArgs = {
 };
 
 
+export type MutationDeleteFacetsArgs = {
+  ids: Array<Scalars['ID']>;
+  force?: Maybe<Scalars['Boolean']>;
+};
+
+
 export type MutationCreateFacetValuesArgs = {
   input: Array<CreateFacetValueInput>;
 };

+ 11 - 0
packages/core/src/api/resolvers/admin/facet.resolver.ts

@@ -5,6 +5,7 @@ import {
     MutationCreateFacetArgs,
     MutationCreateFacetValuesArgs,
     MutationDeleteFacetArgs,
+    MutationDeleteFacetsArgs,
     MutationDeleteFacetValuesArgs,
     MutationRemoveFacetsFromChannelArgs,
     MutationUpdateFacetArgs,
@@ -98,6 +99,16 @@ export class FacetResolver {
         return this.facetService.delete(ctx, args.id, args.force || false);
     }
 
+    @Transaction()
+    @Mutation()
+    @Allow(Permission.DeleteCatalog, Permission.DeleteFacet)
+    async deleteFacets(
+        @Ctx() ctx: RequestContext,
+        @Args() args: MutationDeleteFacetsArgs,
+    ): Promise<DeletionResponse[]> {
+        return Promise.all(args.ids.map(id => this.facetService.delete(ctx, id, args.force || false)));
+    }
+
     @Transaction()
     @Mutation()
     @Allow(Permission.CreateCatalog, Permission.CreateFacet)

+ 3 - 0
packages/core/src/api/schema/admin-api/facet.api.graphql

@@ -13,6 +13,9 @@ type Mutation {
     "Delete an existing Facet"
     deleteFacet(id: ID!, force: Boolean): DeletionResponse!
 
+    "Delete multiple existing Facets"
+    deleteFacets(ids: [ID!]!, force: Boolean): [DeletionResponse!]!
+
     "Create one or more FacetValues"
     createFacetValues(input: [CreateFacetValueInput!]!): [FacetValue!]!
 

+ 1 - 1
packages/core/src/i18n/messages/en.json

@@ -115,7 +115,7 @@
     "cannot-transition-without-settled-payments": "Cannot transition Order to the \"PaymentSettled\" state when the total is not covered by settled Payments",
     "country-used-in-addresses": "The selected Country cannot be deleted as it is used in {count, plural, one {1 Address} other {# Addresses}}",
     "facet-force-deleted": "The Facet was deleted and its FacetValues were removed from {products, plural, =0 {} one {1 Product} other {# Products}}{both, select, both { , } single {}}{variants, plural, =0 {} one {1 ProductVariant} other {# ProductVariants}}",
-    "facet-used": "The selected Facet includes FacetValues which are assigned to {products, plural, =0 {} one {1 Product} other {# Products}}{both, select, both { , } single {}}{variants, plural, =0 {} one {1 ProductVariant} other {# ProductVariants}}",
+    "facet-used": "The Facet \"{ facetCode }\" includes FacetValues which are assigned to {products, plural, =0 {} one {1 Product} other {# Products}}{both, select, both { , } single {}}{variants, plural, =0 {} one {1 ProductVariant} other {# ProductVariants}}",
     "facet-value-force-deleted": "The selected FacetValue was removed from {products, plural, =0 {} one {1 Product} other {# Products}}{both, select, both { , } single {}}{variants, plural, =0 {} one {1 ProductVariant} other {# ProductVariants}} and deleted",
     "facet-value-used": "The selected FacetValue is assigned to {products, plural, =0 {} one {1 Product} other {# Products}}{both, select, both { , } single {}}{variants, plural, =0 {} one {1 ProductVariant} other {# ProductVariants}}",
     "payment-method-used-in-channels": "The selected PaymentMethod is assigned to the following Channels: { channelCodes }. Set \"force: true\" to delete from all Channels.",

+ 1 - 1
packages/core/src/service/services/facet.service.ts

@@ -197,7 +197,7 @@ export class FacetService {
 
         const isInUse = !!(productCount || variantCount);
         const both = !!(productCount && variantCount) ? 'both' : 'single';
-        const i18nVars = { products: productCount, variants: variantCount, both };
+        const i18nVars = { products: productCount, variants: variantCount, both, facetCode: facet.code };
         let message = '';
         let result: DeletionResult;
 

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

@@ -2338,6 +2338,8 @@ export type Mutation = {
   updateFacet: Facet;
   /** Delete an existing Facet */
   deleteFacet: DeletionResponse;
+  /** Delete multiple existing Facets */
+  deleteFacets: Array<DeletionResponse>;
   /** Create one or more FacetValues */
   createFacetValues: Array<FacetValue>;
   /** Update one or more FacetValues */
@@ -2694,6 +2696,12 @@ export type MutationDeleteFacetArgs = {
 };
 
 
+export type MutationDeleteFacetsArgs = {
+  ids: Array<Scalars['ID']>;
+  force?: Maybe<Scalars['Boolean']>;
+};
+
+
 export type MutationCreateFacetValuesArgs = {
   input: Array<CreateFacetValueInput>;
 };

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

@@ -2338,6 +2338,8 @@ export type Mutation = {
   updateFacet: Facet;
   /** Delete an existing Facet */
   deleteFacet: DeletionResponse;
+  /** Delete multiple existing Facets */
+  deleteFacets: Array<DeletionResponse>;
   /** Create one or more FacetValues */
   createFacetValues: Array<FacetValue>;
   /** Update one or more FacetValues */
@@ -2694,6 +2696,12 @@ export type MutationDeleteFacetArgs = {
 };
 
 
+export type MutationDeleteFacetsArgs = {
+  ids: Array<Scalars['ID']>;
+  force?: Maybe<Scalars['Boolean']>;
+};
+
+
 export type MutationCreateFacetValuesArgs = {
   input: Array<CreateFacetValueInput>;
 };

File diff ditekan karena terlalu besar
+ 0 - 0
schema-admin.json


Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini