Skip to content

Commit

Permalink
feat(GlpiRestClient): change active profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianfranco97 authored and Hector Rondon committed Jan 23, 2018
1 parent 4889475 commit d5cdf01
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/prepareRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ function prepareRequest (data) {
}
break

case 'changeActiveProfile':
url = `${url}/changeActiveProfile/`
body = {}
if (data.profilesId) body = {"profiles_id": data.profilesId}
myInit = {
method: 'POST',
body: JSON.stringify(body)
}
break

default:
break
}
Expand Down
32 changes: 31 additions & 1 deletion src/restclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@ class GlpiRestClient {
const response = await fetch (myRequest)
switch (functionName) {
case 'killSession':
if (response.ok) {
if (response.ok) {
responseHandler(await response.text(), response.ok)
} else {
responseHandler(await response.json(), response.ok)
}
break

case 'changeActiveProfile':
if (response.ok) {
responseHandler(await response.text(), response.ok)
} else {
responseHandler(await response.json(), response.ok)
}
break

default:
responseHandler(await response.json(), response.ok)
Expand Down Expand Up @@ -423,6 +431,28 @@ class GlpiRestClient {
})
}

changeActiveProfile (profilesId) {
return new Promise((resolve, reject) => {
try {
const data = {
function: 'changeActiveProfile',
profilesId
}

this._makeRequest( prepareRequest(data), 'changeActiveProfile', (response, isOk) => {
if (isOk) {
resolve ( response )
} else {
reject (response)
}
})
}
catch (err) {
reject(err)
}
})
}

registerUser (userToken, userData) {
return new Promise(async (resolve, reject) => {
try {
Expand Down

0 comments on commit d5cdf01

Please sign in to comment.