mirror of
https://github.com/vercel/commerce.git
synced 2025-05-19 16:07:01 +00:00
35 lines
608 B
TypeScript
35 lines
608 B
TypeScript
import getSortVariables from './get-sort-variables'
|
|
import type { SearchProductsInput } from '../product/use-search'
|
|
|
|
export const getSearchVariables = ({
|
|
brandId,
|
|
search,
|
|
categoryId,
|
|
sort,
|
|
}: SearchProductsInput) => {
|
|
let searchQuery = ''
|
|
let tagIdsParam = {}
|
|
|
|
if (search) {
|
|
searchQuery += search
|
|
}
|
|
|
|
if (brandId) {
|
|
searchQuery += `${search ? ' ' : ''}${brandId}`
|
|
}
|
|
|
|
if (categoryId) {
|
|
tagIdsParam = {
|
|
tagIds: [categoryId],
|
|
}
|
|
}
|
|
|
|
return {
|
|
searchQuery,
|
|
...tagIdsParam,
|
|
...getSortVariables(sort, !!categoryId),
|
|
}
|
|
}
|
|
|
|
export default getSearchVariables
|