Skip to content

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lykmapipo committed Jun 8, 2018
2 parents 417bd60 + b534e6b commit 93db5a6
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.3.0 / 2018-06-08
- Expose models name as constants
- Add get models helper

# v0.1.0 / 2018-05-22

* Common apidoc definitions
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install --save @codetanzania/majifix-common

## Usage
```js
const { env } = require('@codetanzania/majifix-common');
const { env, models } = require('@codetanzania/majifix-common');
```

## Test
Expand Down
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
'use strict';


/* dependencies */
const path = require('path');


/* declarations */
const env = require(path.join(__dirname, 'lib', 'env'));
const schema = require(path.join(__dirname, 'lib', 'schema'));
const models = require(path.join(__dirname, 'lib', 'models'));


Object.defineProperties(exports, {
env: {
Expand All @@ -17,5 +21,10 @@ Object.defineProperties(exports, {
get: function () {
return schema;
}
},
models: {
get: function () {
return models;
}
}
});
66 changes: 66 additions & 0 deletions lib/models.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'use strict';


/* dependencies */
const mongoose = require('mongoose');
const { MissingSchemaError } = mongoose.Error;


/* constants */
Object.defineProperties(exports, {
JURISDICTION_MODEL_NAME: {
get: function () {
return 'Jurisdiction';
}
},
STATUS_MODEL_NAME: {
get: function () {
return 'Status';
}
},
PRIORITY_MODEL_NAME: {
get: function () {
return 'Priority';
}
},
SERVICEGROUP_MODEL_NAME: {
get: function () {
return 'ServiceGroup';
}
},
SERVICE_MODEL_NAME: {
get: function () {
return 'Service';
}
},
SERVICEREQUEST_MODEL_NAME: {
get: function () {
return 'ServiceRequest';
}
}
});


/* helpers */
exports.getModel = function getModel(modelName) {

//try obtain model
try {
const Model = mongoose.model(modelName);
return Model;
}

//catch error
catch (error) {

//ignore missing schema error
if (!(error instanceof MissingSchemaError)) {
throw error;
}

//unknown model
return undefined;

}

};
131 changes: 124 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@codetanzania/majifix-common",
"version": "0.2.0",
"version": "0.3.0",
"description": "Common utilities for majifix",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -48,6 +48,7 @@
"sinon-chai": "^3.0.0"
},
"dependencies": {
"lodash": "^4.17.10"
"lodash": "^4.17.10",
"mongoose": "^5.1.2"
}
}
Loading

0 comments on commit 93db5a6

Please sign in to comment.