From 3adf37e6a5eff7cdfcf4d08e69ceed160211dc79 Mon Sep 17 00:00:00 2001 From: Martin Zanoni Date: Thu, 27 Jun 2024 15:10:05 +0200 Subject: [PATCH] feat: add filters --- packages/client/src/builders/filterBuilder.ts | 99 ++++++++++++++++++- .../builders/filters/brandFilterBuilder.ts | 43 +++++++- .../builders/filters/companyFilterBuilder.ts | 43 +++++++- .../builders/filters/contentFilterBuilder.ts | 58 ++++++++++- .../builders/filters/productFilterBuilder.ts | 58 ++++++++++- .../builders/filters/variantFilterBuilder.ts | 43 +++++++- 6 files changed, 336 insertions(+), 8 deletions(-) diff --git a/packages/client/src/builders/filterBuilder.ts b/packages/client/src/builders/filterBuilder.ts index 86fd164..ef8fecb 100644 --- a/packages/client/src/builders/filterBuilder.ts +++ b/packages/client/src/builders/filterBuilder.ts @@ -242,7 +242,7 @@ export class FilterBuilder { const internalSettingsBuilder = new FilterSettingsBuilder(); options?.filterSettings?.(internalSettingsBuilder); - + const filters = builder.build(); if (filters === null || filters.items === undefined || filters.items === null || filters.items.length <= 0) { throw new Error('And-filters must contain at least 1 filter'); @@ -265,7 +265,7 @@ export class FilterBuilder { const internalSettingsBuilder = new FilterSettingsBuilder(); options?.filterSettings?.(internalSettingsBuilder); - + const filters = builder.build(); if (filters === null || filters.items === undefined || filters.items === null || filters.items.length <= 0) { throw new Error('Or-filters must contain at least 1 filter'); @@ -335,7 +335,7 @@ export class FilterBuilder { const internalSettingsBuilder = new FilterSettingsBuilder(); options?.filterSettings?.(internalSettingsBuilder); - + const filter: CartDataFilter = { $type: 'Relewise.Client.Requests.Filters.CartDataFilter, Relewise.Client', key: key, @@ -525,6 +525,99 @@ export class FilterBuilder { return this; } + /** + * Adds a brand has key filter to the request + * @param key + * @param negated + * @param options + */ + public addBrandDataHasKeyFilter(key: string, negated: boolean = false, options?: FilterOptions): this { + this.brandFilterBuilder.addBrandDataHasKeyFilter(key, negated, options); + return this; + } + + /** + * Adds a brand is disabled filter to the request - only works for product queries, not in searches or recommendations + * @param key + * @param negated + * @param options + */ + public addBrandDisabledFilter(negated: boolean = false, options?: FilterOptions): this { + this.brandFilterBuilder.addBrandDisabledFilter(negated, options); + return this; + } + + /** + * Adds a company has key filter to the request + * @param key + * @param negated + * @param options + */ + public addCompanyDataHasKeyFilter(key: string, negated: boolean = false, options?: FilterOptions): this { + this.companyFilterBuilder.addCompanyDataHasKeyFilter(key, negated, options); + return this; + } + + /** + * Adds a company is disabled filter to the request - only works for product queries, not in searches or recommendations + * @param key + * @param negated + * @param options + */ + public addCompanyDisabledFilter(negated: boolean = false, options?: FilterOptions): this { + this.companyFilterBuilder.addCompanyDisabledFilter(negated, options); + return this; + } + + /** + * Adds a variant has key filter to the request + * @param key + * @param negated + * @param options + */ + public addVariantDataHasKeyFilter(key: string, negated: boolean = false, options?: FilterOptions): this { + this.variantFilterBuilder.addVariantDataHasKeyFilter(key, negated, options); + return this; + } + + /** + * Adds a variant is disabled filter to the request - only works for product queries, not in searches or recommendations + * @param key + * @param negated + * @param options + */ + public addVariantDisabledFilter(negated: boolean = false, options?: FilterOptions): this { + this.variantFilterBuilder.addVariantDisabledFilter(negated, options); + return this; + } + + /** + * Adds a content category has key filter to the request + * @param key + * @param negated + * @param options + */ + public addContentCategoryDataHasKeyFilter(key: string, negated: boolean = false, options?: FilterOptions): this { + this.contentFilterBuilder.addContentCategoryDataHasKeyFilter(key, negated, options); + return this; + } + + /** + * Adds a content category is disabled filter to the request - only works for product queries, not in searches or recommendations + * @param key + * @param negated + * @param options + */ + public addContentCategoryDisabledFilter(negated: boolean = false, options?: FilterOptions): this { + this.contentFilterBuilder.addContentCategoryDisabledFilter(negated, options); + return this; + } + + public addContentCategoryRecentlyViewedByUserFilter(sinceMinutesAgo: number, negated: boolean = false, options?: FilterOptions): this { + this.contentFilterBuilder.addContentCategoryRecentlyViewedByUserFilter(sinceMinutesAgo, negated, options); + return this; + } + public reset(): this { this.filters = []; this.productFilterBuilder.reset(); diff --git a/packages/client/src/builders/filters/brandFilterBuilder.ts b/packages/client/src/builders/filters/brandFilterBuilder.ts index 0fac440..e3fdb08 100644 --- a/packages/client/src/builders/filters/brandFilterBuilder.ts +++ b/packages/client/src/builders/filters/brandFilterBuilder.ts @@ -1,4 +1,4 @@ -import { BrandAssortmentFilter, BrandDataFilter, BrandIdFilter } from 'src/models/data-contracts'; +import { BrandAssortmentFilter, BrandDataFilter, BrandDataHasKeyFilter, BrandDisabledFilter, BrandIdFilter } from 'src/models/data-contracts'; import { ConditionBuilder } from '../conditionBuilder'; import { EntityDataFilterOptions, FilterOptions } from './filters.types.shared'; import { FilterSettingsBuilder } from '../filterSettingsBuilder'; @@ -84,4 +84,45 @@ export class BrandFilterBuilder extends FilterBuilderBase { return this; } + + /** + * Adds a brand has key filter to the request + * @param key + * @param negated + * @param options + */ + public addBrandDataHasKeyFilter(key: string, negated: boolean = false, options?: FilterOptions): this { + const internalSettingsBuilder = new FilterSettingsBuilder(); + options?.filterSettings?.(internalSettingsBuilder); + + const filter: BrandDataHasKeyFilter = { + $type: 'Relewise.Client.Requests.Filters.BrandDataHasKeyFilter, Relewise.Client', + key: key, + negated: negated, + settings: internalSettingsBuilder.build(), + }; + this.filters.push(filter); + + return this; + } + + /** + * Adds a brand is disabled filter to the request - only works for product queries, not in searches or recommendations + * @param key + * @param negated + * @param options + */ + public addBrandDisabledFilter(negated: boolean = false, options?: FilterOptions): this { + const internalSettingsBuilder = new FilterSettingsBuilder(); + options?.filterSettings?.(internalSettingsBuilder); + + const filter: BrandDisabledFilter = { + $type: 'Relewise.Client.Requests.Filters.BrandDisabledFilter, Relewise.Client', + negated: negated, + settings: internalSettingsBuilder.build(), + }; + this.filters.push(filter); + + return this; + } } diff --git a/packages/client/src/builders/filters/companyFilterBuilder.ts b/packages/client/src/builders/filters/companyFilterBuilder.ts index 29c4c9d..bab112f 100644 --- a/packages/client/src/builders/filters/companyFilterBuilder.ts +++ b/packages/client/src/builders/filters/companyFilterBuilder.ts @@ -1,4 +1,4 @@ -import { CompanyDataFilter, CompanyIdFilter } from 'src/models/data-contracts'; +import { CompanyDataFilter, CompanyDataHasKeyFilter, CompanyDisabledFilter, CompanyIdFilter } from 'src/models/data-contracts'; import { ConditionBuilder } from '../conditionBuilder'; import { FilterSettingsBuilder } from '../filterSettingsBuilder'; import { FilterBuilderBase } from './filterBuilderBase'; @@ -60,4 +60,45 @@ export class CompanyFilterBuilder extends FilterBuilderBase