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,31 +49,57 @@ const RegistroComunicado = () => {
} }
const saveComunicado = () => { const saveComunicado = () => {
var data = { if (comunicado._id === null) {
post: document.getElementById('txt_comunicado').value, var data = {
user_id: cookies.id, post: document.getElementById('txt_comunicado').value,
community_id: cookies.community_id user_id: cookies.id,
}; community_id: cookies.community_id
};
fetch('http://localhost:4000/post/createPost', { fetch('http://localhost:4000/post/createPost', {
cache: 'no-cache', cache: 'no-cache',
method: 'POST', method: 'POST',
body: JSON.stringify(data), body: JSON.stringify(data),
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
}).then((response) => { }).then((response) => {
if (response.status != 201) if (response.status != 201)
console.log('Ocurrió un error con el servicio: ' + response.status); console.log('Ocurrió un error con el servicio: ' + response.status);
else else
return response.json(); return response.json();
}).then((_response) => { }).then((_response) => {
}).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">