-
-
Save kristofsajdak/73aadf4393c5526f3705 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var Joi = require('joi'); | |
module.exports = function (harvester) { | |
var category = harvester | |
.resource('categories', { | |
name: Joi.string().required().description('a name'), | |
links: { | |
brand: 'brands' | |
} | |
}); | |
// register routes of interests | |
// all routes are bootstrapped with default swagger spec and validation | |
// e.g. categories.get registers a mustbe permission check activity with 'categories.get' | |
// the Joi schema attributes are used to evaluate body or query params depending on the verb | |
category.get().register(); | |
category.getById().register(); | |
category.getChangeEventsStreaming().register(); | |
category.delete().register(); | |
//or category.all().register(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var Joi = require('joi'); | |
module.exports = function (harvester) { | |
var category = harvester | |
.resource('categories', { | |
name: Joi.string().required().description('a name'), | |
links: { | |
brand: 'brands' | |
} | |
}); | |
category.get().register(); | |
category.getById().swagger({summary: 'all the lovely categories by id'}).register(); | |
// only explicit .swagger() declaration needed when an override of standard swagger spec is wanted | |
category.getChangeEventsStreaming().register(); | |
category.delete().register(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var Joi = require('joi'); | |
module.exports = function (harvester) { | |
var category = harvester | |
.resource('categories', { | |
name: Joi.string().required().description('a name'), | |
links: { | |
brand: 'brands' | |
} | |
}); | |
var validation = { | |
get: {query: {myAwesomeParam: Joi.string().required().description('My awesome parameter')}} | |
}; | |
category.get().validate(validation.get).register(); | |
// only explicit .validate() needed when you want to override/augment defaults | |
category.getById().register(); | |
category.getChangeEventsStreaming().register(); | |
category.delete().register(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var Joi = require('joi'); | |
module.exports = function (harvester) { | |
var category = harvester | |
.resource('categories', { | |
name: Joi.string().required().description('a name'), | |
links: { | |
brand: 'brands' | |
} | |
}); | |
var validation = { | |
get: {query: {myAwesomeParam: Joi.string().required().description('My awesome parameter')}} | |
}; | |
category.get().validate(validation.get).register(); | |
category.getById().swagger({summary: 'all the lovely categories by id'}).register(); | |
category.getChangeEventsStreaming().register(); | |
function dynamicAuthorizeDelete(req) { | |
var _category; | |
return Promise.resolve() | |
.then(function(){ | |
harvester.adapter.find('category',req.params.id) | |
}) | |
.then(function(category){ | |
_category = category; | |
// lookup identity with whoamIfunction | |
return $http.get('/whoami') //header should have authentication | |
}) | |
.then(function(resp) { | |
if (resp.dealerUser && dealerUser.id==_category.links.dealerUser){ | |
return true; | |
}else{ | |
throw new JSONAPI_Error({403, 'something went wrong'})) | |
} | |
}) | |
} | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var Joi = require('joi'); | |
module.exports = function (harvester) { | |
var category = harvester | |
.resource('categories', { | |
name: Joi.string().required().description('a name'), | |
links: { | |
brand: 'brands' | |
} | |
}); | |
// retrieve express from app namespace | |
var app = harvester.app; | |
app.get('/categories', category.get().handler()); | |
app.get('/categories/:id', category.getById().handler()); | |
app.get('/categories/changes/stream', category.getChangeEventsStreaming().handler()); | |
app.delete('/categories', category.delete().handler()); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment