diff --git a/src/prepareRequest.js b/src/prepareRequest.js index fa8b916..9453de3 100644 --- a/src/prepareRequest.js +++ b/src/prepareRequest.js @@ -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 @@ -102,6 +110,7 @@ function prepareRequest (data) { url = `${url}${queryString ? '' : '?'}session_token=${config.sessionToken}` } + console.log(url) myInit = { ...myInit, headers: myHeaders diff --git a/src/restclient.js b/src/restclient.js index 805aa7b..585a33f 100644 --- a/src/restclient.js +++ b/src/restclient.js @@ -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 {