فهرست منبع

refactor: Remove API method applyFacetValuesToProductVariants

No longer needed as we have a more consistent way of doing it via updateProductVariants
Michael Bromley 7 سال پیش
والد
کامیت
a8acb4b60c

+ 0 - 12
admin-ui/src/app/data/definitions/product-definitions.ts

@@ -194,18 +194,6 @@ export const REMOVE_OPTION_GROUP_FROM_PRODUCT = gql`
     }
 `;
 
-export const APPLY_FACET_VALUE_TO_PRODUCT_VARIANTS = gql`
-    mutation ApplyFacetValuesToProductVariants($facetValueIds: [ID!]!, $productVariantIds: [ID!]!) {
-        applyFacetValuesToProductVariants(
-            facetValueIds: $facetValueIds
-            productVariantIds: $productVariantIds
-        ) {
-            ...ProductVariant
-        }
-    }
-    ${PRODUCT_VARIANT_FRAGMENT}
-`;
-
 export const GET_PRODUCT_WITH_VARIANTS = gql`
     query GetProductWithVariants($id: ID!, $languageCode: LanguageCode) {
         product(languageCode: $languageCode, id: $id) {

+ 0 - 12
admin-ui/src/app/data/providers/product-data.service.ts

@@ -2,7 +2,6 @@ import { forkJoin, from } from 'rxjs';
 import { bufferCount, concatMap, mergeMap } from 'rxjs/operators';
 import {
     AddOptionGroupToProduct,
-    ApplyFacetValuesToProductVariants,
     CreateAssets,
     CreateProduct,
     CreateProductCategory,
@@ -32,7 +31,6 @@ import { pick } from 'shared/pick';
 import { getDefaultLanguage } from '../../common/utilities/get-default-language';
 import {
     ADD_OPTION_GROUP_TO_PRODUCT,
-    APPLY_FACET_VALUE_TO_PRODUCT_VARIANTS,
     CREATE_ASSETS,
     CREATE_PRODUCT,
     CREATE_PRODUCT_CATEGORY,
@@ -149,16 +147,6 @@ export class ProductDataService {
         );
     }
 
-    applyFacetValuesToProductVariants(facetValueIds: string[], productVariantIds: string[]) {
-        return this.baseDataService.mutate<
-            ApplyFacetValuesToProductVariants.Mutation,
-            ApplyFacetValuesToProductVariants.Variables
-        >(APPLY_FACET_VALUE_TO_PRODUCT_VARIANTS, {
-            facetValueIds,
-            productVariantIds,
-        });
-    }
-
     getAssetList(take: number = 10, skip: number = 0) {
         return this.baseDataService.query<GetAssetList.Query, GetAssetList.Variables>(GET_ASSET_LIST, {
             options: {

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
schema.json


+ 0 - 64
server/e2e/__snapshots__/product.e2e-spec.ts.snap

@@ -56,70 +56,6 @@ Object {
 }
 `;
 
