{"size": 1401, "ext": "js", "max_stars_repo_path": "api/src/services/cards/cards.service.js", "max_stars_repo_name": "JasonH815/react_cpsc463_app", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "api/src/services/cards/cards.service.js", "max_issues_repo_name": "JasonH815/react_cpsc463_app", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "api/src/services/cards/cards.service.js", "max_forks_repo_name": "JasonH815/react_cpsc463_app", "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": 25.4727272727, "max_line_length": 75, "alphanum_fraction": 0.6324054247}
// Initializes the `card` service on path `/card`
const createService = require('feathers-mongodb');
const hooks = require('./cards.hooks');
const _ = require('lodash');
const _rankValues = ['2','3','4','5','6','7','8','9','10','J','Q','K','A'];
const _suitValues = ['heart', 'diamond', 'club', 'spade'];

//Store the ranks and suits as objects to support dot notation
const RANKS = _.reduce(
  _.map(_rankValues, (label, idx) => { return {label, idx}; }),
  (obj, {label, idx}) => {
    return {...obj, [label.toUpperCase()]:{label, rank: idx}};
  },
  {});

const SUITS = _.reduce(
  _suitValues,
  (obj, suit) => {
    return {...obj, [suit.toUpperCase()]:suit};
  },
  {});

const SuitService = {
  find() {
    return Promise.resolve(SUITS);
  }
};

const RankService = {
  find() {
    return Promise.resolve(RANKS);
  }
};


module.exports = function (app) {
  const paginate = app.get('paginate');
  const mongoClient = app.get('mongoClient');
  const options = { paginate };

  // Initialize our service with any options it requires
  app.use('/cards/suits', SuitService);
  app.use('/cards/ranks', RankService);
  app.use('/cards', createService(options));

  // Get our initialized service so that we can register hooks and filters
  const cardService = app.service('cards');

  mongoClient.then(db => {
    cardService.Model = db.collection('cards');
  });

  cardService.hooks(hooks);
};
