1
0
Fork 0
mirror of synced 2024-08-24 06:31:18 +12:00
appwrite/app/sdks/server-nodejs/lib/services/users.js

215 lines
5.3 KiB
JavaScript
Raw Normal View History

2020-01-28 10:50:41 +13:00
const Service = require('../service.js');
class Users extends Service {
/**
* List Users
*
* Get a list of all the project users. You can use the query params to filter
* your results.
*
* @param string search
* @param number limit
* @param number offset
* @param string orderType
* @throws Exception
* @return {}
*/
2020-01-31 05:18:59 +13:00
async list(search = '', limit = 25, offset = 0, orderType = 'ASC') {
2020-01-28 10:50:41 +13:00
let path = '/users';
return await this.client.call('get', path, {
'content-type': 'application/json',
},
{
'search': search,
'limit': limit,
'offset': offset,
'orderType': orderType
});
}
/**
* Create User
*
* Create a new user.
*
* @param string email
* @param string password
* @param string name
* @throws Exception
* @return {}
*/
2020-01-31 05:18:59 +13:00
async create(email, password, name = '') {
2020-01-28 10:50:41 +13:00
let path = '/users';
return await this.client.call('post', path, {
'content-type': 'application/json',
},
{
'email': email,
'password': password,
'name': name
});
}
/**
* Get User
*
* Get user by its unique ID.
*
* @param string userId
* @throws Exception
* @return {}
*/
2020-01-31 05:18:59 +13:00
async get(userId) {
2020-01-28 10:50:41 +13:00
let path = '/users/{userId}'.replace(new RegExp('{userId}', 'g'), userId);
return await this.client.call('get', path, {
'content-type': 'application/json',
},
{
});
}
/**
* Get User Logs
*
* Get user activity logs list by its unique ID.
*
* @param string userId
* @throws Exception
* @return {}
*/
2020-01-31 05:18:59 +13:00
async getLogs(userId) {
2020-01-28 10:50:41 +13:00
let path = '/users/{userId}/logs'.replace(new RegExp('{userId}', 'g'), userId);
return await this.client.call('get', path, {
'content-type': 'application/json',
},
{
});
}
/**
* Get User Preferences
*
* Get user preferences by its unique ID.
*
* @param string userId
* @throws Exception
* @return {}
*/
2020-01-31 05:18:59 +13:00
async getPrefs(userId) {
2020-01-28 10:50:41 +13:00
let path = '/users/{userId}/prefs'.replace(new RegExp('{userId}', 'g'), userId);
return await this.client.call('get', path, {
'content-type': 'application/json',
},
{
});
}
/**
* Update User Preferences
*
* Update user preferences by its unique ID. You can pass only the specific
* settings you wish to update.
*
* @param string userId
2020-02-14 19:28:54 +13:00
* @param object prefs
2020-01-28 10:50:41 +13:00
* @throws Exception
* @return {}
*/
2020-01-31 05:18:59 +13:00
async updatePrefs(userId, prefs) {
2020-01-28 10:50:41 +13:00
let path = '/users/{userId}/prefs'.replace(new RegExp('{userId}', 'g'), userId);
return await this.client.call('patch', path, {
'content-type': 'application/json',
},
{
'prefs': prefs
});
}
/**
* Get User Sessions
*
* Get user sessions list by its unique ID.
*
* @param string userId
* @throws Exception
* @return {}
*/
2020-01-31 05:18:59 +13:00
async getSessions(userId) {
2020-01-28 10:50:41 +13:00
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 {}
*/
2020-01-31 05:18:59 +13:00
async deleteSessions(userId) {
2020-01-28 10:50:41 +13:00
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
*
* Delete user sessions by its unique ID.
*
* @param string userId
* @param string sessionId
* @throws Exception
* @return {}
*/
2020-01-31 05:18:59 +13:00
async deleteSession(userId, sessionId) {
2020-05-02 16:23:56 +12:00
let path = '/users/{userId}/sessions/{sessionId}'.replace(new RegExp('{userId}', 'g'), userId).replace(new RegExp('{sessionId}', 'g'), sessionId);
2020-01-28 10:50:41 +13:00
return await this.client.call('delete', path, {
'content-type': 'application/json',
},
{
});
}
/**
* Update User Status
*
* Update user status by its unique ID.
*
* @param string userId
* @param string status
* @throws Exception
* @return {}
*/
2020-01-31 05:18:59 +13:00
async updateStatus(userId, status) {
2020-01-28 10:50:41 +13:00
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;