<commit_before>module.exports = {

  /**
  * Init the model for the ressource
  * @params String model name
  */
  initModel: function(model) {
    this.model = require('../models/'+ model);
  },

  /**
  * Create a new crud route
  * @params String || Object
  * @return Array routes object
  */
  initRoute: function(ressource) {
    var routes = new Array();

    if (typeof ressource == 'string') {
      // All functions && no auth
      routes[0] = this.newRoute('all', ressource, false);
      routes[1] = this.newRoute('read', ressource, false);
      routes[2] = this.newRoute('create', ressource, false);
      routes[3] = this.newRoute('update', ressource, false);
      routes[4] = this.newRoute('delete', ressource, false);
    }
    else if (typeof ressource == 'object') {
      // Just choose function
      for (var i = 0; i < ressource['endpoints'].length; i++) {
        routes.push(this.newRoute(ressource['endpoints'][i], ressource.data, ressource['auth']));
      }
    }

    return routes;
  },

  /**
  * Create route object for requester
  * @params String the action
  * @params String the name of the ressources
  * @params Array || Boolean is authenticate
  * @return route object
  */
  newRoute: function(action, ressource, auth) {
    var r = {
      controller: this,
      middleware: [],
      action    : action,
    };

    if(auth)
      r.middleware = (auth.indexOf(action) != -1) ? ['auth'] : [];

    switch(action) {
      case 'all':
        r.path = '/' + ressource;
        r.method = 'get';
        break;
      case 'read':
        r.path = '/' + ressource + '/:id';
        r.method = 'get';
        break;
      case 'create':
        r.path = '/' + ressource + '/';
        r.method = 'post';
        break;
      case 'update':
        r.path = '/' + ressource + '/:id/';
        r.method = 'put';
        break;
      case 'delete':
        r.path = '/' + ressource + '/:id/delete';
        r.method = 'delete';
        break;
      default:
         r.path = '/' + ress;ource;
         r.method = 'get'
    }<commit_msg>clean and add auth === true<commit_after>module.exports = {

  /**
  * Init the model for the ressource
  * @params String model name
  */
  initModel: function(model) {
    this.model = require('../models/'+ model);
  },

  /**
  * Create a new crud route
  * @params String || Object
  * @return Array routes object
  */
  initRoute: function(ressource) {
    var routes = new Array();

    if (typeof ressource == 'string') {
      // All functions && no auth
      routes[0] = this.newRoute('all', ressource, false);
      routes[1] = this.newRoute('read', ressource, false);
      routes[2] = this.newRoute('create', ressource, false);
      routes[3] = this.newRoute('update', ressource, false);
      routes[4] = this.newRoute('delete', ressource, false);
    }
    else if (typeof ressource == 'object') {
      // Just choose function
      for (var i = 0; i < ressource['endpoints'].length; i++) {
        routes.push(this.newRoute(ressource['endpoints'][i], ressource.data, ressource['auth']));
      }
    }

    return routes;
  },

  /**
  * Create route object for requester
  * @params String the action
  * @params String the name of the ressources
  * @params Array || Boolean is authenticate
  * @return route object
  */
  newRoute: function(action, ressource, auth) {
    var r = {
      controller: this,
      middleware: [],
      action    : action,
    };

    if (auth)
      if (auth === true)
        r.middleware = ['auth'];
      else
        r.middleware = (auth.indexOf(action) != -1) ? ['auth'] : [];

    switch(action) {
      case 'all':
        r.path = '/' + ressource;
        r.method = 'get';
        break;
      case 'read':
        r.path = '/' + ressource + '/:id';
        r.method = 'get';
        break;
      case 'create':
        r.path = '/' + ressource + '/';
        r.method = 'post';
        break;
      case 'update':
        r.path = '/' + ressource + '/:id/';
        r.method = 'put';
        break;
      case 'delete':
        r.path = '/' + ressource + '/:id/delete';
        r.method = 'delete';
        break;
      default:
         r.path = '/' + ress;ource;
         r.method = 'get'
    }
{'fraction_non_alphanumeric': 0.1642249527410208, 'fraction_numerical': 0.0033081285444234404, 'mean_word_length': 2.1033724340175954, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '605716', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1345, 'n_words': 343}