tag.js

  1. /**
  2. * @class
  3. * @classdesc API for the Tag entities, which give extra visual information about a given entity.
  4. */
  5. export const TagAPI = superclass =>
  6. class extends superclass {
  7. /**
  8. * Returns all tags in the registry.
  9. *
  10. * @memberof TagAPI
  11. * @param {Object} options An object of options to configure the query and
  12. * its results.
  13. * @returns {Promise} The tag result list.
  14. */
  15. async listTags(options = {}) {
  16. const url = this.baseUrl + "tags";
  17. const contents = await this.get(url, options);
  18. return contents;
  19. }
  20. /**
  21. * Creates a new tag with the provided information.
  22. *
  23. * @memberof TagAPI
  24. * @param {Tag} payload An object that contains information about a tag.
  25. * @returns {Promise} The created person.
  26. */
  27. async createTag(payload) {
  28. const url = this.baseUrl + "tags";
  29. const tag = await this.post(url, { dataJ: payload });
  30. return tag;
  31. }
  32. /**
  33. * Returns the tag with the provided name.
  34. *
  35. * @memberof TagAPI
  36. * @param {String} name The name of the tag.
  37. * @returns {Promise} The tag requested.
  38. */
  39. async getTag(name) {
  40. const url = this.baseUrl + `tags/${name}`;
  41. const tag = await this.get(url);
  42. return tag;
  43. }
  44. /**
  45. * Updates the tag with the provided information.
  46. *
  47. * @memberof TagAPI
  48. * @param {String} name The name of the tag.
  49. * @param {Object} payload An object that contains information about a tag.
  50. * @returns {Promise} The updated tag.
  51. */
  52. async updateTag(name, payload) {
  53. const url = this.baseUrl + `tags/${name}`;
  54. const tag = await this.put(url, { dataJ: payload });
  55. return tag;
  56. }
  57. /**
  58. * Deletes the tag with the provided name.
  59. *
  60. * @memberof TagAPI
  61. * @param {String} name The name of the tag.
  62. * @returns {Promise} Empty response.
  63. */
  64. async deleteTag(name) {
  65. const url = this.baseUrl + `tags/${name}`;
  66. const tag = await this.delete(url);
  67. return tag;
  68. }
  69. };
  70. export default TagAPI;