0

an object(i.e. request.query) must contain these keys and with keys they must have truthy values

const invoice_query_params = [
                'invoice_id',
                'invoice_receipt',
                'invoice_status',
                'payment_id',
                'signature' 
            ];

2
  • you can use Object.hasOwnProperty() here Commented Jan 31, 2021 at 12:59
  • yeah i have done that part but also need to check for falsy value invoice_query_params.every(param => req.query.hasOwnProperty(param) Commented Jan 31, 2021 at 12:59

2 Answers 2

1

Below function with the object as a parameter should check if that object contains every array element as a parameter and the value of it is not falsy.

const checkKeysAndValues = (yourObject) => invoice_query_params.every(param => yourObject.hasOwnProperty(param) && yourObject[param])
Sign up to request clarification or add additional context in comments.

Comments

0

Just test hasOwnProperty and for truthy values of course this will exclude anything that evaluates as falsy and accept anything that evaluates as truthy.

const invoice_query_params = [
                'invoice_id',
                'invoice_receipt',
                'invoice_status',
                'payment_id',
                'signature' 
            ];
let ok = true; 
for(var i=0; i < invoice_query_params.lengh; i++){
  if (request.query.hasOwnProperty(invoice_query_params[i]){
     if(!request.query[invoice_query_param[i]]){
        ok = false; 
     } 
  }
}

if (ok){
  // all were truthy so do something.
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.