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

DiscussService

Extends:

AbstractServiceJsonApiService → DiscussService

Service handling comment calls with specific endpoints.

Typically this shouldn't be used directly but by using some of the other modules that support comment functionality. Currently this includes Content, Flow, FlowStep, Profile, Question, and MobileUser.

Constructor Summary

Public Constructor
public

Update type to be commentable__threads

Member Summary

Public Members
public

Method Summary

Public Methods
public

get(data: Object, cacheMode: String): Promise<Thread[]>

Get or filter threads.

public

getComments(thread: Object, cacheMode: String): Promise<Comment[]|Comment>

Fetches comments associated to a specific object.

public

insert(data: Object, cacheMode: String): Promise<Thread>

Insert Thread

public

insertComment(text: String, thread: Object, author: Object, cacheMode: String): Promise<Comment>

Insert Comment

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 commentable__threads

Override:

JsonApiService#constructor

Public Members

public type: String source

Override:

AbstractService#type

Public Methods

public get(data: Object, cacheMode: String): Promise<Thread[]> source

Get or filter threads.

Override:

JsonApiService#get

Params:

NameTypeAttributeDescription
data Object
  • nullable: false

Object in which to have a discussion

data.id Number
  • nullable: false

Object id to start a discussion on

data.type String
  • nullable: false

Object type to start a discussion on

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Thread[]>

Promise a thread

Throw:

Clinical6Error

If missing required parameters

Example:

import { discussService } from 'clinical6';

discussService.get();  // get all threads

// Get threads from a flow
myFlow = new Flow({...});
discussService.get(myFlow);

// This is also called from other objects in the system like a flow or flowstep.
// In this case, it will use the flow/flowstep owner and object information automatically.
myFlow.getThreads();
myFlow.first.getThreads();  // FlowStep Comments

public getComments(thread: Object, cacheMode: String): Promise<Comment[]|Comment> source

Fetches comments associated to a specific object.

Params:

NameTypeAttributeDescription
thread Object
  • nullable: false

The thread having comments

options.id Number
  • nullable: false

The thread id

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Comment[]|Comment>

Promise object that returns success or failure

Throw:

Clinical6Error

If missing token or missing required parameters

Example:

import { discussService } from 'clinical6';

const thread = new Thread({...});
discussService.getComments(thread);

public insert(data: Object, cacheMode: String): Promise<Thread> source

Insert Thread

Override:

JsonApiService#insert

Params:

NameTypeAttributeDescription
data Object
  • nullable: false

Object in which to have a discussion

data.id Number
  • nullable: false

Object id to start a discussion on

data.type String
  • nullable: false

Object type to start a discussion on

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Thread>

Promise a thread

Throw:

Clinical6Error

If missing required parameters

Example:

import { discussService } from 'clinical6';
const thread = await discussService.insert(myFlow);

public insertComment(text: String, thread: Object, author: Object, cacheMode: String): Promise<Comment> source

Insert Comment

Params:

NameTypeAttributeDescription
text String
  • nullable: false

The comment text

thread Object
  • nullable: false

The discussion thread

thread.id Number
  • nullable: false

Thread id to start a discussion on

thread.type String
  • nullable: false

Thread type to start a discussion on

author Object
  • optional
  • nullable: false

The author of the comment

author.id Number
  • optional
  • nullable: false

Author id

author.type String
  • optional
  • nullable: false

Author type ('mobile_users' or 'users')

cacheMode String
  • optional

Override the caching method for this call

Return:

Promise<Comment>

Promise a thread

Throw:

Clinical6Error

If missing required parameters

Example:

import { discussService, Thread, MobileUser } from 'clinical6';
const thread = new Thread({...});
const author = new MobileUser({...});
const comment = await discussService.insertComment('Hello World', thread);