# mongoose-requests

> A mongoose plugin for creating requests between users

Latest version **1.1.2** (published 2018-08-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install mongoose-requests
pnpm add mongoose-requests
yarn add mongoose-requests
bun add mongoose-requests
```

## 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 | 1.1.2 |
| Published | 2018-08-03 |
| First published | 2018-07-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.4 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| Author | Hiram Cruz |
| Maintainers | forgiv |
| Keywords | mongoose, requests |

## Links

- npm: https://www.npmjs.com/package/mongoose-requests
- Repository: https://github.com/forgiv/mongoose-requests
- npm.io page: https://npm.io/package/mongoose-requests

## Dependencies (1)

- [mongoose](https://npm.io/package/mongoose.md) ^5.0.0

## 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

- 1.1.2 (latest) — 2018-08-03
- 1.1.1 — 2018-08-03
- 1.1.0 — 2018-07-27
- 1.0.4 — 2018-07-26
- 1.0.3 — 2018-07-26
- 1.0.1 — 2018-07-26
- 1.0.0 — 2018-07-25

## README

# mongoose-requests

Mongoose ODM plugin for handling requests between users.

## Installation

with npm:  
`npm install mongoose-requests`  
with yarn:  
`yarn add mongoose-requests`

## Description

mongoose-requests makes it easy to handle requests between user models. Requests are stored as an array of subdocuments under the user schema. All functions have both static and instance forms and return JavaScript promises.

## Usage

Start by including the plugin in the schema:

```
const mongoose = require('mongoose')
const requests = require('mongoose-requests')
const schema = new mongoose.Schema({
  // regular schema building
})

// optionally one may specify both
// the name of the field that will be added
// and the name of the model that it will be added to
schema.plugin(requests, { userModel: 'Racer', propName: 'challenges' })

const Racer = mongoose.model('Racer', schema)
```

Send a request from one document to another either:  
```
Racer.sendRequest(racer1._id, racer2._id)
```

Requests can be fetched with getRequests
```
Racer.getRequests(racer1._id)
  .then(requests => console.log(requests))
```

A request document looks like this:
```
{
  sender: [racer1._id],
  receiver: [racer2._id],
  status: [one of ('pending', 'accepted', 'denied', 'requested')]
  sent: [Date request was sent],
  responded: [Date request was responded to or null]
}
```

One can either accept a request:
```
Racer.acceptRequest(racer2._id, racer1._id)
```

Or deny a request:
```
Racer.denyRequest(racer2._id, racer1._id)
```

Finally, can get all requests of a particular status:
```
Racer.getOfStatus(racer1._id, 'accepted')
  .then(requests => console.log(requests))
```

Want to cancel a request? Just delete it:
```
Racer.deleteRequest(racer1._id, racer2._id)
```

All functions have instance versions:
```
racer1.sendRequest(racer2._id)
```
```
racer2.getRequests().then(requests => console.log(requests))
```
```
racer2.acceptRequest(racer1._id)
```
```
racer1.getOfStatus('accepted').then(requests => console.log(requests))
```
```
racer1.deleteRequest(racer2._id)
```

## What's next?

mongoose-requests is still very much in its infancy, and will be expanded upon in the future. Need a specific feature that you think would fit in nicely? Submit a feature request as an issue and I'll see what I can do.

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