×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

--How to implement req.body.param validation

--How to implement req.body.param validation

--How to implement req.body.param validation

(OP)
Hello:

am trying to validate the value of MAXDEPTH below. if it is greater than x or less than y, execute the function updateMaxdepth(). Otherwise print error saying input value out of bounds.

So I have inserted the if/else block below but its not working.
It is at the borrom of the following code.
Pls advise what I have missed. Thank you.
=======================================================

CODE -->

app.post('/resubmit', urlencodedParser, function(req, res) {

    var QMGR      = req.body.qmgr;
    var APP_ID    = req.body.app_id;
    var QUEUE     = req.body.queue;
    var CURDEPTH  = parseInt(req.body.curdepth);
    var MAXDEPTH  = parseInt(req.body.maxdepth);

    var bash =
{
    cmd_1: `su mqm -c dspmq | grep ${QMGR}`,
    cmd_2: `su mqm -c 'echo \"dis queue(${QUEUE}) CURDEPTH MAXDEPTH\" | runmqsc ${QMGR}' | grep MAX |grep -v dis| perl -lanF\"[()]\" -e 'print $F[1]'`,
    cmd_3: `su mqm -c 'echo \"dis queue(${QUEUE}) CURDEPTH MAXDEPTH\" | runmqsc ${QMGR}' | grep MAX |grep -v dis| perl -lanF\"[()]\" -e 'print $F[3]'`,
    cmd_4: `su mqm -c 'echo \"alt ql(${QUEUE}) maxdepth(${MAXDEPTH})\" | runmqsc ${QMGR}'`
}

    let transport = nodemailer.createTransport({
    host: 'smtp.qcorpaa.aa.com',
    port: 25,
    //port: 587,
    secure: false,
    tls: {rejectUnauthorized: false}
    //tls: { ciphers:'SSLv3' }
});

    console.log(req.body.qmgr+" "+req.body.app_id+" "+req.body.queue+" "+req.body.curdepth+" "+req.body.maxdepth);

function updateMaxdepth() {
  //return new Promise((resolve) => {
    var child = cp.exec(bash.cmd_4, function(err, stdout, stderr) {
    if (stdout.includes('changed')) {

    var mailOptions = {
    from: 'root@esmqst15',
    to: 'JP.Seo@aa.com',
    //to: 'DL_Enterprise_MQ@aa.com',
    subject: 'Maxdepth Updated for queue '+req.body.queue+' on QMGR '+req.body.qmgr,
    text: 'Maxdepth Updated for queue '+req.body.queue+' to '+req.body.maxdepth+' on QMGR '+req.body.qmgr+' by App_ID '+req.body.app_id
    };
    console.log(mailOptions);
    transport.sendMail(mailOptions, function(err, info) {
    if (err) {
      console.log(err)
    } else {
      console.log(info);
    }
    });
    }
    });
}

function getCurDepth() {
  return new Promise((resolve) => {
    var child = cp.exec(bash.cmd_2, function(error, stdout, stderr) {
      let curr_output = stdout.split(/[\r\n|\n|\r]/).filter(String);
      resolve(curr_output);
    });
  });
}

function getMaxDepth() {
  return new Promise((resolve) => {
    var child = cp.exec(bash.cmd_3, function(error, stdout, stderr) {
      let max_output = stdout.split(/[\r\n|\n|\r]/).filter(String);
      resolve(max_output);
    });
  });
}

Promise.all([getCurDepth(), getMaxDepth()]).then(([curDepth, maxDepth]) => {
  console.log(`CURDEPTH  : ${QMGR}_${APP_ID}_${QUEUE}: ${curDepth}`);
  console.log(`MAXQDEPTH : ${QMGR}_${APP_ID}_${QUEUE}: ${maxDepth}`);

  //if(req.body.maxdepth > 1000 ||  req.body.maxdepth < 100000) {
  if(maxDepth > 1000 || maxDepth < 100000) {
  updateMaxdepth();
  res.render("resubmit", {
      data: {
           qmgr     : QMGR,
           app_id   : APP_ID,
           queue    : QUEUE,
           curdepth : curDepth,
           maxqdepth: maxDepth
            }
      });
  } else {
    return res.status(400).json({msg:'not valid'});
  }
  });

}); 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close