Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom schema remember previous value #30

Open
dbartumeu opened this issue Jan 30, 2017 · 11 comments
Open

Custom schema remember previous value #30

dbartumeu opened this issue Jan 30, 2017 · 11 comments

Comments

@dbartumeu
Copy link

Hi:

I'm using a custom schema like this

new querymen.Schema({
    store: {
        type: RegExp,
        paths: ['store'],
        normalize: true,
    },
});

If I made a request like this:
myurl.com/stores/?store=amazon, everithing is ok, but if I made a request after, but without any params: myurl.com/stores/, for some reason i keep getting this { store: /amazon/i } in my query

Is there a way to fix this behavior? or maybe I'm missing somethings.

best regards.

@isaacvitor
Copy link

I had the same problem. I did everything but nothing yet...

Tnks

@diegohaz
Copy link
Owner

diegohaz commented Feb 20, 2017

Sorry about the delay. Could you please post the full code of what you're doing (including express middleware)?

@isaacvitor
Copy link

isaacvitor commented Feb 21, 2017

In my case this is my express config:

module.exports = function (config, arrayDB) {
  const app = express()
  app.set('port', config.port)
  app.use(helmet())
  app.use(cors())

  app.use(bodyParser.urlencoded({
    extended: true
  }))
  app.use(bodyParser.json())
  app.use(methodOverride())
  app.set('secretKey', config.secretKey)
  app.use(express.static('public'))
  app.use((req, res, next) => {
    debug(req.method + ' - ' + req.url)
    next()
  })

  app.set('sqlConnectorOperacional', arrayDB[0])
  app.set('sqlConnectorFinanceiro', arrayDB[1])

  load('models')
    .then('controllers')
    .then('routes')
    .into(app)

  return app
}

and this is a route where I use querymen:

const querymen = require('querymen')

module.exports = function (app) {
  const controller = app.controllers.relatorio

  let logSchema = {
    limit: 100,
    sort: '-created_on',
    codigo: Number,
    find: {
      type: RegExp,
      paths: [
        'operacao',
        'usuario.nome',
        'usuario.email',
        'relatorio.cartao.cpf',
        'relatorio.cartao.matricula'
      ],
      bindTo: 'query'
    },
    after: {
      type: Date,
      paths: [ 'created_on' ],
      operator: '$gte'
    },
    before: {
      type: Date,
      paths: [ 'created_on' ],
      operator: '$lte'
    }
  }
  // Log
  app.route('/api/relatorio/log')
    .get(querymen.middleware(logSchema), controller.list)
}

@diegohaz
Copy link
Owner

diegohaz commented Feb 21, 2017

@isaacvitor I can't reproduce it. What exactly is happening? Is this happening with all schema parameters?

It would be nice to have a minimum repo with a reproduction.

@isaacvitor
Copy link

@diegohaz you're right, really you would cannot reproduce it. Unfortunately I can't put it in a repo.
I don't understand why occurs some kind of cache. I realized that this occurs intermittently.

@kirillbuga
Copy link

I also faced with the same issue. I will try to prepare a small repo with example

@netocp
Copy link

netocp commented May 29, 2017

Have the same issue here.
const userSchema = new Schema({ limit: { max: 1000, default: 20 }, category: { type: String, bindTo: 'select' } })

@agallardol
Copy link

agallardol commented Jul 7, 2017

I have the same problem, has anyone solved the problem?

I will try to review the source code to see if I can fix it.

agallardol added a commit to agallardol/querymen that referenced this issue Jul 7, 2017
Solved problem described in diegohaz#30
@agallardol
Copy link

I solved this problem in #47

@chemitaxis
Copy link
Collaborator

Hi guys, I have solved this issue with this pull request, and all the test is passing ;)

@drochag
Copy link

drochag commented May 3, 2018

Check PR #52 , you might find workarounds there and further discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants