{"size": 1169, "ext": "js", "max_stars_repo_path": "api/handlers.js", "max_stars_repo_name": "dlsemwal/wetheusers-backend", "max_stars_repo_stars_event_min_datetime": "2015-10-17T05:22:04.000Z", "max_stars_repo_stars_event_max_datetime": "2017-01-14T12:22:36.000Z", "max_issues_repo_path": "api/handlers.js", "max_issues_repo_name": "dlsemwal/wetheusers-backend", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "api/handlers.js", "max_forks_repo_name": "dlsemwal/wetheusers-backend", "max_forks_repo_forks_event_min_datetime": "2015-09-25T22:07:34.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-01T19:02:11.000Z"}
{"max_stars_count": 4, "max_issues_count": null, "max_forks_count": 4, "avg_line_length": 19.1639344262, "max_line_length": 63, "alphanum_fraction": 0.6749358426}
/**
 * Handlers for the API routes.
 */

var hapi = require('hapi');
var lodash = require('lodash');

var signatures = require('../db/signatures');


/**
 * Adds a signature to the datastore.
 * @param request The Hapi request object
 * @param reply The Hapi reply object.
 */
var addSignature = function(request, reply) {

  var newSignature = request.payload;
  newSignature.sentToWhiteHouse = false;
  newSignature.isValidated = false;

  var success = function() {
    reply({status: 'success'});
  };

  var failure = function(err) {
    throw err;
  };

  signatures.saveSignature(newSignature, success, failure);

};


/**
 * Check whether a given signature has been validated.
 *
 * @param request
 * @param reply
 */
var getSignature = function(request, reply) {

  var success = function(signature) {
    if (lodash.isObject(signature)) {
      reply(signature);
    } else {
      reply(hapi.error.notFound('valid signature not found'));
    }
  };

  var error = function(err) {
    throw err;
  };

  signatures.getSignature(request.params.email, success, error)
};


module.exports.addSignature = addSignature;
module.exports.getSignature = getSignature;
