Manual Reference Source Test
import RoleService from 'clinical6/src/services/RoleService.js'
public class | source

RoleService

Extends:

AbstractServiceJsonApiService → RoleService

Service handling UserRole calls with specific endpoints.

Constructor Summary

Public Constructor
public

Update type to be user_roles

Method Summary

Public Methods
public

async delete(object: Object, cacheMode: String): Promise

public

async deletePermission(permission: Permission, cacheMode: String): Promise

public

async get(params: Object, cacheMode: String): Promise<Role[]|Role>

public
public

async getInvitableRoles(role: Object, cacheMode: String): Promise<Role[]|Role>

public
public

async insert(role: Role, cacheMode: String): Promise<Role>

public

async insertPermission(permission: Permission, cacheMode: String): Promise<Permission>

public

async update(role: UserRole, cacheMode: String): Promise<Role>

Inherited Summary

From class AbstractService
public get
public set
public
private
From class JsonApiService
public

options: *

public

async delete(obj: Object, options: String): Promise

Call a DELETE request on the main obj.type expecting JSON API information.

public

async get(params: Object, options: String): Promise

Call a GET request expecting JSON API information.

public

async getChildren(parent: Object, child: Object, options: String): Promise

Call a GET request expecting JSON API information for children given a parent.

public

async insert(obj: Object, options: String): Promise

Call a POST request on the main obj.type expecting JSON API information.

public

async update(obj: Object, options: String): Promise

Call a PATCH request on the main obj.type expecting JSON API information.

Public Constructors

public constructor() source

Update type to be user_roles

Override:

JsonApiService#constructor

Public Methods

public async delete(object: Object, cacheMode: String): Promise source

Call a DELETE request on the main obj.type expecting JSON API information.

Override:

JsonApiService#delete

Params:

NameTypeAttributeDescription
object Object

Object in which to delete

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise

Message

Test:

public async deletePermission(permission: Permission, cacheMode: String): Promise source

Params:

NameTypeAttributeDescription
permission Permission

Permission object in which to delete

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise

Message

Example:

import { roleService } from 'clinical6';

// You will be able to delete a permission using `delete`.
roleService.delete({ id: 23 });
// This will also clear the local storage of this type and id

Test:

public async get(params: Object, cacheMode: String): Promise<Role[]|Role> source

Call a GET request expecting JSON API information.

Override:

JsonApiService#get

Params:

NameTypeAttributeDescription
params Object
  • optional

Parameters used to get information from server (such as id)

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Role[]|Role>

Promise object that returns one role or a key:role hashtable

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { roleService } from 'clinical6';

// You will be able to access these roles using the `get` method.
roleService.get().then(roles => console.log(roles));

// Additionally, you can retrieve a specific role with the `get`
// method, using the ID of the desired role as a parameter.
roleService.get({ id: 23}).then(role => console.log(role));

Test:

public getAuthorizableResources(): Promise<[Object]> source

Return:

Promise<[Object]>

Promise object that returns an array of Flow, ContentType, and Section objects.

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { roleService } from 'clinical6';

// You will be able to access authorizable data using the `get` method.
roleService.getAuthorizableResources().then(authorizables => console.log(authorizables));

public async getInvitableRoles(role: Object, cacheMode: String): Promise<Role[]|Role> source

Params:

NameTypeAttributeDescription
role Object
  • optional

Role to grab invitable user roles for

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Role[]|Role>

Promise object that returns one role or a key:role hashtable

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { roleService } from 'clinical6';

// You will be able to access the invitable user roles using the `get` method.
roleService.getInvitableRoles({ id: 5 }).then(roles => console.log(roles));

Test:

public async getPermissions(role: Object, options: String): Promise<Permission[]|Permission> source

Params:

NameTypeAttributeDescription
role Object
  • optional

Role to grab invitable user roles for

options String
  • optional

Modify the nature of the call and response

options.url String
  • optional

Override the url for this call

options.cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Permission[]|Permission>

Promise object that returns one role or a key:role hashtable

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { roleService } from 'clinical6';

// You will be able to access the role permissions using the `get` method.
roleService.getPermissions().then(roles => console.log(roles));

public async insert(role: Role, cacheMode: String): Promise<Role> source

Call a POST request on the main obj.type expecting JSON API information.

Override:

JsonApiService#insert

Params:

NameTypeAttributeDescription
role Role

Role object in which to insert

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Role>

Inserted role

Example:

import { Role, roleService } from 'clinical6';
const user = new Role({...});

// you can insert a role using the `insert` method.
roleService.insert(role).then(role => console.log(role));

// you could also just call `save` on the role if it doesn't have an id, which will also
// invoke the `insert` method
role.save();

Test:

public async insertPermission(permission: Permission, cacheMode: String): Promise<Permission> source

Params:

NameTypeAttributeDescription
permission Permission

Permission object in which to insert

permission.role Role

Role object in which to insert

permission.authorizable Object

Object in which to insert

permission.allowedAction AllowedAction
  • optional

Optional allowedAction object in which to insert

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Permission>

Inserted permission

Example:

import { Permission, Role, roleService } from 'clinical6';
const permission = new Permission({...});
permission.authorizable = {id: 117, type: 'sections'}
permission.role = new Role({...})

// you can insert a permission using the `insertPermission` method.
roleService.insertPermssion(permission).then(permission => console.log(permission));

public async update(role: UserRole, cacheMode: String): Promise<Role> source

Call a PATCH request on the main obj.type expecting JSON API information.

Override:

JsonApiService#update

Params:

NameTypeAttributeDescription
role UserRole

Role object in which to update

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Role>

Updated role

Example:

import { Role, roleService } from 'clinical6';
const role = new Role({...});

// you can update a role using the `update` method.
roleService.update(role).then(role => console.log(role));

// you could also just call `save` on the role if it has an id, which will also
// invoke the `update` method
role.save();

Test: