NodalJs worth a looksie

I've stumbled upon a great new project.
NodalJS is an API framework in NodeJS. It takes it's inspiration from frameworks like DJango and Rails.

@keithwhor (Keith Horwood) is a very opinionated guy from what I've seen, be it by looking at the framework or by listening to his interview on JavaScriptJabber.

The framework is still in it's early steps… but it does have a huge potential.
I followed up on the youtube tutorials, which are pretty much the only "guided tutorial" you have on the web. Since it's in full development, we can expect some differences from the tutorial, and I did find a few, but they are no biggies.

Even though the three part tutorial does a great job at showing the nuts and bolts of the framework, it leaves a few little bits untold. Bear with me, I am very new to the whole nodeJS stuff, and even newer to Nodal (I just started off today), so maybe, what I am saying here is no big news for you veteran JS Devs, or maybe I am just doing this all wrong, yet, I thought I'd document it here.

Once you've done the Tutorial, you have basically an API that authenticates through an access token when you try to post a new "tweet". All that works fine, so I went to the next logical step; authenticate when you update a record. What I thought I'd do was: When you try to update a record with an access token, it should first check out if that is your post. So this is what I did:

update() {
//check if we have an access token
this.authorize( (accessToken, user) => {
// create a generic object to store the user and body for the tweet
var tw = {
'user_id': user.get('id'),
'body': this.params.body.body
};
// search find the current record
Tweet.find(this.params.route.id, (err, model) => {
if (err) {
return callback(err);
}
var postUser = model.get('user_id');
// check if the current post user is the user with the current access token
if (postUser == user.get('id')){
// post user is the authenticated user
// update the tweet
Tweet.update(this.params.route.id, tw, (err, model) => {
this.respond(err || model, this._getVisible());
});
}else{
// user does not own this post
var err = this.error('Not Permitted','This post does not belong to you' );
this.respond(err);
}
});
});
}

So you can get where I am… this is the updated "update" method for the tweet_controller. I've tried to add comments to make it clear of where I was going from an to.

There is one specific little thing that differs from the docs and tutorials…

this.respond(err || model, this._getVisible());

This responder will either show an error (err) or the model, like suggested, but, it also has the "this._getVisible()" which is a simple method I setup on the controller and a property on the model to avoid having to write which columns are going to be displayed or not.

This is the property I setup in the Tweet model.

Tweet.visible = ['id', 'user_id', 'body', 'created_at'];

This is the method setup on the tweet_controller.

  _getVisible(){
var visible = Tweet.visible;
visible.push({user: User.visible});
return visible;
}

It just makes life a bit more simple.

Anyways… I'll try to keep a log of my adventures as I continue to play around more with Nodal. If you have a chance, I would sure recommend you take some time to have a look at it at least.