var Package = require('../models/package');
var Github = require('../models/github');

module.exports = function (imports) {
  var app = imports.app;
  
  app.post('/packages', function (req ,res) {
    var bodyFiles = req.body.files || {};
    var name = req.body.name;
    var package = new Package({
      name: name,
      files: bodyFiles,
      user_id: (req.user) ? req.user.github_id : undefined
    });
    
    // TODO: if package has same name as one the user
    // has already created, return error
    
    package.save(function (err) {
      if (err) return res.send(500, err);
      res.send(package);
    });
  });
};
@@ -188,24 +188,49 @@
 req ,res) %7B%0A
+    var user = req.user;%0A
     var body
@@ -565,24 +565,111 @@
 ion (err) %7B%0A
+      Package.findByIdOrName(package.name, user.github_id, function (err, package) %7B%0A  
       if (er
@@ -695,19 +695,38 @@
 500, err
+.message
 );%0A
+        %0A  
       re
@@ -738,24 +738,34 @@
 d(package);%0A
+      %7D);%0A
     %7D);%0A  %7D)

Return parsed package on package creation. Closes #15