Skip to content

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
IonicaBizau committed Aug 29, 2017
1 parent 1825909 commit eddbb28
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 69 deletions.
39 changes: 4 additions & 35 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,13 @@

You can see below the API reference of this module.

### Plugin Configuration
### bloggify:init

- `db` (String): The database url.
#### Params
- **Object** `config`:
- `uri` (String): The database url.
- `models` (Object): An object containing the Mongoose models.
- `models_dir` (String): The relative path to a directory containing models stored in files.

The model objects can be accessed by requiring the module or accessing the `Bloggify.models` object.

### `model.addHook(type, event, fn)`
Add `pre/post` hooks to the model operations.

Example:

```js
const EMAIL_BLACKLIST = ["[email protected]"];

// Do something before saving
Bloggify.models.User.addHook("pre", "save", function (next) {
if (EMAIL_BLACKLIST.includes(this.email)) {
return next(new Error("This email is blacklisted."));
}
next();
});

// Do something after saving a document
Bloggify.models.User.addHook("post", "save", function (next) {
console.log("User was saved: ", this);
next();
});
```
#### Params
- **String** `type`: The Mongoose hook type (`pre` or `post`).
- **String** `event`: The Mongoose event name. Valid events are:
- `init`
- `validate`
- `save`
- `remove`

Find more information about this in the [Mongoose documentation](http://mongoosejs.com/docs/middleware.html).
- **Function** `fn`: The callback function called with the Model instance as context and with a `next` handler.

51 changes: 17 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,56 +53,39 @@ module.exports = {
};
```

## :memo: Documentation
## :question: Get Help

There are few ways to get help:

### Plugin Configuration
1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question.
2. For bug reports and feature requests, open issues. :bug:
3. For direct and quick help from me, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:

- `db` (String): The database url.
- `models` (Object): An object containing the Mongoose models.
- `models_dir` (String): The relative path to a directory containing models stored in files.

The model objects can be accessed by requiring the module or accessing the `Bloggify.models` object.
## :memo: Documentation

### `model.addHook(type, event, fn)`
Add `pre/post` hooks to the model operations.

Example:
### bloggify:init

```js
const EMAIL_BLACKLIST = ["[email protected]"];

// Do something before saving
Bloggify.models.User.addHook("pre", "save", function (next) {
if (EMAIL_BLACKLIST.includes(this.email)) {
return next(new Error("This email is blacklisted."));
}
next();
});

// Do something after saving a document
Bloggify.models.User.addHook("post", "save", function (next) {
console.log("User was saved: ", this);
next();
});
```
#### Params
- **String** `type`: The Mongoose hook type (`pre` or `post`).
- **String** `event`: The Mongoose event name. Valid events are:
- `init`
- `validate`
- `save`
- `remove`
- **Object** `config`:
- `uri` (String): The database url.
- `models` (Object): An object containing the Mongoose models.
- `models_dir` (String): The relative path to a directory containing models stored in files.

Find more information about this in the [Mongoose documentation](http://mongoosejs.com/docs/middleware.html).
- **Function** `fn`: The callback function called with the Model instance as context and with a `next` handler.
The model objects can be accessed by requiring the module or accessing the `Bloggify.models` object.



## :yum: How to contribute
Have an idea? Found a bug? See [how to contribute][contributing].


## :dizzy: Where is this library used?
If you are using this library in one of your projects, add it in this list. :sparkles:


- [`bloggify.org`](https://github.com/Bloggify/newww#readme) (by Bloggify)—The Bloggify.org website source code.

## :scroll: License

Expand Down

0 comments on commit eddbb28

Please sign in to comment.