{"size": 886, "ext": "js", "max_stars_repo_path": "src/usecases/token/getToken.js", "max_stars_repo_name": "HrithikMittal/Resturant-Backend", "max_stars_repo_stars_event_min_datetime": "2018-10-12T00:14:05.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-25T17:09:50.000Z", "max_issues_repo_path": "src/usecases/token/getToken.js", "max_issues_repo_name": "HrithikMittal/Resturant-Backend", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/usecases/token/getToken.js", "max_forks_repo_name": "HrithikMittal/Resturant-Backend", "max_forks_repo_forks_event_min_datetime": "2018-10-13T04:50:47.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-23T04:48:54.000Z"}
{"max_stars_count": 224, "max_issues_count": null, "max_forks_count": 93, "avg_line_length": 26.8484848485, "max_line_length": 74, "alphanum_fraction": 0.6851015801}
// Dependencies.
const database = require('../../services/database');
const Token = require('../../models/Token');
const validator = require('../../services/validator');
const ResponseContainer = require('../../models/ResponseContainer');

/**
 * Read token.
 * @param {RequestData} requestData
 * @return {Promise}
 */
const getToken = async (requestData) => {
  // Check that the id is valid.
  const id = validator.parseString(requestData.queryStringObject.id);

  if (!id) {
    return new ResponseContainer(400, {error: 'Missing required fields'});
  }

  // Lookup the token.
  const tokenData = await database.read('tokens', id);
  if (!tokenData) {
    return new ResponseContainer(404);
  }

  // Create token instance.
  const token = new Token().fromSnapshot(tokenData);
  return new ResponseContainer(200, token.toObject());
};

// Export module.
module.exports = getToken;
