add function to update post

This commit is contained in:
Eduardo Quiros 2022-08-30 05:37:53 -06:00
parent de607882a1
commit 0ed28237aa
No known key found for this signature in database
GPG Key ID: B77F36C3F12720B4
1 changed files with 48 additions and 22 deletions

View File

@ -49,6 +49,7 @@ const RegistroComunicado = () => {
} }
const saveComunicado = () => { const saveComunicado = () => {
if (comunicado._id === null) {
var data = { var data = {
post: document.getElementById('txt_comunicado').value, post: document.getElementById('txt_comunicado').value,
user_id: cookies.id, user_id: cookies.id,
@ -72,8 +73,33 @@ const RegistroComunicado = () => {
}).catch( }).catch(
err => console.log('Ocurrió un error con el fetch', err) err => console.log('Ocurrió un error con el fetch', err)
); );
} } else {
let data = {
_id: comunicado._id,
post: document.getElementById('txt_comunicado').value,
user_id: cookies.id,
community_id: cookies.community_id
};
fetch(`http://localhost:4000/post/updatePost/${comunicado._id}`, {
cache: 'no-cache',
method: 'PUT',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
}).then((response) => {
if (response.status != 201)
console.log('Ocurrió un error con el servicio: ' + response.status);
else
return response.json();
}).then((_response) => {
}).catch(
err => console.log('Ocurrió un error con el fetch', err)
);
}
}
const header = ( const header = (
<React.Fragment> <React.Fragment>
<div className="flex flex-column md:flex-row md:justify-content-between md:align-items-center"> <div className="flex flex-column md:flex-row md:justify-content-between md:align-items-center">