How to get clause from segment in smart collection route

Hi!

I have created a smart collection, I want to create smart segments, how do I retrieve the “where” clause of my segment when I’m in the route of /myCollection list function ?

request.query.segment only contains the name of the segment :stuck_out_tongue:

Thank you :slight_smile:

At this time I have created a variable that knows the condition of each segment:

const segmentCondition = {
    'Active': {
      activeFrom: {
        [Op.ne]: null
      },
      activeTo: null
    },
    'Dafts ✏️': {
      activeFrom: null,
      activeTo: null
    }
  }

And then put it inside the WHERE clause:

const list = await models.someTable.findAll({
    where: { 
     ...
      ...segmentCondition[request.query.segment]
    }
  })

but if there’s is a cleaner way to get my where clause directly from /forest folder, please HMU :stuck_out_tongue:

Hey @Simon_BRAMI1 :wave:

I’m not totally sure to have understand your issue.
Do you want to create a Smart Segment on your Smart Collection? If that’s the case, I’m guessing that your mentioned solution would be the way to go.

What bother you in your current implementation?

Thanks in advance :pray:

Hi jeff,

I just wanted to avoid duplicate code if there was a method to retrieve the where condition directly into my route !
But anyways that solution works just fine :wink:

Thank you!

1 Like