{"size": 1403, "ext": "js", "max_stars_repo_path": "app/electron/CommonSql.js", "max_stars_repo_name": "namitkaku/Legitquest_Offline", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/electron/CommonSql.js", "max_issues_repo_name": "namitkaku/Legitquest_Offline", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/electron/CommonSql.js", "max_forks_repo_name": "namitkaku/Legitquest_Offline", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.6140350877, "max_line_length": 117, "alphanum_fraction": 0.5744832502}
const getWhereQueryWithType = (query, searchType) => {
  let WHERE = "";
  switch (searchType) {
    case "act-section":
      WHERE = `  Act LIKE '%${query}%'`;
      break;
    case "partyname":
      WHERE = `  (Petitioner LIKE '%${query}%' OR Responder LIKE '%${query}%')`;
      break;
    case "bench":
      WHERE = `Bench LIKE '%${query}%' `;
      break;
    case "citation":
      WHERE = ` (Citation LIKE '%${query}%' OR AlternativeCitation LIKE '%${query}%') `;
      break;
    default:
      WHERE = `  (Petitioner LIKE '%${query}%' OR Responder LIKE '%${query}%'    OR  Judgement LIKE '%${query}%' ) `;
      break;
  }
  ///console.log({WHERE,query,searchType});
  return WHERE;
};

async function queryRunner(QUERY, connection) {
  try {
    return new Promise((resolve, reject) => {
      connection.query(QUERY, (err, result) => {
        let finalReults = [];
        result?.map((item) => {
          finalReults.push({ ...item });
        });
  
        return err ? reject(err) : resolve(finalReults);
      });
    });
  } catch (error) {
    return {error,message:`Error in Query : ${QUERY}`}
  }
}
function addStrictWhere(queryWhere) {
  if(queryWhere){
    return `AND ${queryWhere}`
  }
  return "";
  
}

function getJudgementTableName(year) {
  return `case_${year}`
}
module.exports = {
  getWhereQueryWithType,
  queryRunner,
  addStrictWhere,
  getJudgementTableName
};
