{"size": 4989, "ext": "js", "max_stars_repo_path": "src/screenings.js", "max_stars_repo_name": "revdapp/node-checkr", "max_stars_repo_stars_event_min_datetime": "2017-10-20T16:59:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-14T13:26:57.000Z", "max_issues_repo_path": "src/screenings.js", "max_issues_repo_name": "franciscofsales/node-checkr", "max_issues_repo_issues_event_min_datetime": "2021-06-10T00:52:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-12T13:02:52.000Z", "max_forks_repo_path": "src/screenings.js", "max_forks_repo_name": "franciscofsales/node-checkr", "max_forks_repo_forks_event_min_datetime": "2017-10-25T20:38:08.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-11T22:13:48.000Z"}
{"max_stars_count": 5, "max_issues_count": 5, "max_forks_count": 4, "avg_line_length": 27.4120879121, "max_line_length": 93, "alphanum_fraction": 0.4417718982}
/* ============================================================
 * node.checkr
 * https://github.com/revdapp/node-checkr
 *
 * ============================================================
 * Copyright 2014-2017, Francisco Sales
 * Released under the MIT License
 * ============================================================ */

import Joi from 'joi';
import axios from 'axios';
import handleError from './handleError';

const screenings = options => {
  return {
    ssn_trace: async id => {
      const alphaRegex = /^[a-z0-9]+/i;
      if (alphaRegex.test(id)) {
        try {
          const res = await axios({
            method: 'get',
            url: `${options.baseUrl}/${options.apiVersion}/ssn_traces/${id}`,
            auth: {
              username: options.apiKey,
              password: ''
            }
          });
          return res.data;
        } catch (error) {
          handleError(error);
        }
      }
    },
    sex_offender: async id => {
      const alphaRegex = /^[a-z0-9]+/i;
      if (alphaRegex.test(id)) {
        try {
          const res = await axios({
            method: 'get',
            url: `${options.baseUrl}/${options.apiVersion}/sex_offender_searches/${id}`,
            auth: {
              username: options.apiKey,
              password: ''
            }
          });
          return res.data;
        } catch (error) {
          handleError(error);
        }
      }
    },
    global_watchlist: async id => {
      const alphaRegex = /^[a-z0-9]+/i;
      if (alphaRegex.test(id)) {
        try {
          const res = await axios({
            method: 'get',
            url: `${options.baseUrl}/${options.apiVersion}/global_watchlist_searches/${id}`,
            auth: {
              username: options.apiKey,
              password: ''
            }
          });
          return res.data;
        } catch (error) {
          handleError(error);
        }
      }
    },
    national_criminal: async id => {
      const alphaRegex = /^[a-z0-9]+/i;
      if (alphaRegex.test(id)) {
        try {
          const res = await axios({
            method: 'get',
            url: `${options.baseUrl}/${options.apiVersion}/national_criminal_searches/${id}`,
            auth: {
              username: options.apiKey,
              password: ''
            }
          });
          return res.data;
        } catch (error) {
          handleError(error);
        }
      }
    },
    county_criminal: async id => {
      const alphaRegex = /^[a-z0-9]+/i;
      if (alphaRegex.test(id)) {
        try {
          const res = await axios({
            method: 'get',
            url: `${options.baseUrl}/${options.apiVersion}/county_criminal_searches/${id}`,
            auth: {
              username: options.apiKey,
              password: ''
            }
          });
          return res.data;
        } catch (error) {
          handleError(error);
        }
      }
    },
    state_criminal: async id => {
      const alphaRegex = /^[a-z0-9]+/i;
      if (alphaRegex.test(id)) {
        try {
          const res = await axios({
            method: 'get',
            url: `${options.baseUrl}/${options.apiVersion}/state_criminal_searches/${id}`,
            auth: {
              username: options.apiKey,
              password: ''
            }
          });
          return res.data;
        } catch (error) {
          handleError(error);
        }
      }
    },
    motor_vehicle: async id => {
      const alphaRegex = /^[a-z0-9]+/i;
      if (alphaRegex.test(id)) {
        try {
          const res = await axios({
            method: 'get',
            url: `${options.baseUrl}/${options.apiVersion}/motor_vehicle_reports/${id}`,
            auth: {
              username: options.apiKey,
              password: ''
            }
          });
          return res.data;
        } catch (error) {
          handleError(error);
        }
      }
    },
    education_verifications: async id => {
      const alphaRegex = /^[a-z0-9]+/i;
      if (alphaRegex.test(id)) {
        try {
          const res = await axios({
            method: 'get',
            url: `${options.baseUrl}/${options.apiVersion}/education_verifications/${id}`,
            auth: {
              username: options.apiKey,
              password: ''
            }
          });
          return res.data;
        } catch (error) {
          handleError(error);
        }
      }
    },
    employment_verifications: async id => {
      const alphaRegex = /^[a-z0-9]+/i;
      if (alphaRegex.test(id)) {
        try {
          const res = await axios({
            method: 'get',
            url: `${options.baseUrl}/${options.apiVersion}/employment_verifications/${id}`,
            auth: {
              username: options.apiKey,
              password: ''
            }
          });
          return res.data;
        } catch (error) {
          handleError(error);
        }
      }
    }
  };
};

export default screenings;
