commerce/framework/reactioncommerce/api/utils/get-sort-variables.ts
Loan Laux c2c43b76aa
refactor category and brand filtering logic
Signed-off-by: Loan Laux <loan@outgrow.io>
2021-07-07 19:16:45 +03:00

33 lines
635 B
TypeScript

const getSortVariables = (sort?: string, isCategory = false) => {
let output = {}
switch (sort) {
case 'price-asc':
output = {
sortKey: 'PRICE',
reverse: false,
}
break
case 'price-desc':
output = {
sortKey: 'PRICE',
reverse: true,
}
break
case 'trending-desc':
output = {
sortKey: 'BEST_SELLING',
reverse: false,
}
break
case 'latest-desc':
output = {
sortKey: isCategory ? 'CREATED' : 'CREATED_AT',
reverse: true,
}
break
}
return output
}
export default getSortVariables