This code works but I don't know how to dismantle this "sausage" code.

async function showAllFilters(qry, arrayParams) {
    // params is []
    let result;
    try {
        result = await db.query(qry, arrayParams);

    } catch (error) {
        console.log("showAllFilters error: ");
    return result;

router.get('/', function (req, res) { // localhost:5000/api/filter
    let qry = "SELECT DISTINCT c.subCatName, (select COUNT(*) from tblPostCatMap as pp where pp.idSubCat = c.idSubCat) as subcatSumme from tblsubcat as c order by c.subCatName asc";
    .then(r => { // first, you get the count of records of all posts and store into count var
        var filterJson = {
            "categories": {},
            "subcategories": {}

        filterJson["subcategories"] = r;
        qry = "SELECT DISTINCT c.catName, (select COUNT(*) from tblPostCatMap as pp where pp.idCat = c.idCategorie) as catSumme from tblcategories as c order by c.catName asc";
        showAllFilters(qry, [])
        .then(r2 => {
            // how to dismantle this?
            filterJson["categories"] = r2;
           // ...
        .catch(err => {
            console.log("Err in showing all posts with pagination: " + err);
    .catch(err => {
        console.log("Err in getting the count of all posts: " + err);

The topic you ar explaining about the router is really good. The prograaming concept is so much clear in nature. It's really an informative article. I want to say this is well-penned article in nature. If you need to solve this problem of router then you need to learn how to Fix Wii Error Code 51330 and I will say that it will really helpful for you and everyone also.