actionAboutMe.jsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { actionPromise } from "./actionsPromise";
  2. import { gql } from "../helpers/gql";
  3. import { actionAddChats } from "./actionsForChats";
  4. export const actionFindUser = (_id) => (
  5. actionPromise('aboutMe', gql(`query findUserOne($q: String) {
  6. UserFindOne (query: $q){
  7. _id
  8. createdAt
  9. login
  10. nick
  11. avatar {
  12. _id
  13. url
  14. }
  15. chats {
  16. _id
  17. title
  18. createdAt
  19. lastModified
  20. owner{
  21. _id
  22. }
  23. lastMessage {
  24. text
  25. createdAt
  26. owner{
  27. _id
  28. nick
  29. }
  30. }
  31. avatar{
  32. _id
  33. url
  34. }
  35. members{
  36. _id
  37. nick
  38. avatar{
  39. url
  40. }
  41. }
  42. }
  43. }
  44. }`, {
  45. q: JSON.stringify([ {_id: _id} ])
  46. }
  47. ))
  48. )
  49. export const actionAboutMe = () =>
  50. async (dispatch, getState) => {
  51. const{auth} = getState();
  52. const id = auth?.payload?.sub?.id
  53. if(id){
  54. let user = await dispatch(actionFindUser(id))
  55. console.log(user)
  56. if (user){
  57. dispatch(actionAddChats([...user.chats]));
  58. }
  59. }
  60. }