Skip to content

Commit

Permalink
feat(GlpiRestClient): delete item
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianfranco97 authored and Hector Rondon committed Jan 19, 2018
1 parent ac337f9 commit a309c0e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/prepareRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ function prepareRequest (data) {
url = `${url}/${data.itemtype.name}/${data.id}/${data.subItemtype.name}${queryString ? queryString : ''}`
myInit = { method: 'GET' }
break

case 'deleteItem':
url = `${url}/${data.itemtype.name}/${data.id ? data.id : ''}${ queryString ? queryString : '' }`
myInit = {
method: 'DELETE',
body: JSON.stringify({input: data.input})
}
break

default:
break
Expand All @@ -102,6 +110,7 @@ function prepareRequest (data) {
url = `${url}${queryString ? '' : '?'}session_token=${config.sessionToken}`
}

console.log(url)
myInit = {
...myInit,
headers: myHeaders
Expand Down
34 changes: 34 additions & 0 deletions src/restclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,40 @@ class GlpiRestClient {
})
}

deleteItem (itemtype, id, input, queryString) {
return new Promise((resolve, reject) => {
try {
if (!itemtype) reject ('Invalid itemtype')
if (itemtype !== ITEMTYPE[itemtype.name]) reject ('Invalid itemtype')

const data = {
function: 'deleteItem',
itemtype,
queryString,
input,
id
}

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

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

0 comments on commit a309c0e

Please sign in to comment.