commentQuery.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import { gql } from "../../helpers/getGQL";
  2. import { actionPromise } from "../types/promiseTypes";
  3. export const actionAddComment = (postId, text) =>
  4. actionPromise(
  5. "addComment",
  6. gql(
  7. `mutation AddComment($comment:CommentInput){
  8. CommentUpsert(comment:$comment)
  9. {
  10. _id
  11. text
  12. createdAt
  13. }
  14. }`,
  15. {
  16. comment: {
  17. post: {
  18. _id: postId,
  19. },
  20. text
  21. },
  22. },
  23. ),
  24. )
  25. export const actionOnePost = (_id) =>
  26. actionPromise(
  27. 'onePost',
  28. gql(
  29. `query OneFind($post:String){
  30. PostFindOne(query:$post){
  31. _id createdAt title text
  32. images{_id url originalFileName}
  33. comments {
  34. _id createdAt text
  35. likes { _id owner {_id login nick avatar {_id url} }}
  36. owner {_id login nick
  37. avatar {_id url}
  38. }
  39. answers{
  40. _id
  41. }
  42. answerTo{_id}
  43. }
  44. likes{
  45. _id
  46. owner{
  47. _id login avatar {_id url}
  48. }
  49. }
  50. owner {_id login nick
  51. avatar {_id url}
  52. }
  53. }
  54. }
  55. `,
  56. {
  57. post: JSON.stringify([{ _id }]),
  58. },
  59. ),
  60. )
  61. export const actionGetCommentsOnePost = (postId) =>
  62. actionPromise('commentsOnePost',
  63. gql(`query commentFindPost ($id:String!){
  64. PostFindOne(query:$id){
  65. comments {
  66. _id text createdAt
  67. owner{
  68. _id nick login
  69. avatar{
  70. _id url
  71. }
  72. }
  73. likes{_id}
  74. }
  75. }
  76. }`, { id: JSON.stringify([{ _id: postId }]) }))
  77. export const actionFindSubComment = (findId) =>
  78. actionPromise(
  79. 'subComments',
  80. gql(
  81. `query commentFindOne ($id:String!){
  82. CommentFindOne(query:$id){
  83. _id text answers {
  84. _id text
  85. post {_id }
  86. answers { _id}
  87. createdAt
  88. likes { _id owner
  89. {_id avatar{_id url} login nick } }
  90. owner {
  91. _id login nick
  92. avatar { _id url }
  93. }
  94. }
  95. }
  96. }`,
  97. {
  98. id: JSON.stringify([
  99. {
  100. _id: findId,
  101. },
  102. ]),
  103. },
  104. ),
  105. )
  106. export const actionAddSubComment = (commentId, newResult) =>
  107. actionPromise(
  108. 'addSubComment',
  109. gql(
  110. `mutation AddComment($comment:CommentInput){
  111. CommentUpsert(comment:$comment)
  112. {
  113. _id
  114. text
  115. createdAt
  116. }
  117. }`,
  118. {
  119. comment: {
  120. answerTo: {
  121. _id: commentId,
  122. },
  123. text: newResult,
  124. },
  125. },
  126. ),
  127. )