keithwhor / nodal

API Services Made Easy With Node.js

Home Page:http://www.nodaljs.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`nodal g:model --access_token` & `nodal g:controller v1 --for AccessToken`

nsipplswezey opened this issue · comments

commented

It looks like the two methods we'd like to default implement for an access token controller are create() and destroy():

module.exports = (function() {

  'use strict';

  const Nodal = require('nodal');
  const AccessToken = Nodal.require('app/models/access_token.js');

  class V1AccessTokensController extends Nodal.Controller {

    create() {

      AccessToken.login(this.params, (err, accessToken) => {

        this.respond(err || accessToken);

      });
    }

    destroy() {

      AccessToken.logout(this.params, (err, accessToken) => {

        this.respond(err || accessToken);

      });

    }

  }

  return V1AccessTokensController;

})();

Is there a super solid reason g:controller [nameSpace] --for AccessToken generates a controller with all the default CRUD methods implemented, rather than just create() and destroy()? Is the generator smart enough to know that the AccessToken model was created by nodal g:model --access_token?

We can possibly change this, but I think it's a bit too "magical". --for [Model] should, IMO, have the same behavior every time.