Skip to content

ElderAS/mongoose-isowner

Repository files navigation

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

About

Mongoose plugin for ownership determination

Resources

License

Stars

Watchers

Forks

Packages

No packages published