action.async.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { FETCH_CONFIG } from './helper.js'
  2. export const getThreadContent = (user, apiUrl, idWorkspace, idContent) =>
  3. fetch(`${apiUrl}/workspaces/${idWorkspace}/threads/${idContent}`, {
  4. headers: {
  5. ...FETCH_CONFIG.headers,
  6. 'Authorization': 'Basic ' + user.auth
  7. },
  8. method: 'GET'
  9. })
  10. export const getThreadComment = (user, apiUrl, idWorkspace, idContent) =>
  11. fetch(`${apiUrl}/workspaces/${idWorkspace}/contents/${idContent}/comments`, {
  12. headers: {
  13. ...FETCH_CONFIG.headers,
  14. 'Authorization': 'Basic ' + user.auth
  15. },
  16. method: 'GET'
  17. })
  18. export const postThreadNewComment = (user, apiUrl, idWorkspace, idContent, newComment) =>
  19. fetch(`${apiUrl}/workspaces/${idWorkspace}/contents/${idContent}/comments`, {
  20. headers: {
  21. ...FETCH_CONFIG.headers,
  22. 'Authorization': 'Basic ' + user.auth
  23. },
  24. method: 'POST',
  25. body: JSON.stringify({
  26. raw_content: newComment
  27. })
  28. })
  29. export const putThreadStatus = (user, apiUrl, idWorkspace, idContent, newStatus) =>
  30. fetch(`${apiUrl}/workspaces/${idWorkspace}/threads/${idContent}/status`, {
  31. headers: {
  32. ...FETCH_CONFIG.headers,
  33. 'Authorization': 'Basic ' + user.auth
  34. },
  35. method: 'PUT',
  36. body: JSON.stringify({
  37. status: newStatus
  38. })
  39. })
  40. export const postThreadContent = (user, apiUrl, idWorkspace, idFolder, contentType, newContentName) =>
  41. fetch(`${apiUrl}/workspaces/${idWorkspace}/contents`, {
  42. headers: {
  43. ...FETCH_CONFIG.headers,
  44. 'Authorization': 'Basic ' + user.auth
  45. },
  46. method: 'POST',
  47. body: JSON.stringify({
  48. parent_id: idFolder,
  49. content_type: contentType,
  50. label: newContentName
  51. })
  52. })
  53. export const putThreadContent = (user, apiUrl, idWorkspace, idContent, label) =>
  54. fetch(`${apiUrl}/workspaces/${idWorkspace}/threads/${idContent}`, {
  55. headers: {
  56. ...FETCH_CONFIG.headers,
  57. 'Authorization': 'Basic ' + user.auth
  58. },
  59. method: 'PUT',
  60. body: JSON.stringify({
  61. label: label,
  62. raw_content: '' // threads have no content
  63. })
  64. })
  65. export const putThreadIsArchived = (user, apiUrl, idWorkspace, idContent) => {
  66. return fetch(`${apiUrl}/workspaces/${idWorkspace}/contents/${idContent}/archive`, {
  67. headers: {
  68. 'Authorization': 'Basic ' + user.auth,
  69. ...FETCH_CONFIG.headers
  70. },
  71. method: 'PUT'
  72. })
  73. }
  74. export const putThreadIsDeleted = (user, apiUrl, idWorkspace, idContent) => {
  75. return fetch(`${apiUrl}/workspaces/${idWorkspace}/contents/${idContent}/delete`, {
  76. headers: {
  77. 'Authorization': 'Basic ' + user.auth,
  78. ...FETCH_CONFIG.headers
  79. },
  80. method: 'PUT'
  81. })
  82. }
  83. export const putThreadRestoreArchived = (user, apiUrl, idWorkspace, idContent) => {
  84. return fetch(`${apiUrl}/workspaces/${idWorkspace}/contents/${idContent}/unarchive`, {
  85. headers: {
  86. 'Authorization': 'Basic ' + user.auth,
  87. ...FETCH_CONFIG.headers
  88. },
  89. method: 'PUT'
  90. })
  91. }
  92. export const putThreadRestoreDeleted = (user, apiUrl, idWorkspace, idContent) => {
  93. return fetch(`${apiUrl}/workspaces/${idWorkspace}/contents/${idContent}/undelete`, {
  94. headers: {
  95. 'Authorization': 'Basic ' + user.auth,
  96. ...FETCH_CONFIG.headers
  97. },
  98. method: 'PUT'
  99. })
  100. }
  101. export const putThreadRead = (user, apiUrl, idWorkspace, idContent) => {
  102. return fetch(`${apiUrl}/users/${user.user_id}/workspaces/${idWorkspace}/contents/${idContent}/read`, {
  103. headers: {
  104. 'Authorization': 'Basic ' + user.auth,
  105. ...FETCH_CONFIG.headers
  106. },
  107. method: 'PUT'
  108. })
  109. }