actionChatGroup.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import { actionPromise } from "../../../store/store";
  2. // import history from '../../history';
  3. const getGQL = (url, headers = {}) => (query = "", variables = {}) =>
  4. fetch(url, {
  5. method: "POST",
  6. headers: {
  7. Accept: "application/json",
  8. "Content-Type": "application/json",
  9. ...headers,
  10. },
  11. body: JSON.stringify({ query, variables }),
  12. }).then((res) => res.json());
  13. const actionChatGroupUserPromise = (id) => {
  14. var promise = getGQL("http://localhost:3330/graphql")(
  15. `query allMessOneUser($id: ID!){
  16. getAllChatGroupsOneUser(id: $id){
  17. id, autorId{
  18. id, login
  19. }, partnerId {
  20. id, login
  21. }
  22. }
  23. }`,
  24. { id }
  25. );
  26. return actionPromise("chatGroupUser", promise);
  27. };
  28. const actionChatGroupUser = (id) => {
  29. return async (dispatch) => {
  30. var token = await dispatch(actionChatGroupUserPromise(id));
  31. // console.log(token);
  32. // if (token === undefined) await dispatch(actionLoginPromise1(login, password))
  33. // if(token) history.push("/my_profile")
  34. };
  35. };
  36. const actionChatGroupPromise = (id) => {
  37. var promise = getGQL("http://localhost:3330/graphql")(
  38. `query chatGroup($id: ID!) {
  39. getChatGroup(id: $id){
  40. id, autorId {
  41. id, login
  42. }, partnerId {
  43. id, login
  44. }
  45. }
  46. }`,
  47. { id }
  48. );
  49. return actionPromise("chatGroup", promise);
  50. };
  51. const actionChatGroup = (id) => {
  52. return async (dispatch) => {
  53. var token = await dispatch(actionChatGroupPromise(id));
  54. // console.log(token);
  55. // if (token === undefined) await dispatch(actionLoginPromise1(login, password))
  56. // if(token) history.push("/my_profile")
  57. };
  58. };
  59. const actionMessagePromise = () => {
  60. var promise = getGQL("http://localhost:3330/graphql")(
  61. `query allMessage{
  62. getAllMessages {
  63. id, message, autorId {
  64. id, login
  65. }, partnerId {
  66. id, login
  67. }
  68. }
  69. }`
  70. );
  71. return actionPromise("message", promise);
  72. };
  73. const actionMessage = () => {
  74. return async (dispatch) => {
  75. var token = await dispatch(actionMessagePromise());
  76. // console.log(token);
  77. };
  78. };
  79. const actionUsersPromise = (email) => {
  80. var promise = getGQL("http://localhost:3330/graphql")(
  81. `query find($email: String) {
  82. getUser(email: $email) {
  83. id, email, login
  84. }
  85. }`,
  86. { email }
  87. );
  88. return actionPromise("users", promise);
  89. };
  90. const actionUsers = (email) => {
  91. return async (dispatch) => {
  92. var token = await dispatch(actionUsersPromise(email));
  93. // console.log(token);
  94. };
  95. };
  96. const actionAllMessOneUserPromise = (id) => {
  97. var promise = getGQL("http://localhost:3330/graphql")(
  98. `query allMessOneUser($id: ID!){
  99. getAllMessagesOneUser(id:$id){
  100. id, message, autorId{
  101. id, login
  102. }, partnerId{
  103. id, login
  104. }
  105. }
  106. }`,
  107. { id }
  108. );
  109. return actionPromise("allMessOneUser", promise);
  110. };
  111. const actionAllMessOneUser = (id) => {
  112. return async (dispatch) => {
  113. var token = await dispatch(actionAllMessOneUserPromise(id));
  114. console.log(token);
  115. };
  116. };
  117. export {
  118. actionChatGroupUser,
  119. actionChatGroup,
  120. actionMessage,
  121. actionUsers,
  122. actionAllMessOneUser,
  123. };