jeudi 30 mars 2017

Conditionally set a object property

Its possible to remove the .where clause if queryString is null?

I have tried ternary operator in the middle of expression, but doesn't work.

Also the equals expression dont allow: null, undefined or empty String.

CashierHistory
            .scan()
            .where('userId').equals(path['userId'])
            .where('status').equals(queryString['status']) # remove all this line in case of queryString['status'] is null
            .limit(10)
            .startKey(queryString)
            .exec(function (err, acc) {
                if (err == null) {
                    console.log(acc);
                    return cb(null, Api.response(acc));
                } else {
                    console.log(err['message']);
                    return cb(null, Api.errors(200, {5: err['message']}));
                }
            });

Aucun commentaire:

Enregistrer un commentaire