Skip to content

Commit

Permalink
Merge 335e9eb into 016e6e3
Browse files Browse the repository at this point in the history
  • Loading branch information
bentatum committed Jan 26, 2018
2 parents 016e6e3 + 335e9eb commit 3b6971b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -24,9 +24,11 @@ var objection = require('objection');
var ObjectionRest = require('objection-rest');
var Person = require('./models/Person');
var Movie = require('./models/Movie');
var _ = require('lodash');
ObjectionRest(objection)
.routePrefix('/api')
.routeFormat(_.kebabCase)
.addModel(Person, function(findQuery) {
// findQuery.registerFilter(...) see objection-find
})
Expand Down
13 changes: 9 additions & 4 deletions lib/RestApiGenerator.js
Expand Up @@ -43,13 +43,18 @@ function RestApiGenerator(objection) {
this._pluralizer = function (word) {
return word + 's';
};
this._routeFormat = path => this._pluralizer(_.camelCase(path))
}

RestApiGenerator.prototype.logger = function (logger) {
this._logger = logger;
return this;
};

RestApiGenerator.prototype.pluralizer = function (pluralizer) {
this._pluralizer = pluralizer;
};

RestApiGenerator.prototype.addModel = function (modelClass, modifyCb) {
var self = this;

Expand Down Expand Up @@ -78,8 +83,8 @@ RestApiGenerator.prototype.routePrefix = function (routePrefix) {
return this;
};

RestApiGenerator.prototype.pluralizer = function (pluralizer) {
this._pluralizer = pluralizer;
RestApiGenerator.prototype.routeFormat = function (formatFunction) {
this._routeFormat = formatFunction;
return this;
};

Expand All @@ -106,7 +111,7 @@ RestApiGenerator.prototype.generate = function (app) {
var self = this;

_.each(this._models, function (modelClass) {
self._logger(colors.green(_.capitalize(_.camelCase(modelClass.name))) + colors.white(':'));
self._logger(colors.green(modelClass.name) + colors.white(':'));

var route = self._routeForModel(modelClass);

Expand Down Expand Up @@ -175,7 +180,7 @@ RestApiGenerator.prototype.generate = function (app) {
};

RestApiGenerator.prototype._routeForModel = function (modelClass) {
return this._routePrefix + this._pluralizer(_.camelCase(modelClass.tableName));
return this._routePrefix + this._routeFormat(modelClass.tableName);
};

RestApiGenerator.prototype._routeForRelation = function (relation) {
Expand Down

0 comments on commit 3b6971b

Please sign in to comment.