actionChatGroup.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { actionPromise, store } 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 actionChatGroupPromise = (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("chatGroup", promise);
  27. };
  28. const actionChatGroup = (id) => {
  29. return async (dispatch) => {
  30. var token = await dispatch(actionChatGroupPromise(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 actionMessagePromise = () => {
  37. var promise = getGQL("http://localhost:3330/graphql")(
  38. `query allMessage{
  39. getAllMessages {
  40. id, message, autorId {
  41. id, login
  42. }, partnerId {
  43. id, login
  44. }
  45. }
  46. }`
  47. );
  48. return actionPromise("message", promise);
  49. };
  50. const actionMessage = () => {
  51. return async (dispatch) => {
  52. var token = await dispatch(actionMessagePromise());
  53. // console.log(token);
  54. };
  55. };
  56. const actionUsersPromise = (email) => {
  57. var promise = getGQL("http://localhost:3330/graphql")(
  58. `query find($email: String) {
  59. getUser(email: $email) {
  60. id, email, login
  61. }
  62. }`,
  63. { email }
  64. );
  65. return actionPromise("users", promise);
  66. };
  67. const actionUsers = (email) => {
  68. return async (dispatch) => {
  69. var token = await dispatch(actionUsersPromise(email));
  70. // console.log(token);
  71. };
  72. };
  73. const actionAllMessOneUserPromise = (id) => {
  74. var promise = getGQL("http://localhost:3330/graphql")(
  75. `query allMessOneUser($id: ID!){
  76. getAllMessagesOneUser(id:$id){
  77. id, message, autorId{
  78. id, login
  79. }, partnerId{
  80. id, login
  81. }
  82. }
  83. }`,
  84. { id }
  85. );
  86. return actionPromise("allMessOneUser", promise);
  87. };
  88. const actionAllMessOneUser = (id) => {
  89. return async (dispatch) => {
  90. var token = await dispatch(actionAllMessOneUserPromise(id));
  91. // console.log(token);
  92. };
  93. };
  94. export { actionChatGroup, actionMessage, actionUsers, actionAllMessOneUser };