import actionPromise from "./action-promise";
import { gql } from '../../graphQl/getGQL'
import jwtDecode from '../../helpers/jwt-decode'


export const actionAboutMe = () => {
    let _id = jwtDecode(localStorage.authToken).sub.id
    return (
        actionPromise('userData', gql(`
            query($userId: String!) {
                UserFindOne(query: $userId){
                    login, _id, avatar {_id, url, originalFileName}, chats{
                        members {
                            _id
                            createdAt
                            login
                            nick
                          }
                        messages {
                            _id
                            createdAt
                            text
                                    owner {
                                      _id
                                      createdAt
                                      login
                                      nick
                                    }
                            media {
                              _id
                              createdAt
                              text
                              url
                              originalFileName
                              type
                            }
                          }
                        _id
                        createdAt
                        title
                        lastMessage {
                            _id
                            createdAt
                            text
                        }
                    }
                }
            }
        `, { userId: JSON.stringify([{ _id }]) }))
    )
}

