Skip to content

Instantly share code, notes, and snippets.

@kuryaki
Last active September 16, 2016 00:42
Show Gist options
  • Select an option

  • Save kuryaki/b9c3798febcd01f6750aa17acc96b6bc to your computer and use it in GitHub Desktop.

Select an option

Save kuryaki/b9c3798febcd01f6750aa17acc96b6bc to your computer and use it in GitHub Desktop.
## entities / models:
```
'use strict';
const Mongoose = require('mongoose');
const internals = {};
internals.schema = new Mongoose.Schema(
{
uuid: { type: String, required: true, index: { unique: true } },
name: { type: String, required: true }
},
{
toJSON: { virtuals: true },
timestamps: true
}
);
module.exports = Mongoose.model('carrier', internals.schema);
```
-------
## use cases / handlers
```
'use strict';
const Boom = require('boom');
const Models = require('../../models');
const Carrier = Models.Carrier;
exports.find = (request, reply) => {
const limit = request.query.limit;
Carrier
.find({})
.limit(limit)
.lean()
.exec((err, carriers) => {
/* $lab:coverage:off$ */
if (err) {
return reply(Boom.badImplementation('Error fetching carriers', err));
}
/* $lab:coverage:on$ */
return reply({ carriers } );
});
};
```
------
## interface adapters / routes
```
'use strict';
const Handlers = require('./handlers');
const Schema = require('./schema');
module.exports = [
{
method: 'GET',
path: '/carriers',
config: {
handler: Handlers.find,
validate: {
options: {
stripUnknown: true
},
query: Schema.carrierFilter
},
response: {
schema: Schema.carriers,
modify: true,
options: {
stripUnknown: true
}
}
}
}
];
```
--------
## frameworks-drivers / module index
```
'use strict';
const Routes = require('./routes');
exports.register = (server, options, next) => {
server.route(Routes);
return next();
};
exports.register.attributes = {
name: 'carriers',
dependencies: [
'@pager/hapi-auth-armor',
'@pager/hapi-bunny',
'@pager/hapi-mongo'
]
};
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment