Skip to content

Commit

Permalink
Merge branch 'release/1.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lykmapipo committed Aug 30, 2019
2 parents 1b6aa4a + 9484653 commit 1ee275c
Show file tree
Hide file tree
Showing 11 changed files with 491 additions and 313 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,33 @@
#### 1.9.0 (2019-08-30)

##### Chores

* improve package keywords ([7f806843](https://github.com/CodeTanzania/majifix-account/commit/7f8068431f56a818064da8482c5882af1e974acb))
* **deps:**
* remove unused ([4589115d](https://github.com/CodeTanzania/majifix-account/commit/4589115d6e414801c3ee3700aacfe17f085a1f50))
* force latest version & audit fix ([4eda339e](https://github.com/CodeTanzania/majifix-account/commit/4eda339eff344e47d7a70d280b3047136ae68217))
* force latest version & audit fix ([5a861aa9](https://github.com/CodeTanzania/majifix-account/commit/5a861aa94a0a0d43e588433d7e90ccfd5878cca9))
* **configs:** update eslint configs ([08ccb7ab](https://github.com/CodeTanzania/majifix-account/commit/08ccb7ab13993eb147058bf141ff1ed799b90523))
* **examples:** improve sample app & seed ([023f8902](https://github.com/CodeTanzania/majifix-account/commit/023f8902170d168f469e6be18ff8dd008318bd33))

##### Documentation Changes

* update usage docs ([197edd17](https://github.com/CodeTanzania/majifix-account/commit/197edd17c61d7467fe68f1a85456c075e0bd6383))
* improve requirements version ([efcda90e](https://github.com/CodeTanzania/majifix-account/commit/efcda90ea10fb573924e2d1928c30eaa883dc9a6))
* add statuses badge ([2ed25aef](https://github.com/CodeTanzania/majifix-account/commit/2ed25aefd2f23b37a44ca72bed443cc71f7cffe4))

##### Refactors

* improve main exports ([53650515](https://github.com/CodeTanzania/majifix-account/commit/536505150cb15765387d18b8e78a9929f01902fb))

##### Code Style Changes

* **examples:** fix lint error ([522c9556](https://github.com/CodeTanzania/majifix-account/commit/522c95568d02eb36c6bbf085952d1ad30e7437cb))

##### Tests

* improve imports ([8fc3b9d2](https://github.com/CodeTanzania/majifix-account/commit/8fc3b9d2a31c82f98c917e689a6efbee52e007b6))

#### 1.8.0 (2019-08-23)

##### Chores
Expand Down
33 changes: 19 additions & 14 deletions README.md
@@ -1,8 +1,15 @@
# majifix-account

[![Build Status](https://travis-ci.org/CodeTanzania/majifix-account.svg?branch=develop)](https://travis-ci.org/CodeTanzania/majifix-account)
[![Dependencies Status](https://david-dm.org/CodeTanzania/majifix-account/status.svg?style=flat-square)](https://david-dm.org/CodeTanzania/majifix-account)
[![Deploy to Heroku](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy?template=https://github.com/CodeTanzania/majifix-account/tree/develop)
[![Dependencies Status](https://david-dm.org/CodeTanzania/majifix-account.svg)](https://david-dm.org/CodeTanzania/majifix-account)
[![Coverage Status](https://coveralls.io/repos/github/CodeTanzania/majifix-account/badge.svg?branch=develop)](https://coveralls.io/github/CodeTanzania/majifix-account?branch=develop)
[![GitHub License](https://img.shields.io/github/license/CodeTanzania/majifix-account)](https://github.com/CodeTanzania/majifix-account/blob/develop/LICENSE)
[![Deploy to Heroku](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy?template=https://github.com/CodeTanzania/majifix-account/tree/develop)

[![Commitizen Friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![Code Style](https://badgen.net/badge/code%20style/airbnb/ff5a5f?icon=airbnb)](https://github.com/airbnb/javascript)
[![npm version](https://img.shields.io/npm/v/@codetanzania/majifix-account)](https://www.npmjs.com/package/@codetanzania/majifix-account)

A representation of an entity (i.e organization, individual, customer, or client) which receiving service(s) from a particular [jurisdiction](https://github.com/CodeTanzania/majifix-jurisdiction).

Expand All @@ -15,10 +22,10 @@ It's a simplified version obtained after merging:

## Requirements

- [NodeJS v8.11.1+](https://nodejs.org)
- [Npm v5.6.0+](https://www.npmjs.com/)
- [MongoDB v3.4.10+](https://www.mongodb.com/)
- [Mongoose v5.1.2+](https://github.com/Automattic/mongoose)
- [NodeJS v12+](https://nodejs.org)
- [Npm v6+](https://www.npmjs.com/)
- [MongoDB v4+](https://www.mongodb.com/)
- [Mongoose v5.6+](https://github.com/Automattic/mongoose)

## Installation

Expand All @@ -29,16 +36,14 @@ npm install @codetanzania/majifix-account --save
## Usage

```js
const mongoose = require('mongoose');
const { app } = require('@codetanzania/majifix-account');
import { connect } from '@lykmapipo/mongoose-common';
import { Account, start } from '@codetanzania/majifix-account';

//connect to mongodb
mongoose.connect(process.env.MONGODB_URI);
// connect to mongodb
connect(process.env.MONGODB_URI, error => { ... });

//fire the app
app.start(function(error, env) {
...
});
// fire http server
start(error => { ... });
```

## Testing
Expand Down
76 changes: 60 additions & 16 deletions es/index.js
@@ -1,6 +1,7 @@
import { pkg } from '@lykmapipo/common';
import _ from 'lodash';
import { pkg } from '@lykmapipo/common';
import { getString, getStringSet, apiVersion } from '@lykmapipo/env';
import { Router, start } from '@lykmapipo/express-common';
import async from 'async';
import moment from 'moment';
import actions from 'mongoose-rest-actions';
Expand All @@ -10,7 +11,6 @@ import { toE164 } from '@lykmapipo/phone';
import { createSubSchema, createSchema, ObjectId, Mixed, model } from '@lykmapipo/mongoose-common';
import { MODEL_NAME_ACCOUNT, POPULATION_MAX_DEPTH, COLLECTION_NAME_ACCOUNT } from '@codetanzania/majifix-common';
import { Jurisdiction } from '@codetanzania/majifix-jurisdiction';
import { Router } from '@lykmapipo/express-common';

/**
* @name Period
Expand Down Expand Up @@ -2365,17 +2365,22 @@ router.delete(PATH_ACCESSORS_SINGLE, function removeAccountAccountAccessors(
* @version 0.1.0
* @example
*
* const { app } = require('@codetanzania/majifix-account');
*
* ...
*
* app.start();
* const { Account, start } = require('@codetanzania/majifix-account');
* start(error => { ... });
*
*/

/* declarations */
/**
* @name info
* @description package information
* @type {object}
*
* @author lally elias <lallyelias87@gmail.com>
* @since 1.0.0
* @version 0.1.0
*/
const info = pkg(
'../package.json',
`${__dirname}/package.json`,
'name',
'description',
'version',
Expand All @@ -2389,28 +2394,67 @@ const info = pkg(

/* export function */
const account = integration => {
// ensure integration integration

// ensure integration
if (integration) {
const { fetchAccount } = integration;
if (_.isFunction(fetchAccount)) {
Account.fetchAccount = fetchAccount;
}
}

return account;
};

// export info
/**
* @name info
* @description package information
* @type {object}
*
* @author lally elias <lallyelias87@gmail.com>
* @since 1.0.0
* @version 0.1.0
*/
account.info = info;

// export apiVersion
/**
* @name apiVersion
* @description http router api version
* @type {string}
*
* @author lally elias <lallyelias87@gmail.com>
* @since 0.1.0
* @version 0.1.0
*/
account.apiVersion = apiVersion();

// export router
/**
* @name accountRouter
* @description account http router
*
* @author lally elias <lallyelias87@gmail.com>
* @since 0.1.0
* @version 0.1.0
*/
account.accountRouter = router;

// export Account
/**
* @name Account
* @description Account model
*
* @author lally elias <lallyelias87@gmail.com>
* @since 0.1.0
* @version 0.1.0
*/
account.Account = Account;

/**
* @function start
* @name start
* @description start http server
*
* @author lally elias <lallyelias87@gmail.com>
* @since 0.1.0
* @version 0.1.0
*/
account.start = start;

export default account;
107 changes: 33 additions & 74 deletions examples/app.js
@@ -1,76 +1,35 @@
/* ensure mongo uri */
process.env.MONGODB_URI =
process.env.MONGODB_URI || 'mongodb://localhost/majifix-account';

/* dependencies */
const path = require('path');
const _ = require('lodash');
const async = require('async');
const mongoose = require('mongoose');
// mongoose.set('debug', true);
const { get, mount, start } = require('@lykmapipo/express-common');
const { Jurisdiction } = require('@codetanzania/majifix-jurisdiction');

const { Account, accountRouter, apiVersion, info } = require(path.join(
__dirname,
'..'
));

let samples = require('./samples')(20);

/* connect to mongoose */
mongoose.connect(process.env.MONGODB_URI);

/**
*
*/
function boot() {
async.waterfall(
[
function clear(next) {
Account.remove(function(/* error, results */) {
next();
});
},

function clearJurisdiction(next) {
Jurisdiction.remove(function(/* error, results */) {
next();
});
},

function seedJurisdiction(next) {
const jurisdiction = Jurisdiction.fake();
jurisdiction.post(next);
},

function seedAccounts(jurisdiction, next) {
/* fake accounts */
samples = _.map(samples, function(sample, index) {
if (index % 2 === 0) {
sample.jurisdiction = jurisdiction;
}
return sample;
});
Account.create(samples, next);
},
],
function(error, results) {
/* expose module info */
get('/', function(request, response) {
response.status(200);
response.json(info);
});

// mount routers
mount(accountRouter);

/* fire the app */
start(function(error, env) {
console.log(`visit http://0.0.0.0:${env.PORT}/${apiVersion}/accounts`);
});
const { connect, jsonSchema } = require('@lykmapipo/mongoose-common');
const { accountRouter, info, apiVersion } = require('../lib');

const startHttpServer = () => {
get('/', (request, response) => {
response.status(200);
response.json(info);
});

get(`/${apiVersion}/schemas`, (request, response) => {
const schema = jsonSchema();
response.status(200);
response.json(schema);
});

// mount routers
mount(accountRouter);

// fire http serve
start((error, env) => {
if (error) {
throw error;
}
);
}

boot();
console.log(`visit http://0.0.0.0:${env.PORT}/${apiVersion}/accounts`);
});
};

// connect and start http server
connect(error => {
if (error) {
throw error;
}
startHttpServer();
});
20 changes: 8 additions & 12 deletions examples/samples.js
@@ -1,17 +1,13 @@
/* dependencies */
const _ = require('lodash');
const faker = require('@benmaruchu/faker');
const faker = require('@benmaruchu/faker'); // eslint-disable-line import/no-extraneous-dependencies
const moment = require('moment');
const { randomPoint } = require('mongoose-geojson-schemas');

const today = moment(new Date());
const periods = _.range(1, 4);
const phones = ['255719818179', '255714095061', '255756995069'];

/**
*
*/
function sample(n) {
const sample = n => {
return {
number: n > 0 ? faker.random.number(99999, 999999) : '55555',
identity: n > 0 ? faker.random.number(11111, 44444) : '44444',
Expand All @@ -23,15 +19,15 @@ function sample(n) {
address: faker.address.streetAddress(),
locale: 'en',
location: randomPoint(),
accessors: _.map(phones, function(phone, index) {
accessors: _.map(phones, (phone, index) => {
return {
name: faker.name.findName(),
phone,
email: faker.internet.email(),
verifiedAt: index > 0 ? new Date() : undefined,
};
}),
bills: _.map(periods, function(period) {
bills: _.map(periods, period => {
return {
number: faker.random.number(99999, 999999),
items: [
Expand Down Expand Up @@ -106,9 +102,9 @@ function sample(n) {
}),
active: true,
};
}
};

module.exports = function(size = 10) {
size = size > 0 ? size : 10;
return _.times(size, sample);
module.exports = (size = 10) => {
const number = size > 0 ? size : 10;
return _.times(number, sample);
};

0 comments on commit 1ee275c

Please sign in to comment.