Selaa lähdekoodia

feat(server): Set FacetValues on ProductCategory

Relates to #43
Michael Bromley 7 vuotta sitten
vanhempi
sitoutus
b089c59e5d

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
schema.json


+ 14 - 2
server/e2e/__snapshots__/product-category.e2e-spec.ts.snap

@@ -24,7 +24,13 @@ Object {
   ],
   "children": null,
   "description": "",
-  "facetValues": Array [],
+  "facetValues": Array [
+    Object {
+      "code": "Schiller_-_Welch",
+      "id": "T_1",
+      "name": "Schiller - Welch",
+    },
+  ],
   "featuredAsset": Object {
     "fileSize": 4,
     "id": "T_2",
@@ -67,7 +73,13 @@ Object {
   ],
   "children": null,
   "description": "Apple stuff ",
-  "facetValues": Array [],
+  "facetValues": Array [
+    Object {
+      "code": "Lindgren,_Conn_and_King",
+      "id": "T_3",
+      "name": "Lindgren, Conn and King",
+    },
+  ],
   "featuredAsset": Object {
     "fileSize": 4,
     "id": "T_2",

+ 2 - 0
server/e2e/product-category.e2e-spec.ts

@@ -51,6 +51,7 @@ describe('ProductCategory resolver', () => {
                 input: {
                     assetIds: [assets[0].id, assets[1].id],
                     featuredAssetId: assets[1].id,
+                    facetValueIds: ['T_1'],
                     translations: [{ languageCode: LanguageCode.en, name: 'Electronics', description: '' }],
                 },
             });
@@ -99,6 +100,7 @@ describe('ProductCategory resolver', () => {
                     id: appleCategory.id,
                     assetIds: [assets[1].id],
                     featuredAssetId: assets[1].id,
+                    facetValueIds: ['T_3'],
                     translations: [{ languageCode: LanguageCode.en, description: 'Apple stuff ' }],
                 },
             });

+ 2 - 2
server/src/api/resolvers/product-category.resolver.ts

@@ -41,7 +41,7 @@ export class ProductCategoryResolver {
 
     @Mutation()
     @Allow(Permission.CreateCatalog)
-    @Decode('assetIds', 'featuredAssetId', 'parentId')
+    @Decode('assetIds', 'featuredAssetId', 'parentId', 'facetValueIds')
     async createProductCategory(
         @Ctx() ctx: RequestContext,
         @Args() args: CreateProductCategoryMutationArgs,
@@ -52,7 +52,7 @@ export class ProductCategoryResolver {
 
     @Mutation()
     @Allow(Permission.UpdateCatalog)
-    @Decode('assetIds', 'featuredAssetId')
+    @Decode('assetIds', 'featuredAssetId', 'facetValueIds')
     async updateProductCategory(
         @Ctx() ctx: RequestContext,
         @Args() args: UpdateProductCategoryMutationArgs,

+ 2 - 0
server/src/entity/product-category/product-category.graphql

@@ -34,6 +34,7 @@ input CreateProductCategoryInput {
     featuredAssetId: ID
     assetIds: [ID!]
     parentId: ID
+    facetValueIds: [ID!]
     translations: [ProductCategoryTranslationInput!]!
 }
 
@@ -42,5 +43,6 @@ input UpdateProductCategoryInput {
     featuredAssetId: ID
     parentId: ID
     assetIds: [ID!]
+    facetValueIds: [ID!]
     translations: [ProductCategoryTranslationInput!]!
 }

+ 11 - 0
server/src/service/services/product-category.service.ts

@@ -14,6 +14,7 @@ import { IllegalOperationError } from '../../common/error/errors';
 import { ListQueryOptions } from '../../common/types/common-types';
 import { Translated } from '../../common/types/locale-types';
 import { assertFound, idsAreEqual } from '../../common/utils';
+import { FacetValue } from '../../entity/facet-value/facet-value.entity';
 import { ProductCategoryTranslation } from '../../entity/product-category/product-category-translation.entity';
 import { ProductCategory } from '../../entity/product-category/product-category.entity';
 import { ListQueryBuilder } from '../helpers/list-query-builder/list-query-builder';
@@ -23,6 +24,7 @@ import { translateDeep, translateTree } from '../helpers/utils/translate-entity'
 
 import { AssetService } from './asset.service';
 import { ChannelService } from './channel.service';
+import { FacetValueService } from './facet-value.service';
 
 export class ProductCategoryService {
     private rootCategories: { [channelCode: string]: ProductCategory } = {};
@@ -31,6 +33,7 @@ export class ProductCategoryService {
         @InjectConnection() private connection: Connection,
         private channelService: ChannelService,
         private assetService: AssetService,
+        private facetValueService: FacetValueService,
         private listQueryBuilder: ListQueryBuilder,
         private translatableSaver: TranslatableSaver,
     ) {}
@@ -94,6 +97,9 @@ export class ProductCategoryService {
                     category.parent = parent;
                 }
                 category.position = await this.getNextPositionInParent(ctx, input.parentId || undefined);
+                if (input.facetValueIds) {
+                    category.facetValues = await this.facetValueService.findByIds(input.facetValueIds);
+                }
             },
         });
         await this.saveAssetInputs(productCategory, input);
@@ -108,6 +114,11 @@ export class ProductCategoryService {
             input,
             entityType: ProductCategory,
             translationType: ProductCategoryTranslation,
+            beforeSave: async category => {
+                if (input.facetValueIds) {
+                    category.facetValues = await this.facetValueService.findByIds(input.facetValueIds);
+                }
+            },
         });
         await this.saveAssetInputs(productCategory, input);
         return assertFound(this.findOne(ctx, productCategory.id));

+ 2 - 0
shared/generated-types.ts

@@ -1184,6 +1184,7 @@ export interface CreateProductCategoryInput {
     featuredAssetId?: string | null;
     assetIds?: string[] | null;
     parentId?: string | null;
+    facetValueIds?: string[] | null;
     translations: ProductCategoryTranslationInput[];
     customFields?: Json | null;
 }
@@ -1201,6 +1202,7 @@ export interface UpdateProductCategoryInput {
     featuredAssetId?: string | null;
     parentId?: string | null;
     assetIds?: string[] | null;
+    facetValueIds?: string[] | null;
     translations: ProductCategoryTranslationInput[];
     customFields?: Json | null;
 }

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä