UNPKG

mongodb-atlas-api-client

Version:
69 lines (59 loc) 1.99 kB
const {getQueryStringFromOptions} = require("./helper"); class AtlasUser { constructor(client, baseUrl, projectId) { this.client_ = client; this.baseUrl_ = baseUrl; this.projectId_ = projectId; } async getByName(username, options = {}) { const queryString = getQueryStringFromOptions(options); const httpOptions = options.httpOptions; const response = ( await this.client_.fetch(`${this.baseUrl_}/users/byName/${username}?${queryString}`, httpOptions) ); return response; } async getById(userId, options = {}) { const queryString = getQueryStringFromOptions(options); const httpOptions = options.httpOptions; const response = ( await this.client_.fetch(`${this.baseUrl_}/users/${userId}?${queryString}`, httpOptions) ); return response; } async getAll(options = {}) { const queryString = getQueryStringFromOptions(options); const httpOptions = options.httpOptions; const response = ( await this.client_.fetch(`${this.baseUrl_}/groups/${this.projectId_}/users?${queryString}`, httpOptions) ); return response; } async update(userId, body, options = {}) { const queryString = getQueryStringFromOptions(options); const httpOptions = options.httpOptions; const response = ( await this.client_.fetch(`${this.baseUrl_}/users/${userId}?${queryString}`, { "method": "PATCH", "data": body, "headers": {"Content-Type": "application/json"}, ...httpOptions }) ); return response; } async create(body, options = {}) { const queryString = getQueryStringFromOptions(options); const httpOptions = options.httpOptions; const response = ( await this.client_.fetch(`${this.baseUrl_}/users?${queryString}`, { "method": "POST", "data": body, "headers": {"Content-Type": "application/json"}, ...httpOptions }) ); return response; } } module.exports = AtlasUser;