This repository has been archived by the owner on May 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #429 from icmaa/feature/refactor-storefront-query-…
…builder Update to `storefront-query-builder` version `1.0.0`
- Loading branch information
Showing
9 changed files
with
142 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/api/extensions/example-custom-filter/filter/catalog/SampleFilter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { FilterInterface } from 'storefront-query-builder' | ||
|
||
const filter: FilterInterface = { | ||
priority: 1, | ||
check: ({ operator, value, attribute, queryChain }) => attribute === 'custom-filter-name', | ||
filter ({ value, attribute, operator, queryChain }) { | ||
// Do you custom filter logic like: queryChain.filter('terms', attribute, value) | ||
return queryChain | ||
}, | ||
mutator: (value) => typeof value !== 'object' ? { 'in': [value] } : value | ||
} | ||
|
||
export default filter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Router } from 'express' | ||
|
||
module.exports = () => { | ||
let exampleFilter = Router() | ||
return exampleFilter | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import path from 'path' | ||
|
||
export default async function loadModuleCustomFilters (config: Record<string, any>, type: string = 'catalog'): Promise<any> { | ||
let filters: any = {} | ||
let filterPromises: Promise<any>[] = [] | ||
|
||
for (const mod of config.registeredExtensions) { | ||
if (config.extensions.hasOwnProperty(mod) && config.extensions[mod].hasOwnProperty(type + 'Filter') && Array.isArray(config.extensions[mod][type + 'Filter'])) { | ||
const moduleFilter = config.extensions[mod][type + 'Filter'] | ||
const dirPath = [__dirname, '../api/extensions/' + mod + '/filter/', type] | ||
for (const filterName of moduleFilter) { | ||
const filePath = path.resolve(...dirPath, filterName) | ||
filterPromises.push( | ||
import(filePath) | ||
.then(module => { | ||
filters[filterName] = module.default | ||
}) | ||
.catch(e => { | ||
console.log(e) | ||
}) | ||
) | ||
} | ||
} | ||
} | ||
|
||
return Promise.all(filterPromises).then((e) => filters) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters