{"size": 603, "ext": "js", "max_stars_repo_path": "api/users/users-model.js", "max_stars_repo_name": "MMGroesbeck/tile-backend", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "api/users/users-model.js", "max_issues_repo_name": "MMGroesbeck/tile-backend", "max_issues_repo_issues_event_min_datetime": "2021-05-11T12:04:01.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-02T10:24:13.000Z", "max_forks_repo_path": "api/users/users-model.js", "max_forks_repo_name": "MMGroesbeck/tile-backend", "max_forks_repo_forks_event_min_datetime": "2020-05-04T15:59:43.000Z", "max_forks_repo_forks_event_max_datetime": "2020-05-04T15:59:43.000Z"}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": 1, "avg_line_length": 17.7352941176, "max_line_length": 52, "alphanum_fraction": 0.6036484245}
const db = require("../data/dbConfig");
const jwt = require('jsonwebtoken');
const secrets = require('../api/secrets');

module.exports = {
  add,
  findBy,
  findById,
  findByEmail
};

function findBy(filter, select) {
  return db("users").select(select).where(filter);
}

async function add(user) {
  const [id] = await db("users").insert(user, "id");

  return findById(id);
}

function findByEmail(email, role) {
  return db("users")
    .where({ email: email,
              role: role 
            })
    .first();
}

function findById(id) {
  return db("users")
    .where({ id })
    .first();
}