Skip to content

Commit

Permalink
updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nataniel López committed May 19, 2020
1 parent 685d900 commit b867c19
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 58 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Added
- `databaseSettings` parameter for `postSaveHook()` method
- `databaseSettingsSource` getter to specify other settings source for client DB config

### Changed
- `Client` Model now set the new clients databaseKey from config

### Fixed
- `Client Create API` `postSaveHook()` client codes parameter
Expand Down
84 changes: 27 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@


## Introduction
This package includes all the generic functionality of the creation of a client at the services. It main purpose is to avoid code repetition.
This package includes all the generic functionality of the creation of a client at the services. It main purpose is to avoid code repetition.

## Installation
```sh
npm install @janiscommerce/client-creator
Expand All @@ -14,6 +15,31 @@ npm install @janiscommerce/client-creator

After installing this package you should create or update the following files:

### Service settings (.janiscommercerc)
You should configure the database config in your service, in order to get the correct DB config for new clients:

#### .janiscommercerc.json
```js
{
"database": {
"core": { // DB config where save new clients
"type": "mongodb",
"host": "core-host"
// ...
},
"newClients": { // DB config that the clients will use
"type": "mongodb",
"host": "clients-host"
// ...
}
},
"clients": {
"databaseKey": "newClients", // The new clients config databaseKey,
"table": "clients" // The clients table where create the clients ("clients" by default)
}
}
```

### ClientModel
At `./[MS_PATH]/models/client.js`

Expand Down Expand Up @@ -72,7 +98,6 @@ const { helper } = require('sls-helper'); // eslint-disable-line
const functions = require('./serverless/functions.json');
const { clientFunctions } = require('@janiscommerce/client-creator');


module.exports = helper({
hooks: [
// other hooks
Expand Down Expand Up @@ -111,61 +136,6 @@ Finally, create or update `./.nycrc` to avoid coverage leaks:

:warning: If exists any customization of the files, do not add the file to the .nyrcr and add the corresponding tests.

### Getters
Both `APICreate` and `ListenerCreated` have a getter for customize the client creation settings.

#### `databaseSettingsSource` (*`instance getter`*): Is the database config source key that will be getted from your MS database config. Default: `clientModel.databaseKey`.

##### Example

##### .janiscommercerc
```js
{
"database":{
"newClients": {
type: 'mongodb',
host: 'core-host'
// ...
},
otherDb: {
host: 'http://clients-host:8983',
type: 'solr'
}
}
}
```

##### `./[MS_PATH]/api/client/post.js`
```js
'use strict';
const { APICreate } = require('@janiscommerce/client-creator')

class ClientCreateAPI extends APICreate {

get databaseSettingsSource() {
return 'otherDb';
}
}

module.exports = ClientCreateAPI;
```

##### `./[MS_PATH]/event-listeners/id/client/created.js`
```js
'use strict';
const { ServerlessHandler } = require('@janiscommerce/event-listener');
const { ListenerCreated } = require('@janiscommerce/client-creator');

class ClientCreateListener extends ListenerCreated {

get databaseSettingsSource() {
return 'otherDb';
}
}

module.exports.handler = (...args) => ServerlessHandler.handle(ClientCreateListener, ...args);
```

### Hooks
Both `APICreate` and `ListenerCreated` have a hook for post processing the client or clients created data.

Expand Down

0 comments on commit b867c19

Please sign in to comment.