Skip to content

Commit

Permalink
feat(core): Add facetValueId filter to products/variants list queries
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed May 15, 2023
1 parent 5f3f2f4 commit 00b8268
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4126,6 +4126,7 @@ export type ProductFilterParameter = {
createdAt?: InputMaybe<DateOperators>;
description?: InputMaybe<StringOperators>;
enabled?: InputMaybe<BooleanOperators>;
facetValueId?: InputMaybe<IdOperators>;
id?: InputMaybe<IdOperators>;
languageCode?: InputMaybe<StringOperators>;
name?: InputMaybe<StringOperators>;
Expand Down Expand Up @@ -4283,6 +4284,7 @@ export type ProductVariantFilterParameter = {
createdAt?: InputMaybe<DateOperators>;
currencyCode?: InputMaybe<StringOperators>;
enabled?: InputMaybe<BooleanOperators>;
facetValueId?: InputMaybe<IdOperators>;
id?: InputMaybe<IdOperators>;
languageCode?: InputMaybe<StringOperators>;
name?: InputMaybe<StringOperators>;
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4351,6 +4351,7 @@ export type ProductFilterParameter = {
createdAt?: InputMaybe<DateOperators>;
description?: InputMaybe<StringOperators>;
enabled?: InputMaybe<BooleanOperators>;
facetValueId?: InputMaybe<IdOperators>;
id?: InputMaybe<IdOperators>;
languageCode?: InputMaybe<StringOperators>;
name?: InputMaybe<StringOperators>;
Expand Down Expand Up @@ -4517,6 +4518,7 @@ export type ProductVariantFilterParameter = {
createdAt?: InputMaybe<DateOperators>;
currencyCode?: InputMaybe<StringOperators>;
enabled?: InputMaybe<BooleanOperators>;
facetValueId?: InputMaybe<IdOperators>;
id?: InputMaybe<IdOperators>;
languageCode?: InputMaybe<StringOperators>;
name?: InputMaybe<StringOperators>;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/e2e/graphql/generated-e2e-admin-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4126,6 +4126,7 @@ export type ProductFilterParameter = {
createdAt?: InputMaybe<DateOperators>;
description?: InputMaybe<StringOperators>;
enabled?: InputMaybe<BooleanOperators>;
facetValueId?: InputMaybe<IdOperators>;
id?: InputMaybe<IdOperators>;
languageCode?: InputMaybe<StringOperators>;
name?: InputMaybe<StringOperators>;
Expand Down Expand Up @@ -4283,6 +4284,7 @@ export type ProductVariantFilterParameter = {
createdAt?: InputMaybe<DateOperators>;
currencyCode?: InputMaybe<StringOperators>;
enabled?: InputMaybe<BooleanOperators>;
facetValueId?: InputMaybe<IdOperators>;
id?: InputMaybe<IdOperators>;
languageCode?: InputMaybe<StringOperators>;
name?: InputMaybe<StringOperators>;
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/api/schema/admin-api/product.api.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,17 @@ input StockMovementListOptions {
# generated by generateListOptions function
input ProductListOptions

input ProductFilterParameter {
facetValueId: IDOperators
}

# generated by generateListOptions function
input ProductVariantListOptions

input ProductVariantFilterParameter {
facetValueId: IDOperators
}

input ProductTranslationInput {
id: ID
languageCode: LanguageCode!
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/service/services/product-variant.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
DeletionResult,
GlobalFlag,
Permission,
ProductListOptions,
ProductVariantListOptions,
RemoveProductVariantsFromChannelInput,
UpdateProductVariantInput,
} from '@vendure/common/lib/generated-types';
Expand Down Expand Up @@ -88,12 +90,19 @@ export class ProductVariantService {
options?: ListQueryOptions<ProductVariant>,
): Promise<PaginatedList<Translated<ProductVariant>>> {
const relations = ['featuredAsset', 'taxCategory', 'channels'];
const customPropertyMap: { [name: string]: string } = {};
const hasFacetValueIdFilter = !!(options as ProductVariantListOptions)?.filter?.facetValueId;
if (hasFacetValueIdFilter) {
relations.push('facetValues');
customPropertyMap.facetValueId = 'facetValues.id';
}
return this.listQueryBuilder
.build(ProductVariant, options, {
relations,
channelId: ctx.channelId,
where: { deletedAt: IsNull() },
ctx,
customPropertyMap,
})
.getManyAndCount()
.then(async ([variants, totalItems]) => {
Expand Down
12 changes: 11 additions & 1 deletion packages/core/src/service/services/product.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { Injectable } from '@nestjs/common';
import {
AssignProductsToChannelInput,
CreateProductInput,
CustomerListOptions,
DeletionResponse,
DeletionResult,
ProductListOptions,
RemoveOptionGroupFromProductResult,
RemoveProductsFromChannelInput,
UpdateProductInput,
Expand Down Expand Up @@ -78,12 +80,20 @@ export class ProductService {
options?: ListQueryOptions<Product>,
relations?: RelationPaths<Product>,
): Promise<PaginatedList<Translated<Product>>> {
const effectiveRelations = relations || this.relations;
const customPropertyMap: { [name: string]: string } = {};
const hasFacetValueIdFilter = !!(options as ProductListOptions)?.filter?.facetValueId;
if (hasFacetValueIdFilter) {
effectiveRelations.push('facetValues');
customPropertyMap.facetValueId = 'facetValues.id';
}
return this.listQueryBuilder
.build(Product, options, {
relations: relations || this.relations,
relations: effectiveRelations,
channelId: ctx.channelId,
where: { deletedAt: IsNull() },
ctx,
customPropertyMap,
})
.getManyAndCount()
.then(async ([products, totalItems]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4126,6 +4126,7 @@ export type ProductFilterParameter = {
createdAt?: InputMaybe<DateOperators>;
description?: InputMaybe<StringOperators>;
enabled?: InputMaybe<BooleanOperators>;
facetValueId?: InputMaybe<IdOperators>;
id?: InputMaybe<IdOperators>;
languageCode?: InputMaybe<StringOperators>;
name?: InputMaybe<StringOperators>;
Expand Down Expand Up @@ -4283,6 +4284,7 @@ export type ProductVariantFilterParameter = {
createdAt?: InputMaybe<DateOperators>;
currencyCode?: InputMaybe<StringOperators>;
enabled?: InputMaybe<BooleanOperators>;
facetValueId?: InputMaybe<IdOperators>;
id?: InputMaybe<IdOperators>;
languageCode?: InputMaybe<StringOperators>;
name?: InputMaybe<StringOperators>;
Expand Down
2 changes: 2 additions & 0 deletions packages/payments-plugin/e2e/graphql/generated-admin-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4126,6 +4126,7 @@ export type ProductFilterParameter = {
createdAt?: InputMaybe<DateOperators>;
description?: InputMaybe<StringOperators>;
enabled?: InputMaybe<BooleanOperators>;
facetValueId?: InputMaybe<IdOperators>;
id?: InputMaybe<IdOperators>;
languageCode?: InputMaybe<StringOperators>;
name?: InputMaybe<StringOperators>;
Expand Down Expand Up @@ -4283,6 +4284,7 @@ export type ProductVariantFilterParameter = {
createdAt?: InputMaybe<DateOperators>;
currencyCode?: InputMaybe<StringOperators>;
enabled?: InputMaybe<BooleanOperators>;
facetValueId?: InputMaybe<IdOperators>;
id?: InputMaybe<IdOperators>;
languageCode?: InputMaybe<StringOperators>;
name?: InputMaybe<StringOperators>;
Expand Down
2 changes: 1 addition & 1 deletion schema-admin.json

Large diffs are not rendered by default.

0 comments on commit 00b8268

Please sign in to comment.