{"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\";\nexport const GET_ALL_POSTS = \"GET_ALL_POSTS\";\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      dispatch({\n        type: GET_ALL_POSTS,\n        payload: res.data\n      });\n    }).catch(err => console.log(err));\n  };\n};\nexport const addPost = data => {\n  return dispatch => {\n    return axios.post(`http://localhost:5001/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","GET_ALL_POSTS","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","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\nexport const GET_ALL_POSTS = \"GET_ALL_POSTS\";\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            dispatch({ type: GET_ALL_POSTS, payload: res.data });\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(`http://localhost:5001/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,OAAO,MAAMC,aAAa,GAAG,eAAe;AAC5C;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,OAAOZ;IACP;IAAA,CACCa,GAAG,CAAE,iCAAgC,CAAC,CACtCC,IAAI,CAAEC,GAAG,IAA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