# portal-models

> Enable sharing saas related mongodb models between apps.

Latest version **2.9.2** (published 2017-03-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install portal-models
pnpm add portal-models
yarn add portal-models
bun add portal-models
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.9.2 |
| Published | 2017-03-23 |
| First published | 2017-02-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+8 in 2 direct dependencies) |
| Install scripts | no |
| Author | Jean-Baptiste Louazel |
| Maintainers | plop |
| Keywords | mongoose, models, schemas |

## Links

- npm: https://www.npmjs.com/package/portal-models
- npm.io page: https://npm.io/package/portal-models

## Dependencies (5)

- [bcrypt](https://npm.io/package/bcrypt.md) ^0.8.5
- [crypto](https://npm.io/package/crypto.md) 0.0.3
- [lodash](https://npm.io/package/lodash.md) ^4.13.1
- [bluebird](https://npm.io/package/bluebird.md) ^3.3.4
- [mongoose](https://npm.io/package/mongoose.md) ^4.4.7

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 2.9.2 (latest) — 2017-03-23
- 2.9.1 — 2017-03-01
- 2.9.0 — 2017-02-28
- 2.8.0 — 2017-02-28

## README

# portal-models #

This project has for its first goal to uniformize MongoDB data across endpoints that require it with Mongoose.
Mongoose has for requirements to get schema of resources it will call in order to work. Duplicating schemas across projects will be hard to maintain since schemas like `user` need some libraries to work (bcrypt, etc...). 


### Installation

```sh
npm install --save portal-models
```

### Usage

In order to use it, you just need to import the model you need:
```javascript
const Report = require('portal-models').Report;

Report.create(...);
```


### Bluebird promises

The main advantage of using this library instead of an embedded existing schema is bluebird promises. It allows us some pretty manipulations instead of mongoose callbacks while using it:

```javascript
User
  .findOne({'statProviderId': ...})
  .then(user => // do stuff with user)
  .catch(error => // handle error);
``` 

Since it return promise, you can also yield for result from an ES6 generator:

```javascript
function* createUser() {
  try {
    let user = yield User.create({ firstName: 'John', lastName: 'Doe' });

    console.log(user.firstName, user.lastName); // Will print you 'John Doe', synchronous writing for asynchronous operations thanks to the yield.

  } catch(e) {
    console.log(e.message); // Will tell you why the operation has failed.
  }
}
```

---
_Source: https://npm.io/package/portal-models · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
