{"ast":null,"code":"import axios from \"axios\";\n\n// posts\nexport const GET_POSTS = \"GET_POSTS\";\nexport const UPDATE_POST = \"UPDATE_POST\";\nexport const DELETE_POST = \"DELETE_POST\";\nexport const ADD_POST = \"ADD_POST\";\n//commentaire\nexport const ADD_COMMENT = \"ADD_COMMENT\";\nexport const EDIT_COMMENT = \"EDIT_COMMENT\";\nexport const DELETE_COMMENT = \"DELETE_COMMENT\";\n\n// errors\nexport const GET_POST_ERRORS = \"GET_POST_ERRORS\";\n\n//parametre num (number ) voir thred.js pour getposts\nexport const getPosts = num => {\n  return dispatch => {\n    return axios\n    // on recupère la base de donné post\n    .get(`http://localhost:5001/api/post/`).then(res => {\n      // la data des psots avec slice ! au niveau 0, a partir du premier element et me garde jusqu'ai num\n      const array = res.data.slice(0, num);\n      dispatch({\n        type: GET_POSTS,\n        payload: array\n      });\n    }).catch(err => console.log(err));\n  };\n};\nexport const addPost = data => {\n  return dispatch => {\n    return axios.post(`${process.env.REACT_APP_API_URL}api/post/`, data).then(res => {\n      if (res.data.errors) {\n        dispatch({\n          type: GET_POST_ERRORS,\n          payload: res.data.errors\n        });\n      } else {\n        dispatch({\n          type: GET_POST_ERRORS,\n          payload: \"\"\n        });\n      }\n    });\n  };\n};\nexport const upadatePost = (postId, message) => {\n  return dispatch => {\n    return axios({\n      method: 'put',\n      url: `http://localhost:5001/api/post/${postId}`,\n      data: {\n        message\n      }\n    }).then(res => {\n      dispatch({\n        type: UPDATE_POST,\n        payload: {\n          message,\n          postId\n        }\n      });\n    }).catch(err => console.log(err));\n  };\n};\nexport const deletepost = postId => {\n  return dispatch => {\n    return axios({\n      method: 'delete',\n      url: `http://localhost:5001/api/post/${postId}`\n    }).then(res => {\n      dispatch({\n        type: DELETE_POST,\n        payload: {\n          postId\n        }\n      });\n    }).catch(err => console.log(err));\n  };\n};\nexport const addComment = (postId, commenterId, text, commenterPseudo) => {\n  return dispatch => {\n    return axios({\n      method: \"patch\",\n      url: `http://localhost:5001/api/post/comment-post/${postId}`,\n      data: {\n        commenterId,\n        text,\n        commenterPseudo\n      }\n    }).then(res => {\n      dispatch({\n        type: ADD_COMMENT,\n        payload: {\n          postId\n        }\n      });\n    }).catch(err => console.log(err));\n  };\n};\nexport const editComment = (postId, commentId, text) => {\n  return dispatch => {\n    return axios({\n      method: \"patch\",\n      url: `http://localhost:5001/api/post/edit-comment-post/${postId}`,\n      data: {\n        commentId,\n        text\n      }\n    }).then(res => {\n      dispatch({\n        type: EDIT_COMMENT,\n        payload: {\n          postId,\n          commentId,\n          text\n        }\n      });\n    }).catch(err => console.log(err));\n  };\n};\nexport const deleteComment = (postId, commentId) => {\n  return dispatch => {\n    return axios({\n      method: \"patch\",\n      url: `http://localhost:5001/api/post/delete-comment-post/${postId}`,\n      data: {\n        commentId\n      }\n    }).then(res => {\n      dispatch({\n        type: DELETE_COMMENT,\n        payload: {\n          postId,\n          commentId\n        }\n      });\n    }).catch(err => console.log(err));\n  };\n};","map":{"version":3,"names":["axios","GET_POSTS","UPDATE_POST","DELETE_POST","ADD_POST","ADD_COMMENT","EDIT_COMMENT","DELETE_COMMENT","GET_POST_ERRORS","getPosts","num","dispatch","get","then","res","array","data","slice","type","payload","catch","err","console","log","addPost","post","process","env","REACT_APP_API_URL","errors","upadatePost","postId","message","method","url","deletepost","addComment","commenterId","text","commenterPseudo","editComment","commentId","deleteComment"],"sources":["C:/Users/user/Desktop/05mediaSocial/client/src/actions/post.actions.js"],"sourcesContent":["import axios from \"axios\";\r\n\r\n// posts\r\nexport const GET_POSTS=\"GET_POSTS\";\r\nexport const UPDATE_POST=\"UPDATE_POST\";\r\nexport const DELETE_POST=\"DELETE_POST\";\r\nexport const ADD_POST = \"ADD_POST\";\r\n//commentaire\r\nexport const ADD_COMMENT=\"ADD_COMMENT\"\r\nexport const EDIT_COMMENT = \"EDIT_COMMENT\";\r\nexport const DELETE_COMMENT = \"DELETE_COMMENT\";\r\n\r\n// errors\r\nexport const GET_POST_ERRORS = \"GET_POST_ERRORS\";\r\n\r\n//parametre num (number ) voir thred.js pour getposts\r\nexport const getPosts=(num)=>{\r\n    return (dispatch)=>{\r\n        return axios\r\n        // on recupère la base de donné post\r\n        .get(`http://localhost:5001/api/post/`)\r\n        .then((res)=>{\r\n            // la data des psots avec slice ! au niveau 0, a partir du premier element et me garde jusqu'ai num\r\n            const array=res.data.slice(0, num);\r\n            dispatch({type:GET_POSTS, payload: array})\r\n        })\r\n        .catch((err)=>console.log(err))\r\n    }\r\n\r\n}\r\n\r\nexport const addPost = (data) => {\r\n    return (dispatch) => {\r\n      return axios\r\n        .post(`${process.env.REACT_APP_API_URL}api/post/`, data)\r\n        .then((res) => {\r\n          if (res.data.errors) {\r\n            dispatch({ type: GET_POST_ERRORS, payload: res.data.errors });\r\n          } else {\r\n            dispatch({ type: GET_POST_ERRORS, payload: \"\" });\r\n          }\r\n        });\r\n    };\r\n  };\r\n\r\n\r\n\r\n\r\nexport const upadatePost=(postId,message)=>{\r\n    return(dispatch)=>{\r\n        return axios({\r\n            method:'put',\r\n            url:`http://localhost:5001/api/post/${postId}`,\r\n            data: {message}\r\n\r\n        })\r\n        .then((res)=>{\r\n            dispatch({type:UPDATE_POST,payload: {message,postId}});\r\n        })\r\n        .catch((err)=>console.log(err));\r\n    };\r\n}\r\n\r\nexport const deletepost=(postId)=>{\r\n    return(dispatch)=>{\r\n        return axios({\r\n            method:'delete',\r\n            url:`http://localhost:5001/api/post/${postId}`,\r\n         \r\n\r\n        })\r\n        .then((res)=>{\r\n            dispatch({type:DELETE_POST,payload: {postId}});\r\n        })\r\n        .catch((err)=>console.log(err));\r\n    };\r\n\r\n}\r\n\r\nexport const addComment = (postId, commenterId, text, commenterPseudo) => {\r\n    return (dispatch) => {\r\n      return axios({\r\n        method: \"patch\",\r\n        url: `http://localhost:5001/api/post/comment-post/${postId}`,\r\n        data: { commenterId, text, commenterPseudo },\r\n      })\r\n        .then((res) => {\r\n          dispatch({ type: ADD_COMMENT, payload: { postId } });\r\n        })\r\n        .catch((err) => console.log(err));\r\n    };\r\n  };\r\n  \r\n  export const editComment = (postId, commentId, text) => {\r\n    return (dispatch) => {\r\n      return axios({\r\n        method: \"patch\",\r\n        url:`http://localhost:5001/api/post/edit-comment-post/${postId}`,\r\n        data: { commentId, text },\r\n      })\r\n        .then((res) => {\r\n          dispatch({ type: EDIT_COMMENT, payload: { postId, commentId, text } });\r\n        })\r\n        .catch((err) => console.log(err));\r\n    };\r\n  };\r\n  \r\n  export const deleteComment = (postId, commentId) => {\r\n    return (dispatch) => {\r\n      return axios({\r\n        method: \"patch\",\r\n        url: `http://localhost:5001/api/post/delete-comment-post/${postId}`,\r\n        data: { commentId },\r\n      })\r\n        .then((res) => {\r\n          dispatch({ type: DELETE_COMMENT, payload: { postId, commentId } });\r\n        })\r\n        .catch((err) => console.log(err));\r\n    };\r\n  };\r\n\r\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;;AAEzB;AACA,OAAO,MAAMC,SAAS,GAAC,WAAW;AAClC,OAAO,MAAMC,WAAW,GAAC,aAAa;AACtC,OAAO,MAAMC,WAAW,GAAC,aAAa;AACtC,OAAO,MAAMC,QAAQ,GAAG,UAAU;AAClC;AACA,OAAO,MAAMC,WAAW,GAAC,aAAa;AACtC,OAAO,MAAMC,YAAY,GAAG,cAAc;AAC1C,OAAO,MAAMC,cAAc,GAAG,gBAAgB;;AAE9C;AACA,OAAO,MAAMC,eAAe,GAAG,iBAAiB;;AAEhD;AACA,OAAO,MAAMC,QAAQ,GAAEC,GAAG,IAAG;EACzB,OAAQC,QAAQ,IAAG;IACf,OAAOX;IACP;IAAA,CACCY,GAAG,CAAE,iCAAgC,CAAC,CACtCC,IAAI,CAAEC,GAAG,IAAG;MACT;MACA,MAAMC,KAAK,GAACD,GAAG,CAACE,IAAI,CAACC,KAAK,CAAC,CAAC,EAAEP,GAAG,CAAC;MAClCC,QAAQ,CAAC;QAACO,IAAI,EAACjB,SAAS;QAAEkB,OAAO,EAAEJ;MAAK,CAAC,CAAC;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