<commit_before>var tsModule = require('../shared/Module.js');
var databaseFactory = require('../shared/DatabaseFactory.js');
var tsModuleClasses = function(){
  var obj = tsModule();

  obj.init = function(user, request, reply, errorHandler){
    obj.user = user;
    obj.request = request;
    obj.reply = reply;
    obj.errorHandler = errorHandler;
  
    obj.userClassesDb = databaseFactory('userClasses',user);
    obj.classInfoDb = databaseFactory('classInfo',user);
  };

  obj.getClasses = function(){
    console.log('Classes getting user RIN for', obj.user);
    var RIN = obj.request.getParamTyped('RIN', Number);
    obj.userClassesDb.get(RIN).then(function(res){
      if(res === null){
          obj.reply.send(["No classes registered"]);
	  return;
      }
      obj.classInfoDb.batchGet(res).then(function(res){
        obj.reply.send(res);
      },
      function(err){
        console.log(err);
        obj.errorHandler.send(err);
      });
    },
    function(err){
      console.log(err);
      obj.errorHandler.send(err);
    });
  };
  
  obj.addClass = function() {
    var classCRN = obj.reques.getParamTyped('classCRN', Number);
    obj.classInfo.allKeys().then(function(pars){
      if(pars.indexOf(classCRN)!== -1){
	databaseUtils.mergeDB(obj.userClassesDb, obj.user.RIN, [classCRN]);
	console.log('Added', classCRN, 'to', obj.user.RIN, 'friend list');
	obj.reply.send('Done');
      }
    },function(err){});
    
  };
    
  obj.run = function(){
    var requestType = obj.request.getRequestType();
    if(requestType === 'GET') {
      var requestedDB = obj.request.getRequestedDatabase();
      console.log('Requested class database', requestedDB);
      return obj.getClasses();
    }else if(requestType === 'POST') {
      return obj.addClass();
    }
  };  
  
  return obj;
};
module.exports = tsModuleClasses;<commit_msg>added add class feature<commit_after>var tsModule = require('../shared/Module.js');
var databaseFactory = require('../shared/DatabaseFactory.js');
var databaseUtils = require('../shared/DatabaseUtils.js');
var tsModuleClasses = function(){
  var obj = tsModule();

  obj.init = function(user, request, reply, errorHandler){
    obj.user = user;
    obj.request = request;
    obj.reply = reply;
    obj.errorHandler = errorHandler;
  
    obj.userClassesDb = databaseFactory('userClasses',user);
    obj.classInfoDb = databaseFactory('classInfo',user);
  };

  obj.getClasses = function(){
    console.log('Classes getting user RIN for', obj.user);
    var RIN = obj.request.getParamTyped('RIN', Number);
    obj.userClassesDb.get(RIN).then(function(res){
      if(res === null){
          obj.reply.send(["No classes registered"]);
	  return;
      }
      obj.classInfoDb.batchGet(res).then(function(res){
        obj.reply.send(res);
      },
      function(err){
        console.log(err);
        obj.errorHandler.send(err);
      });
    },
    function(err){
      console.log(err);
      obj.errorHandler.send(err);
    });
  };
  
  obj.addClass = function() {
    var classCRN = obj.request.getParamTyped('classCRN', Number);
    obj.classInfoDb.allKeys().then(function(pars){
      console.log(pars);
      if(pars.indexOf(classCRN)!== -1){
	console.log('Adding '+classCRN);
	databaseUtils.mergeDB(obj.userClassesDb, obj.user.RIN, [classCRN]);
	console.log('Added', classCRN, 'to', obj.user.RIN, 'friend list');
	obj.reply.send('Done');
      }
    },function(err){});
    
  };
    
  obj.run = function(){
    var requestType = obj.request.getRequestType();
    if(requestType === 'GET') {
      var requestedDB = obj.request.getRequestedDatabase();
      console.log('Requested class database', requestedDB);
      return obj.getClasses();
    }else if(requestType === 'POST') {
      return obj.addClass();
    }
  };  
  
  return obj;
};
module.exports = tsModuleClasses;
{'fraction_non_alphanumeric': 0.16445485297944315, 'fraction_numerical': 0.0005204267499349467, 'mean_word_length': 3.2102957283680174, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1660326', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1215, 'n_words': 210}