From f00ad09ead21f46e4efc907e71d7507a5b9e3b0b Mon Sep 17 00:00:00 2001 From: Leela Krishna Kadiri Date: Mon, 12 Mar 2018 13:38:49 -0600 Subject: [PATCH] [SB-1001] GLOBAL SKILLS - Create/Update user, get all locations --- .gitignore | 8 +++++++- index.js | 34 +++++++++++++++++++++++++++++++++- utilities/url.js | 3 +-- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 7e40d2d..b65d135 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,10 @@ node_modules/ # Built files coverage/ -__TEST__/ \ No newline at end of file +__TEST__/ + +# Logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* \ No newline at end of file diff --git a/index.js b/index.js index e3f969e..3aa1aee 100644 --- a/index.js +++ b/index.js @@ -99,12 +99,44 @@ class Sprucebot { * Get a user without a location. GLOBAL SKILLS ONLY * * @param {String} userId - * @param {Object} Optional query stirng to be added to the request + * @param {Object} Optional query string to be added to the request */ async globalUser(userId, query) { return this.https.get(`/users/${userId}`, query) } + /** + * Get all locations. GLOBAL SKILLS ONLY + * + * @param {Object} Optional query string to be added to the request + */ + async globalLocations(query) { + return this.https.get(`/ge/locations`, query) + } + + /** + * Create a user + * + * @param {Object} values + * @returns {Promise} + */ + async createUser(values) { + return this.https.post('/ge/users', values) + } + + /** + * Update a users role + * + * @param {String} locationId + * @param {String} userId + * @param {String} role + * @returns {Promise} + */ + async updateRole(locationId, userId, role) { + return this.https.patch( + `/ge/locations/${locationId}/users/${userId}/${role}` + ) + } /** * Search for users who have been to this location * diff --git a/utilities/url.js b/utilities/url.js index f1c4f00..3c8f8fe 100644 --- a/utilities/url.js +++ b/utilities/url.js @@ -25,9 +25,8 @@ module.exports = { // Construct URL using the query pathWithQuery += pathWithQuery.search(/\?/) === -1 ? '?' : '&' if (query) { - pathWithQuery += '&' + this.serialize(query) + pathWithQuery += this.serialize(query) } - return pathWithQuery } }