Skip to content

Latest commit

 

History

History
49 lines (38 loc) · 1.42 KB

authorizedSubResource.md

File metadata and controls

49 lines (38 loc) · 1.42 KB

AuthorizedSubResource extends AuthorizedResource

rest-io supports Authorized Resources. The UserResource is mandatory to enable authorized resources.

Quick Start

To create an Authorized Parent Resource:

import { AuthorizedResource } from 'rest-io';

export const blog = new AuthorizedResource({
  name: 'blog',
  model: {
    title: String,
    posts: [{
      message: String
    }]
  }
});

To create a sub resource for the posts:

import { AuthorizedSubResource } from 'rest-io';
import blog from './blog';

export const posts = new AuthorizedSubResource({
  name: 'post',
  parentResource: blog
});

API

The Authorized Sub Resource allows you to easily configure per method what roles have access to them.

createProjectionQuery(req)

Returns a projection query object. Used during getting a single sub resource.

createPullQuery(req)

Returns a $pull query object. Used during deleting a sub resource.

createFindQuery(req)

Returns a query to single out the sub resource within it's parent. Used during updating a sub resource.

createSubUpdate(req)

Returns a $set query object. Used during updating a sub resource.