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

Apply padding to month param with leading zero #1

Open
mirsahib opened this issue Feb 15, 2021 · 0 comments
Open

Apply padding to month param with leading zero #1

mirsahib opened this issue Feb 15, 2021 · 0 comments
Labels
good first issue Good for newcomers

Comments

@mirsahib
Copy link
Owner

Problem: The run method in the scrapper.controller.js file throws a bill not exist error because the scrapping url should accept month parameter with leading zero.
Example:

// month param less than 10
https://dpdc.org.bd/service/ebill?btyp=current&year=2021&month=01&cno=24546800&email=
// month more than 10
https://dpdc.org.bd/service/ebill?btyp=current&year=2021&month=12&cno=24546800&email=

Solution:

const run = async function (req, res) {
  const year = req.query.year;
  const month = req.query.month.length===1 ? '0'+req.query.month:req.query.month; //add this line
  const customer_no = req.query.cno.split(",");
  //console.log({ year, month, customer_no });

  try {
    //error handling code
    if (checkParam(year) && checkParam(month) && checkParam(customer_no)) {
      const data = await getData(year, month, customer_no, res);
      res.status(200).json(data);
    } else {
      res.status(400).json({
        msg: "Parameters are undefined or null value",
        parameter: { year, month, customer_no },
      });
    }
  } catch (error) {
    res.status(500).json({ msg: error });
  }
};
@mirsahib mirsahib added the good first issue Good for newcomers label Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant