mongoose-isowner

1.0.1 • Public • Published

mongoose-isowner

Build Status npm npm

Mongoose plugin for ownership determination by calling [Model].isOwner(doc, user)

Installation

npm install --save mongoose-isowner

Usage

const mongoose = require('mongoose')
const Schema = mongoose.Schema
const mongooseIsOwner = require('mongoose-isowner')
 
let YourSchema = new Schema({
  title: String,
  description: String,
  author: String,
})
 
YourSchema.plugin(mongooseIsOwner, {
  resolver: function(doc, user) {
    return doc.owner.equals(user._id)
  },
})
 
let Model = mongoose.model('YourSchema', YourSchema)

After setting up, you can call .isOwner(doc, user) on your model which will determine if the user is the owner.

Model.isOwner(doc, user)

License

The MIT License Copyright (c) Carsten Jacobsen

Package Sidebar

Install

npm i mongoose-isowner

Weekly Downloads

22

Version

1.0.1

License

MIT

Unpacked Size

10.8 kB

Total Files

7

Last publish

Collaborators

  • crsten