You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. declare var $: Function;
  2. /**
  3. * Sends an ajax request to a directory service.
  4. *
  5. * @param {string} serviceUrl - The service to query.
  6. * @param {string} jwt - The jwt token to pass to the search service.
  7. * @param {string} text - Text to search.
  8. * @param {Array<string>} queryTypes - Array with the query types that will be
  9. * executed - "conferenceRooms" | "user" | "room".
  10. * @returns {Promise} - The promise created by the request.
  11. */
  12. export function searchPeople(// eslint-disable-line max-params
  13. serviceUrl,
  14. jwt,
  15. text,
  16. queryTypes = [ 'conferenceRooms', 'user', 'room' ]
  17. ) {
  18. const queryTypesString = JSON.stringify(queryTypes);
  19. return new Promise((resolve, reject) => {
  20. $.getJSON(`${serviceUrl}?query=${encodeURIComponent(text)}`
  21. + `&queryTypes=${queryTypesString}&jwt=${jwt}`,
  22. response => resolve(response)
  23. ).fail((jqxhr, textStatus, error) =>
  24. reject(error)
  25. );
  26. });
  27. }
  28. /**
  29. * Sends a post request to an invite service.
  30. *
  31. * @param {string} inviteServiceUrl - The invite service that generates the
  32. * invitation.
  33. * @param {string} inviteUrl - The url to the conference.
  34. * @param {string} jwt - The jwt token to pass to the search service.
  35. * @param {Immutable.List} inviteItems - The list of items to invite.
  36. * @returns {Promise} - The promise created by the request.
  37. */
  38. export function invitePeople(inviteServiceUrl, inviteUrl, jwt, inviteItems) { // eslint-disable-line max-params, max-len
  39. return new Promise((resolve, reject) => {
  40. $.post(`${inviteServiceUrl}?token=${jwt}`,
  41. JSON.stringify({
  42. 'invited': inviteItems,
  43. 'url': inviteUrl }),
  44. response => resolve(response),
  45. 'json')
  46. .fail((jqxhr, textStatus, error) =>
  47. reject(error)
  48. );
  49. });
  50. }