Skip to content

Commit

Permalink
feat: add filters
Browse files Browse the repository at this point in the history
  • Loading branch information
mzanoni committed Jun 27, 2024
1 parent eeb8b6e commit 3adf37e
Show file tree
Hide file tree
Showing 6 changed files with 336 additions and 8 deletions.
99 changes: 96 additions & 3 deletions packages/client/src/builders/filterBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
43 changes: 42 additions & 1 deletion packages/client/src/builders/filters/brandFilterBuilder.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -84,4 +84,45 @@ export class BrandFilterBuilder extends FilterBuilderBase<BrandFilterBuilder> {

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;
}
}
43 changes: 42 additions & 1 deletion packages/client/src/builders/filters/companyFilterBuilder.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -60,4 +60,45 @@ export class CompanyFilterBuilder extends FilterBuilderBase<CompanyFilterBuilder

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 {
const internalSettingsBuilder = new FilterSettingsBuilder();
options?.filterSettings?.(internalSettingsBuilder);

const filter: CompanyDataHasKeyFilter = {
$type: 'Relewise.Client.Requests.Filters.CompanyDataHasKeyFilter, Relewise.Client',
key: key,
negated: negated,
settings: internalSettingsBuilder.build(),
};
this.filters.push(filter);

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 {
const internalSettingsBuilder = new FilterSettingsBuilder();
options?.filterSettings?.(internalSettingsBuilder);

const filter: CompanyDisabledFilter = {
$type: 'Relewise.Client.Requests.Filters.CompanyDisabledFilter, Relewise.Client',
negated: negated,
settings: internalSettingsBuilder.build(),
};
this.filters.push(filter);

return this;
}
}
58 changes: 57 additions & 1 deletion packages/client/src/builders/filters/contentFilterBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContentAssortmentFilter, ContentCategoryAssortmentFilter, ContentCategoryHasAncestorFilter, ContentCategoryHasChildFilter, ContentCategoryHasContentsFilter, ContentCategoryHasParentFilter, ContentCategoryIdFilter, ContentCategoryLevelFilter, ContentCategoryDataFilter, ContentDataFilter, ContentIdFilter } from 'src/models/data-contracts';
import { ContentAssortmentFilter, ContentCategoryAssortmentFilter, ContentCategoryHasAncestorFilter, ContentCategoryHasChildFilter, ContentCategoryHasContentsFilter, ContentCategoryHasParentFilter, ContentCategoryIdFilter, ContentCategoryLevelFilter, ContentCategoryDataFilter, ContentDataFilter, ContentIdFilter, ContentCategoryDataHasKeyFilter, ContentCategoryDisabledFilter, ContentCategoryRecentlyViewedByUserFilter } from 'src/models/data-contracts';
import { ConditionBuilder } from '../conditionBuilder';
import { EntityDataFilterOptions, FilterOptions } from './filters.types.shared';
import { FilterSettingsBuilder } from '../filterSettingsBuilder';
Expand Down Expand Up @@ -263,4 +263,60 @@ export class ContentFilterBuilder extends FilterBuilderBase<ContentFilterBuilder

return this;
}

/**
* Adds a contentCategory has key filter to the request
* @param key
* @param negated
* @param options
*/
public addContentCategoryDataHasKeyFilter(key: string, negated: boolean = false, options?: FilterOptions): this {
const internalSettingsBuilder = new FilterSettingsBuilder();
options?.filterSettings?.(internalSettingsBuilder);

const filter: ContentCategoryDataHasKeyFilter = {
$type: 'Relewise.Client.Requests.Filters.ContentCategoryDataHasKeyFilter, Relewise.Client',
key: key,
negated: negated,
settings: internalSettingsBuilder.build(),
};
this.filters.push(filter);

return this;
}

