diegohaz / querymen

Querystring parser middleware for MongoDB, Express and Nodejs (MEN)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple filters same path custom schema

chemitaxis opened this issue · comments

commented

Hi, if you add this to the middleware:

query({
    after: {
      type: Date,
      paths: ['DateInvoice'],
      operator: '$gte'
    },
    before: {
      type: Date,
      paths: ['DateInvoice'],
      operator: '$lte'
    }
  }),

Just the last is working, the first (after) is ignored... Any ideas? Thanks

commented

Hi @diegohaz Did you have time to check this? Thank you so much!!

commented

Here you have a test failing the issue:

request(
        route(
          new querymen.Schema({
            before: {
              type: Date,
              operator: '$lte',
              paths: ['createdAt']
            },
            after: {
              type: Date,
              operator: '$gte',
              paths: ['createdAt']
            }
          })
        )
      )
        .get('/tests')
        .query({ after: '2016-04-22T10:00', before: '2016-04-23T09:00' })
        .expect(200)
        .end((err, res) => {
          if (err) throw err
          t.equal(res.body.length, 1, 'should respond with 1 item')
          t.equal(
            res.body[0].title,
            'nice!',
            'should respond with item after date and before date'
          )
        })
commented

Could you start a PR with that test so we can try to pass it?

commented

of course ;)

commented

Done ;) Thanks @diegohaz

commented

Hi @diegohaz did you have time to check my PR? Thanks!

commented

I'm not able to do that right now. Will check that as soon as possible.

commented

Fixed in #44