2019-06-10 06:13:55 +12:00
|
|
|
const Service = require('../service.js');
|
|
|
|
|
|
|
|
class Users extends Service {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List Users
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/users/list-users.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string search
|
|
|
|
* @param number limit
|
|
|
|
* @param number offset
|
|
|
|
* @param string orderType
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async listUsers(search = '', limit = 25, offset = 0, orderType = 'ASC') {
|
|
|
|
let path = '/users';
|
|
|
|
|
|
|
|
return await this.client.call('get', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
'search': search,
|
|
|
|
'limit': limit,
|
|
|
|
'offset': offset,
|
|
|
|
'orderType': orderType
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create User
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/users/create-user.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string email
|
|
|
|
* @param string password
|
|
|
|
* @param string name
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async createUser(email, password, name = '') {
|
|
|
|
let path = '/users';
|
|
|
|
|
|
|
|
return await this.client.call('post', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
'email': email,
|
|
|
|
'password': password,
|
|
|
|
'name': name
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get User
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/users/get-user.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string userId
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async getUser(userId) {
|
|
|
|
let path = '/users/{userId}'.replace(new RegExp('{userId}', 'g'), userId);
|
|
|
|
|
|
|
|
return await this.client.call('get', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get User Logs
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/users/get-user-logs.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string userId
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async getUserLogs(userId) {
|
|
|
|
let path = '/users/{userId}/logs'.replace(new RegExp('{userId}', 'g'), userId);
|
|
|
|
|
|
|
|
return await this.client.call('get', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get User Prefs
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/users/get-user-prefs.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string userId
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async getUserPrefs(userId) {
|
|
|
|
let path = '/users/{userId}/prefs'.replace(new RegExp('{userId}', 'g'), userId);
|
|
|
|
|
|
|
|
return await this.client.call('get', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-09 17:16:38 +13:00
|
|
|
/**
|
|
|
|
* Update Account Prefs
|
|
|
|
*
|
|
|
|
* /docs/references/users/update-user-prefs.md
|
|
|
|
*
|
|
|
|
* @param string userId
|
|
|
|
* @param string prefs
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async updateUserPrefs(userId, prefs) {
|
|
|
|
let path = '/users/{userId}/prefs'.replace(new RegExp('{userId}', 'g'), userId);
|
|
|
|
|
|
|
|
return await this.client.call('patch', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
'prefs': prefs
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-10 06:13:55 +12:00
|
|
|
/**
|
|
|
|
* Get User Sessions
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/users/get-user-sessions.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string userId
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async getUserSessions(userId) {
|
|
|
|
let path = '/users/{userId}/sessions'.replace(new RegExp('{userId}', 'g'), userId);
|
|
|
|
|
|
|
|
return await this.client.call('get', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete User Sessions
|
|
|
|
*
|
|
|
|
* Delete all user sessions by its unique ID.
|
|
|
|
*
|
|
|
|
* @param string userId
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async deleteUserSessions(userId) {
|
|
|
|
let path = '/users/{userId}/sessions'.replace(new RegExp('{userId}', 'g'), userId);
|
|
|
|
|
|
|
|
return await this.client.call('delete', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete User Session
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/users/delete-user-session.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string userId
|
|
|
|
* @param string sessionId
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
2019-10-09 17:16:38 +13:00
|
|
|
async deleteUserSession(userId, sessionId) {
|
2019-06-10 06:13:55 +12:00
|
|
|
let path = '/users/{userId}/sessions/:session'.replace(new RegExp('{userId}', 'g'), userId);
|
|
|
|
|
|
|
|
return await this.client.call('delete', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
'sessionId': sessionId
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update user status
|
|
|
|
*
|
2019-10-09 17:16:38 +13:00
|
|
|
* /docs/references/users/update-user-status.md
|
2019-06-10 06:13:55 +12:00
|
|
|
*
|
|
|
|
* @param string userId
|
|
|
|
* @param string status
|
|
|
|
* @throws Exception
|
|
|
|
* @return {}
|
|
|
|
*/
|
|
|
|
async updateUserStatus(userId, status) {
|
|
|
|
let path = '/users/{userId}/status'.replace(new RegExp('{userId}', 'g'), userId);
|
|
|
|
|
|
|
|
return await this.client.call('patch', path, {'content-type': 'application/json'},
|
|
|
|
{
|
|
|
|
'status': status
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Users;
|