Skip to content

Instantly share code, notes, and snippets.

@tyrw
Created December 19, 2019 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyrw/c7d5b60f56a04fadcb9a9baa89eb3c10 to your computer and use it in GitHub Desktop.
Save tyrw/c7d5b60f56a04fadcb9a9baa89eb3c10 to your computer and use it in GitHub Desktop.
// As stored in state variable
facets = {
operator: 'AND',
filterGroups: [
{
operator: 'AND',
filters: [
{
attribute: 'name',
comparator: '$iLike',
value: 'John'
},
{
attribute: 'lastActiveAt',
comparator: '$between',
value: ['Thu Dec 12 2019 11:59:27 GMT-0800', 'Thu Dec 19 2019 11:59:27 GMT-0800']
}
]
},
{
operator: 'AND',
filters: [
{
attribute: 'userId',
comparator: '$gte',
value: 20
}
]
}
]
}
// Function to convert facets into query
fn(facets)
=>
{
$and: [
$and: [
name: { $iLike: 'John' },
lastActiveAt: { $between: ['Thu Dec 12 2019 11:59:27 GMT-0800', 'Thu Dec 19 2019 11:59:27 GMT-0800'] }
],
$and: [
userId: { $gte: 20 }
]
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment