{"size": 958, "ext": "js", "max_stars_repo_path": "packages/dila.js/src/getConteneursList.js", "max_stars_repo_name": "SocialGouv/dila2sql", "max_stars_repo_stars_event_min_datetime": "2019-04-16T08:57:17.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-22T14:42:41.000Z", "max_issues_repo_path": "packages/dila.js/src/getConteneursList.js", "max_issues_repo_name": "SocialGouv/dila2sql", "max_issues_repo_issues_event_min_datetime": "2019-03-27T08:49:38.000Z", "max_issues_repo_issues_event_max_datetime": "2020-08-11T06:34:44.000Z", "max_forks_repo_path": "packages/dila.js/src/getConteneursList.js", "max_forks_repo_name": "SocialGouv/dila2sql", "max_forks_repo_forks_event_min_datetime": "2019-08-08T13:25:03.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-16T18:12:20.000Z"}
{"max_stars_count": 4, "max_issues_count": 16, "max_forks_count": 2, "avg_line_length": 35.4814814815, "max_line_length": 89, "alphanum_fraction": 0.6565762004}
const getConteneursList = (knex, userFilters = {}) => {
  const defaultFilters = {
    etat: ["VIGUEUR", "VIGUEUR_ETEN", "VIGUEUR_NON_ETEN"]
  };
  const whitelistedFilters = Object.keys(userFilters)
    .filter(key => ["nature", "etat", "active"].includes(key))
    .reduce((obj, key) => ({ ...obj, [key]: userFilters[key] }), {});

  const filters = { ...defaultFilters, ...whitelistedFilters };

  let query = knex.table("conteneurs");
  if (filters.etat) {
    if (filters.etat instanceof Array) query = query.whereIn("etat", filters.etat);
    else query = query.where("etat", filters.etat);
  }
  if (filters.nature) {
    if (filters.nature instanceof Array) query = query.whereIn("nature", filters.nature);
    else query = query.where("nature", filters.nature);
  }
  if (filters.hasOwnProperty("active")) {
    query = query.where("active", filters.active);
  }
  return query.orderBy("date_publi", "desc");
};

module.exports = getConteneursList;
