{"size": 886, "ext": "js", "max_stars_repo_path": "src/services/submit.js", "max_stars_repo_name": "jchurchman/formforfun", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/services/submit.js", "max_issues_repo_name": "jchurchman/formforfun", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/services/submit.js", "max_forks_repo_name": "jchurchman/formforfun", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.6046511628, "max_line_length": 76, "alphanum_fraction": 0.6376975169}
import {
  INCOME,
  REQUEST,
  MAX_LOAN_AMT,
  MIN_LOAN_AMT,
  INCOME_DEBT_RATIO,
  REJECTED,
} from '../constants';

const evaluateLoan = ({ income, request }) => {
  if (request < MIN_LOAN_AMT) {
    return REJECTED.SMALL;
  }
  if (request > MAX_LOAN_AMT) {
    return REJECTED.LARGE;
  }
  if (request > (income * INCOME_DEBT_RATIO)) {
    return REJECTED.RATIO;
  }
  return true;
};

export default function (argObj) {
  const income = argObj[INCOME];
  const request = argObj[REQUEST];

  const record = localStorage.getItem('submissions'); // eslint-disable-line
  const submissions = record ? JSON.parse(record) : [];
  const evaluation = evaluateLoan({ income, request });

  localStorage.setItem( // eslint-disable-line
    'submissions',
    JSON.stringify([
      ...submissions,
      {
        ...argObj,
        evaluation,
      },
    ]),
  );
  return evaluation;
}