/**
* Adds a contentCategory 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 {
const internalSettingsBuilder = new FilterSettingsBuilder();
options?.filterSettings?.(internalSettingsBuilder);

const filter: ContentCategoryDisabledFilter = {
$type: 'Relewise.Client.Requests.Filters.ContentCategoryDisabledFilter, Relewise.Client',
negated: negated,
settings: internalSettingsBuilder.build(),
};
this.filters.push(filter);

return this;
}

public addContentCategoryRecentlyViewedByUserFilter(sinceMinutesAgo: number, negated: boolean = false, options?: FilterOptions): this {
const internalSettingsBuilder = new FilterSettingsBuilder();
options?.filterSettings?.(internalSettingsBuilder);

const filter: ContentCategoryRecentlyViewedByUserFilter = {
$type: 'Relewise.Client.Requests.Filters.ContentCategoryRecentlyViewedByUserFilter, Relewise.Client',
sinceMinutesAgo: sinceMinutesAgo,
negated: negated,
settings: internalSettingsBuilder.build(),
};
this.filters.push(filter);

return this;
}
}
58 changes: 57 additions & 1 deletion packages/client/src/builders/filters/productFilterBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ProductAndVariantIdFilter, ProductAssortmentFilter, ProductCategoryAssortmentFilter, ProductCategoryHasAncestorFilter, ProductCategoryHasChildFilter, ProductCategoryHasParentFilter, ProductCategoryHasProductsFilter, ProductCategoryIdFilter, ProductCategoryLevelFilter, ProductDataFilter, ProductDisplayNameFilter, ProductHasVariantsFilter, ProductIdFilter, ProductListPriceFilter, ProductRecentlyPurchasedByUserFilter, ProductRecentlyViewedByUserFilter, ProductSalesPriceFilter, ProductAndVariantId, ProductCategoryDataFilter } from 'src/models/data-contracts';
import { ProductAndVariantIdFilter, ProductAssortmentFilter, ProductCategoryAssortmentFilter, ProductCategoryHasAncestorFilter, ProductCategoryHasChildFilter, ProductCategoryHasParentFilter, ProductCategoryHasProductsFilter, ProductCategoryIdFilter, ProductCategoryLevelFilter, ProductDataFilter, ProductDisplayNameFilter, ProductHasVariantsFilter, ProductIdFilter, ProductListPriceFilter, ProductRecentlyPurchasedByUserFilter, ProductRecentlyViewedByUserFilter, ProductSalesPriceFilter, ProductAndVariantId, ProductCategoryDataFilter, ProductCategoryDataHasKeyFilter, ProductCategoryDisabledFilter, ProductCategoryRecentlyViewedByUserFilter } from 'src/models/data-contracts';
import { ConditionBuilder } from '../conditionBuilder';
import { EntityDataFilterOptions, FilterOptions } from './filters.types.shared';
import { FilterSettingsBuilder } from '../filterSettingsBuilder';
Expand Down Expand Up @@ -423,4 +423,60 @@ export class ProductFilterBuilder extends FilterBuilderBase<ProductFilterBuilder

return this;
}

/**
* Adds a product category has key filter to the request
* @param key
* @param negated
* @param options
*/
public addProductCategoryDataHasKeyFilter(key: string, negated: boolean = false, options?: FilterOptions): this {
const internalSettingsBuilder = new FilterSettingsBuilder();
options?.filterSettings?.(internalSettingsBuilder);

const filter: ProductCategoryDataHasKeyFilter = {
$type: 'Relewise.Client.Requests.Filters.ProductCategoryDataHasKeyFilter, Relewise.Client',
key: key,
negated: negated,
settings: internalSettingsBuilder.build(),
};
this.filters.push(filter);

return this;
}

/**
* Adds a product category is disabled filter to the request - only works for product queries, not in searches or recommendations
* @param key
* @param negated
* @param options
*/
public addProductCategoryDisabledFilter(negated: boolean = false, options?: FilterOptions): this {
const internalSettingsBuilder = new FilterSettingsBuilder();
options?.filterSettings?.(internalSettingsBuilder);

const filter: ProductCategoryDisabledFilter = {
$type: 'Relewise.Client.Requests.Filters.ProductCategoryDisabledFilter, Relewise.Client',
negated: negated,
settings: internalSettingsBuilder.build(),
};
this.filters.push(filter);

return this;
}

public addProductCategoryRecentlyViewedByUserFilter(sinceMinutesAgo: number, negated: boolean = false, options?: FilterOptions): this {
const internalSettingsBuilder = new FilterSettingsBuilder();
options?.filterSettings?.(internalSettingsBuilder);

const filter: ProductCategoryRecentlyViewedByUserFilter = {
$type: 'Relewise.Client.Requests.Filters.ProductCategoryRecentlyViewedByUserFilter, Relewise.Client',
sinceMinutesAgo: sinceMinutesAgo,
negated: negated,
settings: internalSettingsBuilder.build(),
};
this.filters.push(filter);

return this;
}
}
Loading

0 comments on commit 3adf37e

Please sign in to comment.