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.run = 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);
    });
  };  
  
  return obj;
};
module.exports = tsModuleClasses;

@@ -459,22 +459,25 @@
  %7D;%0A
-    
 %0A  obj.
-run
+getClasses
  = f
@@ -1020,24 +1020,24 @@
 d(err);%0A
-
     %7D);%0A
   %7D;  %0A 
@@ -1028,16 +1028,750 @@
     %7D);%0A
+  %7D;%0A  %0A  obj.addClass = function() %7B%0A    var classCRN = obj.reques.getParamTyped('classCRN', Number);%0A    obj.classInfo.allKeys().then(function(pars)%7B%0A      if(pars.indexOf(classCRN)!== -1)%7B%0A%09databaseUtils.mergeDB(obj.userClassesDb, obj.user.RIN, %5BclassCRN%5D);%0A%09console.log('Added', classCRN, 'to', obj.user.RIN, 'friend list');%0A%09obj.reply.send('Done');%0A      %7D%0A    %7D,function(err)%7B%7D);%0A    %0A  %7D;%0A    %0A  obj.run = function()%7B%0A    var requestType = obj.request.getRequestType();%0A    if(requestType === 'GET') %7B%0A      var requestedDB = obj.request.getRequestedDatabase();%0A      console.log('Requested class database', requestedDB);%0A      return obj.getClasses();%0A    %7Delse if(requestType === 'POST') %7B%0A      return obj.addClass();%0A    %7D%0A
   %7D;  %0A 

add class