3.0.15 • Published 5 years ago
mrs-node-util v3.0.15
mrs-node-util
Include module
"mrs-node-util": "git+https://github.com/Tlantic/mrs-node-util.git#master"
HTTP
Response
var httpResponse = require('mrs-node-util').httpResponse;
Example: with Express
Success 200
httpResponse.success(data, res);
{
"status": "OK",
"result": {
"email": "dgjsdgjasgjdasgjdasj@gmail.com",
}
}
Error 403 forbidden
httpResponse.forbidden(data, res);
{
"status": 403,
"error": "Forbidden",
"message": {
}
}
BOOT
Require Module
var mrsBoot = require('mrs-node-util').boot;
Use Example
mrsBoot.getConfigurations(configData, configData.core.host, configData.core.port, function(err, _config){
if(err){
console.log(err);
}
else {
console.log(c_onfig);
}
});
INTERNAL_ROUTER
Require Module
var mrsInternalRouter = require('mrs-node-util').internalRouter;
Use Example
mrsInternalRouter.request({
internalRouterAddress: 'http://10.58.1.63:8011',
route: 'catalog/orgs/monteserrat/apps/customer/hierarchicalstructure/1',
serviceName: 'get-products',
verb: 'GET',
data: [optional]
}, function(err, data){
console.log(data);
});
CRUD
Use the CRUD utility to wrap basic crud operation methods around a database model.\ All callbacks used in this utility are expected to have an error-first signature style.
Require Module
var CrudWrapper = require('mrs-node-util').crud;
Use Example
Create a wrapper around a model.
/* function (model, modelName, MODULE, SUB_MODULE) */
var crud = new CrudWrapper( documentModel, 'document', defaultView, serviceName );
Create a record
If required to check for possible duplicates, provide the uniqueParams argument as an array containing the function to be called when looking for duplicate records.
var record,
data = { code: '007', firstName: 'James', lastName: 'Bond' },
params = { applicationId: appId };
function getByAppIdAndCode ( appId, code, callback ) { ... }
/* function (params, record, cb) */
crud.create( params, data, function(err, res){
if ( err ) {
throw err;
}
record = res.result;
});
/* function (params, record, uniqueParams, indexingViews, cb) */
crud.create( params, data, [ params.applicationId, code, getByAppIdAndCode ], indexingViews, function(err, res){
if ( err ) {
throw err;
}
record = res.result;
});
Retrieve a record
crud.retrieve( record._uId, function(err, res){
if ( err ) {
throw err;
}
record = res.result;
}
Update a record
crud.update( record._uId, { lastName: 'Oliver' }, indexingViews, function(err, res){
if ( err ) {
throw err;
}
record = res.result;
}
Delete a record
crud.delete( record._uId, indexingViews, function(err, res){
if ( err ) {
throw err;
}
}
3.0.15
5 years ago