Skip to content

Commit

Permalink
cleanup sloppy logs
Browse files Browse the repository at this point in the history
  • Loading branch information
martindale committed Jan 31, 2015
1 parent 1934079 commit 8857d5f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 57 deletions.
96 changes: 44 additions & 52 deletions lib/Resource/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,61 +336,53 @@ Resource.prototype.create = function( doc , params , complete ) {

var Model = self.Model;

var query = {};
query[ self.fields.id ] = doc[ self.fields.id ];

// disallow creation of documents with the same identifier field
// find one based on our query, and return it if it exists
Model.findOne( query ).exec(function(err, instance) {
if (err) return complete(err);
if (instance) return complete( err , instance );
async.waterfall([
executePreFunctions,
executeMethod,
executePostFunctions
], function(err, instance) {
console.log('lololol complete:', instance);

self.emit('create', instance );
return complete( err , instance );
async.waterfall([
checkForDuplicates,
executePreFunctions,
executeMethod,
executePostFunctions
], function(err, instance) {
self.emit('create', instance );
return complete( err , instance );
});

function checkForDuplicates( done ) {
var query = {};
query[ self.fields.id ] = doc[ self.fields.id ];
// disallow creation of documents with the same identifier field
// find one based on our query, and return it if it exists
Model.findOne( query ).exec(function(err, instance) {
if (err) return complete(err);
if (instance) return complete( err , instance );
return done( null );
});

function executePreFunctions( done ) {
console.log('pre functions...');
async.series( self.middlewares['pre']['create'].map(function(x) {
return function( next ) {
x.apply( doc , [ next , complete ] );
};
}), function(err, results) {
done( null , doc );
} );
}
function executeMethod( doc , done ) {
console.log('method execution...');
}
function executePreFunctions( done ) {
async.series( self.middlewares['pre']['create'].map(function(x) {
return function( next ) {
x.apply( doc , [ next , complete ] );
};
}), function(err, results) {
done( null , doc );
} );
}
function executeMethod( doc , done ) {
var instance = new Model( doc );
instance.save(function(err) {
if (err) return complete(err);
done( null , instance );
});
}
function executePostFunctions( instance , done ) {
async.series( self.middlewares['post']['create'].map(function(x) {
return function( done ) {
x.apply( instance , [ done ] );
};
}), function(err, results) {
return done( null , instance );
});
}

console.log('instance definition...');
var instance = new Model( doc );
instance.save(function(err) {
if (err) return complete(err);
console.log('calling back! instance:', instance );
done( null , instance );
});
}
function executePostFunctions( instance , done ) {
console.log('post functions! instance:', instance );
async.series( self.middlewares['post']['create'].map(function(x) {
return function( done ) {
x.apply( instance , [ done ] );
};
}), function(err, results) {
return done( null , instance );
});
}

});
}

Resource.prototype.update = function( query , params , complete ) {
Expand Down
5 changes: 0 additions & 5 deletions lib/Service/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ HTTP.prototype.attach = function( maki ) {
var handlers = _.merge({
html: {
create: function(req, res, next) {
console.log('locals:', res.locals );
// send the correct status code to clients expecting HTML (usually browsers)
res.redirect( 303 , '/' + maki.resources[ r ].collection + '/' + req.locals[ resource.fields.id ] );
}
Expand Down Expand Up @@ -530,10 +529,6 @@ HTTP.prototype.attach = function( maki ) {

resource[ p ]( doc , function(err, instance) {
if (err) return res.error( err );

console.log('outof all the middles...');
console.log('instance:', instance );

req.locals = instance;
return res.provide( r , instance , handlers );
});
Expand Down

0 comments on commit 8857d5f

Please sign in to comment.