Skip to content

Commit

Permalink
feat(GlpiRestClient): search items
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianfranco97 authored and Hector Rondon committed Jan 24, 2018
1 parent 2065bbe commit d7328d8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/prepareRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,21 @@ function prepareRequest (data) {
break

case 'getMultipleItems':

queryString = `?${createQueryString(data.items)}${createQueryString(data.options)}`

url = `${url}/getMultipleItems${queryString}`

myInit = { method: 'GET' }
break

case 'searchItems':
queryString = `?${createQueryString(data.criteria)}${createQueryString(data.metacriteria)}${createQueryString(data.options)}`

url = `${url}/search/${data.itemtype}/${queryString}`

myInit = { method: 'GET' }
break

default:
break
}
Expand Down
25 changes: 25 additions & 0 deletions src/restclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,31 @@ class GlpiRestClient {
})
}

searchItems (itemtype, criteria, metacriteria, options) {
return new Promise((resolve, reject) => {
try {
const data = {
function: 'searchItems',
itemtype,
criteria,
metacriteria,
options
}

this._makeRequest( prepareRequest(data), 'searchItems', (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 d7328d8

Please sign in to comment.