|
|
@@ -2,6 +2,8 @@ import { Args, Query, Resolver } from '@nestjs/graphql';
|
|
|
import {
|
|
|
QueryCollectionArgs,
|
|
|
QueryCollectionsArgs,
|
|
|
+ QueryFacetArgs,
|
|
|
+ QueryFacetsArgs,
|
|
|
QueryProductArgs,
|
|
|
SearchResponse,
|
|
|
} from '@vendure/common/lib/generated-shop-types';
|
|
|
@@ -13,8 +15,9 @@ import { InternalServerError, UserInputError } from '../../../common/error/error
|
|
|
import { ListQueryOptions } from '../../../common/types/common-types';
|
|
|
import { Translated } from '../../../common/types/locale-types';
|
|
|
import { Collection } from '../../../entity/collection/collection.entity';
|
|
|
+import { Facet } from '../../../entity/facet/facet.entity';
|
|
|
import { Product } from '../../../entity/product/product.entity';
|
|
|
-import { CollectionService } from '../../../service';
|
|
|
+import { CollectionService, FacetService } from '../../../service';
|
|
|
import { FacetValueService } from '../../../service/services/facet-value.service';
|
|
|
import { ProductVariantService } from '../../../service/services/product-variant.service';
|
|
|
import { ProductService } from '../../../service/services/product.service';
|
|
|
@@ -28,6 +31,7 @@ export class ShopProductsResolver {
|
|
|
private productVariantService: ProductVariantService,
|
|
|
private facetValueService: FacetValueService,
|
|
|
private collectionService: CollectionService,
|
|
|
+ private facetService: FacetService,
|
|
|
) {}
|
|
|
|
|
|
@Query()
|
|
|
@@ -109,4 +113,31 @@ export class ShopProductsResolver {
|
|
|
async search(...args: any): Promise<Omit<SearchResponse, 'facetValues'>> {
|
|
|
throw new InternalServerError(`error.no-search-plugin-configured`);
|
|
|
}
|
|
|
+
|
|
|
+ @Query()
|
|
|
+ async facets(
|
|
|
+ @Ctx() ctx: RequestContext,
|
|
|
+ @Args() args: QueryFacetsArgs,
|
|
|
+ ): Promise<PaginatedList<Translated<Facet>>> {
|
|
|
+ const options: ListQueryOptions<Facet> = {
|
|
|
+ ...args.options,
|
|
|
+ filter: {
|
|
|
+ ...(args.options && args.options.filter),
|
|
|
+ isPrivate: { eq: false },
|
|
|
+ },
|
|
|
+ };
|
|
|
+ return this.facetService.findAll(ctx, options || undefined);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Query()
|
|
|
+ async facet(
|
|
|
+ @Ctx() ctx: RequestContext,
|
|
|
+ @Args() args: QueryFacetArgs,
|
|
|
+ ): Promise<Translated<Facet> | undefined> {
|
|
|
+ const facet = await this.facetService.findOne(ctx, args.id);
|
|
|
+ if (facet && facet.isPrivate) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ return facet;
|
|
|
+ }
|
|
|
}
|