-exports[`Product resolver product mutation variants applyFacetValuesToProductVariants adds facets to variants 1`] = `
-Array [
-  Object {
-    "code": "Harris_LLC",
-    "facet": Object {
-      "id": "T_1",
-      "name": "Brand",
-    },
-    "id": "T_1",
-    "name": "Harris LLC",
-  },
-  Object {
-    "code": "Heathcote_-_Goyette",
-    "facet": Object {
-      "id": "T_1",
-      "name": "Brand",
-    },
-    "id": "T_3",
-    "name": "Heathcote - Goyette",
-  },
-  Object {
-    "code": "Fisher,_Sporer_and_Bailey",
-    "facet": Object {
-      "id": "T_1",
-      "name": "Brand",
-    },
-    "id": "T_5",
-    "name": "Fisher, Sporer and Bailey",
-  },
-]
-`;
-
-exports[`Product resolver product mutation variants applyFacetValuesToProductVariants adds facets to variants 2`] = `
-Array [
-  Object {
-    "code": "Harris_LLC",
-    "facet": Object {
-      "id": "T_1",
-      "name": "Brand",
-    },
-    "id": "T_1",
-    "name": "Harris LLC",
-  },
-  Object {
-    "code": "Heathcote_-_Goyette",
-    "facet": Object {
-      "id": "T_1",
-      "name": "Brand",
-    },
-    "id": "T_3",
-    "name": "Heathcote - Goyette",
-  },
-  Object {
-    "code": "Fisher,_Sporer_and_Bailey",
-    "facet": Object {
-      "id": "T_1",
-      "name": "Brand",
-    },
-    "id": "T_5",
-    "name": "Fisher, Sporer and Bailey",
-  },
-]
-`;
-
 exports[`Product resolver product query returns expected properties 1`] = `
 Object {
   "assets": Array [

+ 22 - 51
server/e2e/product.e2e-spec.ts

@@ -17,7 +17,6 @@ import { omit } from 'shared/omit';
 
 import {
     ADD_OPTION_GROUP_TO_PRODUCT,
-    APPLY_FACET_VALUE_TO_PRODUCT_VARIANTS,
     CREATE_PRODUCT,
     GENERATE_PRODUCT_VARIANTS,
     GET_ASSET_LIST,
@@ -497,6 +496,28 @@ describe('Product resolver', () => {
                 expect(updatedVariant.taxCategory.id).toBe('T_2');
             });
 
+            it('updateProductVariants updates facetValues', async () => {
+                const firstVariant = variants[0];
+                const result = await client.query<
+                    UpdateProductVariants.Mutation,
+                    UpdateProductVariants.Variables
+                >(UPDATE_PRODUCT_VARIANTS, {
+                    input: [
+                        {
+                            id: firstVariant.id,
+                            facetValueIds: ['T_1'],
+                        },
+                    ],
+                });
+                const updatedVariant = result.updateProductVariants[0];
+                if (!updatedVariant) {
+                    fail('no updated variant returned.');
+                    return;
+                }
+                expect(updatedVariant.facetValues.length).toBe(1);
+                expect(updatedVariant.facetValues[0].id).toBe('T_1');
+            });
+
             it('updateProductVariants throws with an invalid variant id', async () => {
                 try {
                     await client.query<UpdateProductVariants.Mutation, UpdateProductVariants.Variables>(
@@ -519,56 +540,6 @@ describe('Product resolver', () => {
                     );
                 }
             });
-
-            it('applyFacetValuesToProductVariants adds facets to variants', async () => {
-                const result = await client.query<
-                    ApplyFacetValuesToProductVariants.Mutation,
-                    ApplyFacetValuesToProductVariants.Variables
-                >(APPLY_FACET_VALUE_TO_PRODUCT_VARIANTS, {
-                    facetValueIds: ['T_1', 'T_3', 'T_5'],
-                    productVariantIds: variants.map(v => v.id),
-                });
-
-                expect(result.applyFacetValuesToProductVariants.length).toBe(2);
-                expect(result.applyFacetValuesToProductVariants[0].facetValues).toMatchSnapshot();
-                expect(result.applyFacetValuesToProductVariants[1].facetValues).toMatchSnapshot();
-
-                variants = result.applyFacetValuesToProductVariants;
-            });
-
-            it('applyFacetValuesToProductVariants with invalid facet value id is a noop', async () => {
-                const variant = variants[0];
-                const initialValues = variant.facetValues.map(v => v.id);
-
-                const result = await client.query<
-                    ApplyFacetValuesToProductVariants.Mutation,
-                    ApplyFacetValuesToProductVariants.Variables
-                >(APPLY_FACET_VALUE_TO_PRODUCT_VARIANTS, {
-                    facetValueIds: ['999', '888'],
-                    productVariantIds: variants.map(v => v.id),
-                });
-
-                expect(result.applyFacetValuesToProductVariants[0].facetValues.map(v => v.id)).toEqual(
-                    initialValues,
-                );
-            });
-
-            it('applyFacetValuesToProductVariants errors with invalid variant id', async () => {
-                try {
-                    await client.query<
-                        ApplyFacetValuesToProductVariants.Mutation,
-                        ApplyFacetValuesToProductVariants.Variables
-                    >(APPLY_FACET_VALUE_TO_PRODUCT_VARIANTS, {
-                        facetValueIds: ['1', '3', '5'],
-                        productVariantIds: ['999'],
-                    });
-                    fail('Should have thrown');
-                } catch (err) {
-                    expect(err.message).toEqual(
-                        expect.stringContaining(`No ProductVariant with the id '999' could be found`),
-                    );
-                }
-            });
         });
     });
 });

+ 1 - 13
server/src/api/resolvers/product.resolver.ts

@@ -128,7 +128,7 @@ export class ProductResolver {
 
     @Mutation()
     @Allow(Permission.UpdateCatalog)
-    @Decode('taxCategoryId')
+    @Decode('taxCategoryId', 'facetValueIds')
     async updateProductVariants(
         @Ctx() ctx: RequestContext,
         @Args() args: UpdateProductVariantsMutationArgs,
@@ -136,16 +136,4 @@ export class ProductResolver {
         const { input } = args;
         return Promise.all(input.map(variant => this.productVariantService.update(ctx, variant)));
     }
-
-    @Mutation()
-    @Allow(Permission.UpdateCatalog)
-    @Decode('facetValueIds', 'productVariantIds')
-    async applyFacetValuesToProductVariants(
-        @Ctx() ctx: RequestContext,
-        @Args() args: ApplyFacetValuesToProductVariantsMutationArgs,
-    ): Promise<Array<Translated<ProductVariant>>> {
-        const { facetValueIds, productVariantIds } = args;
-        const facetValues = await this.facetValueService.findByIds(facetValueIds);
-        return this.productVariantService.addFacetValues(ctx, productVariantIds, facetValues);
-    }
 }

+ 0 - 3
server/src/api/types/product.api.graphql

@@ -21,9 +21,6 @@ type Mutation {
 
     "Update existing ProductVariants"
     updateProductVariants(input: [UpdateProductVariantInput!]!): [ProductVariant]!
-
-    "Applies a FacetValue to the given ProductVariants"
-    applyFacetValuesToProductVariants(facetValueIds: [ID!]!, productVariantIds: [ID!]!): [ProductVariant!]!
 }
 
 type ProductList implements PaginatedList {

+ 0 - 31
server/src/service/services/product-variant.service.ts

@@ -171,37 +171,6 @@ export class ProductVariantService {
         return variants.map(v => translateDeep(v, DEFAULT_LANGUAGE_CODE));
     }
 
-    async addFacetValues(
-        ctx: RequestContext,
-        productVariantIds: ID[],
-        facetValues: FacetValue[],
-    ): Promise<Array<Translated<ProductVariant>>> {
-        const variants = await this.connection.getRepository(ProductVariant).findByIds(productVariantIds, {
-            relations: ['options', 'facetValues', 'facetValues.facet', 'taxCategory'],
-        });
-
-        const notFoundIds = productVariantIds.filter(id => !variants.find(v => idsAreEqual(v.id, id)));
-        if (notFoundIds.length) {
-            throw new EntityNotFoundError('ProductVariant', notFoundIds[0]);
-        }
-        for (const variant of variants) {
-            for (const facetValue of facetValues) {
-                if (!variant.facetValues.map(fv => fv.id).includes(facetValue.id)) {
-                    variant.facetValues.push(facetValue);
-                }
-            }
-            await this.connection.manager.save(variant);
-        }
-
-        return variants.map(v =>
-            translateDeep(this.applyChannelPriceAndTax(v, ctx), DEFAULT_LANGUAGE_CODE, [
-                'options',
-                'facetValues',
-                ['facetValues', 'facet'],
-            ]),
-        );
-    }
-
     /**
      * Populates the `price` field with the price for the specified channel.
      */

+ 0 - 34
shared/generated-types.ts

@@ -650,7 +650,6 @@ export interface Mutation {
     removeOptionGroupFromProduct: Product;
     generateVariantsForProduct: Product;
     updateProductVariants: (ProductVariant | null)[];
-    applyFacetValuesToProductVariants: ProductVariant[];
     createPromotion: Promotion;
     updatePromotion: Promotion;
     createRole: Role;
@@ -1651,10 +1650,6 @@ export interface GenerateVariantsForProductMutationArgs {
 export interface UpdateProductVariantsMutationArgs {
     input: UpdateProductVariantInput[];
 }
-export interface ApplyFacetValuesToProductVariantsMutationArgs {
-    facetValueIds: string[];
-    productVariantIds: string[];
-}
 export interface CreatePromotionMutationArgs {
     input: CreatePromotionInput;
 }
@@ -3905,11 +3900,6 @@ export namespace MutationResolvers {
         removeOptionGroupFromProduct?: RemoveOptionGroupFromProductResolver<Product, any, Context>;
         generateVariantsForProduct?: GenerateVariantsForProductResolver<Product, any, Context>;
         updateProductVariants?: UpdateProductVariantsResolver<(ProductVariant | null)[], any, Context>;
-        applyFacetValuesToProductVariants?: ApplyFacetValuesToProductVariantsResolver<
-            ProductVariant[],
-            any,
-            Context
-        >;
         createPromotion?: CreatePromotionResolver<Promotion, any, Context>;
         updatePromotion?: UpdatePromotionResolver<Promotion, any, Context>;
         createRole?: CreateRoleResolver<Role, any, Context>;
@@ -4384,16 +4374,6 @@ export namespace MutationResolvers {
         input: UpdateProductVariantInput[];
     }
 
-    export type ApplyFacetValuesToProductVariantsResolver<
-        R = ProductVariant[],
-        Parent = any,
-        Context = any
-    > = Resolver<R, Parent, Context, ApplyFacetValuesToProductVariantsArgs>;
-    export interface ApplyFacetValuesToProductVariantsArgs {
-        facetValueIds: string[];
-        productVariantIds: string[];
-    }
-
     export type CreatePromotionResolver<R = Promotion, Parent = any, Context = any> = Resolver<
         R,
         Parent,
@@ -5207,20 +5187,6 @@ export namespace RemoveOptionGroupFromProduct {
     };
 }
 
-export namespace ApplyFacetValuesToProductVariants {
-    export type Variables = {
-        facetValueIds: string[];
-        productVariantIds: string[];
-    };
-
-    export type Mutation = {
-        __typename?: 'Mutation';
-        applyFacetValuesToProductVariants: ApplyFacetValuesToProductVariants[];
-    };
-
-    export type ApplyFacetValuesToProductVariants = ProductVariant.Fragment;
-}
-
 export namespace GetProductWithVariants {
     export type Variables = {
         id: string;

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است