<commit_before># AuthorizedSubResource extends [AuthorizedResource](/docs/authorizedResource.md)
`rest-io` supports Authorized Resources. The [UserResource](/docs/user.md) is mandatory to enable authorized resources.

## Quick Start
To create an Authorized Parent Resource:

```javascript
var restIO = require('rest-io');
var AuthorizedResource = restIO.AuthorizedResource;

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

To create a sub resource for the posts:

```javascript
var restIO = require('rest-io');
var AuthorizedSubResource = restIO.AuthorizedSubResource;
var blog = require('./blog');

var 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](http://docs.mongodb.org/manual/reference/method/db.collection.find/#db.collection.find) object.
Used during getting a single sub resource.

### createPullQuery(req)
Returns a [$pull query](http://docs.mongodb.org/manual/reference/operator/update/pull/) 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](http://docs.mongodb.org/manual/reference/operator/update/set/) object.
Used during updating a sub resource.<commit_msg>updated authorized sub resource<commit_after># AuthorizedSubResource extends [AuthorizedResource](/docs/authorizedResource.md)
`rest-io` supports Authorized Resources. The [UserResource](/docs/user.md) is mandatory to enable authorized resources.

## Quick Start
To create an Authorized Parent Resource:

```javascript
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:

```javascript
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](http://docs.mongodb.org/manual/reference/method/db.collection.find/#db.collection.find) object.
Used during getting a single sub resource.

### createPullQuery(req)
Returns a [$pull query](http://docs.mongodb.org/manual/reference/operator/update/pull/) 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](http://docs.mongodb.org/manual/reference/operator/update/set/) object.
Used during updating a sub resource.
{'fraction_non_alphanumeric': 0.11611842105263158, 'fraction_numerical': 0.0, 'mean_word_length': 4.870656370656371, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '749921', 'n_tokens_mistral': 863, 'n_tokens_neox': 830, 'n_words': 287}