"use strict";
const debug = require('debug')('loopback:connector:jira.resource.user');
const baseResource_1 = require('./baseResource');
/**
* The user class for the Jira Connector
*
* @constructor user
* @property {IConnector} connector the jira connector instance
* @property {Model} model the model definition
*/
class user extends baseResource_1.baseResource {
constructor(connector, definition) {
super(connector, definition);
/**
* Creates a new session for a user in JIRA. Once a session has been successfully created it can be used to access any of JIRA's remote APIs and also the web UI
*
* @method login
* @memberOf user#
* @param {Object} options The request options passed onto the Jira API.
* @param {string} options.username The username to login with
* @param {string} options.password The password to login with
* @param [callback] if supplied, called with Array of matching records
* @return {Promise.<Array>} Array of matching records
*/
this.login = (options = {}, callback) => {
return this.connector.login(options, callback);
};
/**
* Logs the current user out of JIRA, destroying the existing session, if any.
*
* @method logout
* @memberOf user#
* @param {Object} options The request options passed onto the Jira API.
* @param {string} [options.token] The token to use for authentication. This token is supplied on a sucessful login. If not supplied, the default token (if set) is used
* @param {string} options.username The username to logout
* @param [callback] if supplied, called with Array of matching records
* @return {Promise.<Array>} Array of matching records
*/
this.logout = (options = {}, callback) => {
return this.connector.logout(options, callback);
};
/**
* Returns a list of users that match the search string and/or property. This resource cannot be accessed anonymously.
*
* @method find
* @memberOf user#
* @param {Object} options The request options passed onto the Jira API.
* @param {string} [options.token] The token to use for authentication. This token is supplied on a sucessful login. If not supplied, the default token (if set) is used
* @param {string} options.username A query string used to search username, name or e-mail address
* @param {number} [options.startAt=0] the index of the first user to return (0-based)
* @param {number} [options.maxResults=50] the maximum number of users to return (defaults to 50). The maximum allowed value is 1000. If you specify a value that is higher than this number, your search results will betruncated.
* @param {boolean} [options.includeActive=true] If true, then active users are included in the results (default true)
* @param {boolean} [options.includeInactive=false] If true, then inactive users are included in the results (default false)
* @param [callback] if supplied, called with Array of matching records
* @return {Promise.<Array>} Array of matching records
*/
this.find = (options = {}, callback) => {
options.username = options.username || ".";
return this.makeRequest("find", options, callback);
};
/**
* Returns a user. This resource cannot be accessed anonymously. The resource accepts the expand param that is used to include, hidden by default, parts of response. This can be used to include:
* groups - all groups, including nested groups, to which user belongs
* applicationRoles - application roles defines to which application user has access
*
* @method findById
* @memberOf user#
* @param {Object} options The request options passed onto the Jira API.
* @param {string} [options.token] The token to use for authentication. This token is supplied on a sucessful login. If not supplied, the default token (if set) is used
* @param {string} [options.id] The key or username of the user to find
* @param [callback] if supplied, called with Array of matching records
* @return {Promise.<Object>} the selected Project
*/
this.findById = (options = {}, callback) => {
return this.makeRequest("findById", options, callback);
};
/* ** */
/**
* Deletes a project
*
* @method deleteById
* @memberOf project#
* @param {Object} options The request options passed onto the Jira API.
* @param {string} [options.id] The key or id of the project to delete
* @param [callback] if supplied, called with Array of matching records
* @return {Promise.<Object>} the selected Project
*/
this.deleteById = (options = {}, callback) => {
return this.makeRequest("deleteById", options, callback);
};
/**
* Creates a project.
*
* @method create
* @memberOf ProjectClient#
* @param {Object} options The request options sent to the Jira API. See {@link https://docs.atlassian.com/jira/REST/latest/#api/2/project}
* @param {string} options.key The key of the project
* @param {string} options.name The name of the project
* @param {string} options.lead The name of the user leading the project
* @param [callback] Called when the project has been created.
* @return {Promise} Resolved when the project has been created.
*/
this.create = (options = {}, callback) => {
return this.makeRequest("create", options, callback);
};
this.register();
}
}
exports.user = user;