|
@@ -1,3 +1,4 @@
|
|
|
+import store from "../reducers"
|
|
|
const getGQL = url =>
|
|
|
(query, variables={}) => fetch(url, {
|
|
|
method: 'POST',
|
|
@@ -59,6 +60,7 @@ export const actionAuthLogin = token => ({type:'LOGIN', token})
|
|
|
export const actionAuthLogout = () => ({type:'LOGOUT'})
|
|
|
export const actionFullLogin = (login , password) => async dispatch => {
|
|
|
let result = await dispatch(actionPromise("login",log(login,password)))
|
|
|
+ console.log(result)
|
|
|
if (result?.data?.login !== null){
|
|
|
dispatch(actionAuthLogin(result.data.login))
|
|
|
}
|
|
@@ -74,7 +76,8 @@ export const actionRegister = (login,password) => async dispatch => {
|
|
|
|
|
|
export const actionFullRegister = (login,password) => async dispatch => {
|
|
|
let result = await dispatch (actionRegister(login,password))
|
|
|
- if (result?.errors === undefined) {
|
|
|
+
|
|
|
+ if (result?.data?.createUser !== null) {
|
|
|
await dispatch (actionFullLogin(login,password))
|
|
|
}
|
|
|
else {
|
|
@@ -83,3 +86,72 @@ export const actionFullRegister = (login,password) => async dispatch => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+export const imgFind = async() => {
|
|
|
+ return await gql(`query fhbg{
|
|
|
+ ImageFind(query:"[{}]"){
|
|
|
+ url owner{
|
|
|
+ nick
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }`)
|
|
|
+}
|
|
|
+
|
|
|
+const userFind = async(id) => {
|
|
|
+ let query = `query userOne {
|
|
|
+ UserFindOne(query:"[{\"_id\":\"6151892f68554b3e33cd8134\"}]"){
|
|
|
+ _id avatar{
|
|
|
+ url
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }`
|
|
|
+
|
|
|
+ let qVariables = {id}
|
|
|
+
|
|
|
+ let res = await gql(query,qVariables)
|
|
|
+ console.log(res)
|
|
|
+ return res
|
|
|
+}
|
|
|
+
|
|
|
+let ava = async (idUser , id) => {
|
|
|
+ let query = `mutation setAvatar{
|
|
|
+ UserUpsert(user:{_id: "6151892f68554b3e33cd8134", avatar: {_id: "61518b0b68554b3e33cd813c"}}){
|
|
|
+ _id, avatar{
|
|
|
+ _id
|
|
|
+ }
|
|
|
+ }
|
|
|
+}`
|
|
|
+let qVariables = {idUser , id}
|
|
|
+
|
|
|
+let res = await gql(query, qVariables)
|
|
|
+return res
|
|
|
+}
|
|
|
+
|
|
|
+export const actionImgFind = () => async dispatch => {
|
|
|
+ return await dispatch(actionPromise('img'),imgFind())
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+export const actionFindUser = () => async dispatch => {
|
|
|
+ return await dispatch (actionPromise('findUser'), userFind(store.getState().auth.payload.sub.id) )
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+export const actionSetAvatar = (idUser , id) => async dispatch => {
|
|
|
+ return await dispatch (actionPromise('setAvatar') , ava(idUser , id))
|
|
|
+}
|
|
|
+
|
|
|
+export const actionUploadFile = (files) => async dispatch => {
|
|
|
+ let fd = new FormData()
|
|
|
+ fd.append('photo' , files)
|
|
|
+ return await dispatch (actionPromise('upload', fetch('/upload', {
|
|
|
+ method: "POST",
|
|
|
+ headers: localStorage.authToken ? {Authorization: 'Bearer ' + localStorage.authToken} : {},
|
|
|
+ body: fd
|
|
|
+}).then(res => res.json())))
|
|
|
+}
|
|
|
+
|
|
|
+export const actionFullAvatar = (idUser , id) => async dispatch => {
|
|
|
+ let result = await dispatch (actionUploadFile())
|
|
|
+ await dispatch (actionSetAvatar(idUser,id))
|
|
|
+}
|
|
|
+
|