Merge pull request #191 from DeimosPr4/69-us-37-eliminar-comunicado-de-administrador-de-comunidad

69 us 37 eliminar comunicado de administrador de comunidad
This commit is contained in:
Eduardo Quiros 2022-08-23 06:15:20 +00:00 committed by GitHub
commit aacb019a58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 196 additions and 132 deletions

View File

@ -489,6 +489,11 @@ export class AppController {
return this.appService.findPost(paramPost); return this.appService.findPost(paramPost);
} }
@Delete('post/deletePost/:id')
deletePost(@Param('id') id: string) {
return this.appService.deletePost(id);
}
// #==== API Comment // #==== API Comment
@Post('post/createComment') @Post('post/createComment')

View File

@ -618,6 +618,15 @@ export class AppService {
.pipe(map((message: string) => ({ message }))); .pipe(map((message: string) => ({ message })));
} }
//DELETE
deletePost(paramPostId: string) {
const pattern = { cmd: 'removePost' };
const payload = { id: paramPostId };
return this.clientPostApp
.send<string>(pattern, payload)
.pipe(map((message: string) => ({ message })));
}
// ====================== COMMNENT POSTS =============================== // ====================== COMMNENT POSTS ===============================
//Comment parameter from API //Comment parameter from API

View File

@ -11,13 +11,9 @@ import { Toolbar } from 'primereact/toolbar';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faHome, faUserAlt } from '@fortawesome/free-solid-svg-icons'; import { faHome, faUserAlt } from '@fortawesome/free-solid-svg-icons';
import { faCommentAlt } from '@fortawesome/free-solid-svg-icons'; import { faCommentAlt } from '@fortawesome/free-solid-svg-icons';
import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons';
import { faAt } from '@fortawesome/free-solid-svg-icons';
import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons';
import { faEllipsis } from '@fortawesome/free-solid-svg-icons'; import { faEllipsis } from '@fortawesome/free-solid-svg-icons';
import { faHomeAlt } from '@fortawesome/free-solid-svg-icons';
import { Dropdown } from 'primereact/dropdown';
import classNames from 'classnames'; import classNames from 'classnames';
const RegistroComunicado = () => { const RegistroComunicado = () => {
let emptyComunicado = { let emptyComunicado = {
@ -27,14 +23,14 @@ const RegistroComunicado = () => {
community_id: '' community_id: ''
}; };
useEffect(()=>{ useEffect(() => {
listaComunis(); listaComunis();
},[]) }, [])
const [comunicado, setComunicado] = useState(emptyComunicado); const [comunicado, setComunicado] = useState(emptyComunicado);
const [comunicados,setComuicados]=useState([]); const [comunicados, setComunicados] = useState([]);
const [comunicadoId, setComunicadoId] = useState(null); const [comunicadoId, setComunicadoId] = useState(null);
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
const [submitted, setSubmitted] = useState(false); const [submitted, setSubmitted] = useState(false);
const toast = useRef(null); const toast = useRef(null);
const dt = useRef(null); const dt = useRef(null);
@ -42,13 +38,15 @@ const RegistroComunicado = () => {
const [globalFilter, setGlobalFilter] = useState(null); const [globalFilter, setGlobalFilter] = useState(null);
async function listaComunis() { async function listaComunis() {
let comunicadosA=await fetch('http://localhost:4000/post/allPosts', {method:'GET'}); let comunicadosResponse = await fetch('http://localhost:4000/post/allPosts', { method: 'GET' });
let comunicadosRes= await comunicadosA.json(); const comunicadosJson = await comunicadosResponse.json();
setComuicados(comunicadosRes.message); const comunicadosCommunity = comunicadosJson.message.filter((comunicado) => {
console.log(comunicadosRes.message); return comunicado.community_id === cookies.community_id;
})
setComunicados(comunicadosCommunity);
console.log(comunicadosCommunity);
} }
const saveComunicado = () => { const saveComunicado = () => {
var data = { var data = {
post: document.getElementById('txt_comunicado').value, post: document.getElementById('txt_comunicado').value,
@ -63,28 +61,20 @@ const RegistroComunicado = () => {
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
}) }).then((response) => {
.then(
function (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(
function (response) {
} }).catch(
)
.catch(
err => console.log('Ocurrió un error con el fetch', err) 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">
<h5 className="m-0">Comunicados de la comunidad</h5> <h5 className="m-0">Comunicados de la comunidad</h5>
<span className="block mt-2 md:mt-0 p-input-icon-left"> <span className="block mt-2 md:mt-0 p-input-icon-left">
@ -111,21 +101,75 @@ const RegistroComunicado = () => {
</div> </div>
</React.Fragment> </React.Fragment>
) )
} }
const rightToolbarTemplate = () => { const rightToolbarTemplate = () => {
return ( return (
<React.Fragment> <React.Fragment>
<Button label="Exportar" icon="pi pi-upload" className="p-button-help" /> <Button label="Exportar" icon="pi pi-upload" className="p-button-help" />
</React.Fragment> </React.Fragment>
) )
} }
const actions = (rowData) => {
return (
<div className="actions">
<Button
icon='pi pi-trash'
className='p-button-rounded p-button-danger mt-2 mx-2'
onClick={() => confirmDelete(rowData)}
title='Eliminar Inquilino'
/>
</div>
)
}
const confirmDelete = (post) => {
setComunicado(post);
setShowDeleteDialog(true);
}
const deleteDialogFooter = (
<>
<Button label="Cancelar" icon="pi pi-times" className="p-button-secondary" onClick={() => setShowDeleteDialog(false)} />
<Button label="Eliminar" icon="pi pi-check" className="p-button-danger" onClick={() => deleteComunicado()} />
</>
);
const deleteComunicado = () => {
fetch(`http://localhost:4000/post/deletePost/${comunicado._id}`, {
cache: 'no-cache',
method: 'DELETE',
headers: { 'Content-Type': 'application/json' }
}).then((response) => {
if (response.status != 200)
console.log('Ocurrió un error con el servicio: ' + response.status);
else
return response.json();
}).then((_response) => {
setShowDeleteDialog(false);
listaComunis();
setComunicado(emptyComunicado);
}).catch(err => console.log('Ocurrió un error con el fetch', err));
}
return ( return (
<div className="grid"> <div className="grid">
<div className="col-12"> <div className="col-12">
<Toast ref={toast} /> <Toast ref={toast} />
<div className="card"> <div className="card">
<Dialog
header="Eliminar comunicado"
visible={showDeleteDialog}
style={{ width: '450px' }}
modal={true} onHide={() => setShowDeleteDialog(false)}
footer={deleteDialogFooter}
>
<div className="flex align-items-center justify-content-center">
<i className="pi pi-exclamation-triangle mr-3" style={{ fontSize: '2rem' }} />
{comunicado && <span>¿Estás seguro que desea eliminar el aviso "<b>{comunicado.post}</b>"?</span>}
</div>
</Dialog>
<Toolbar className="mb-4" left={leftToolbarTemplate} right={rightToolbarTemplate}></Toolbar> <Toolbar className="mb-4" left={leftToolbarTemplate} right={rightToolbarTemplate}></Toolbar>
<DataTable ref={dt} value={comunicados} dataKey="_id" paginator rows={5} <DataTable ref={dt} value={comunicados} dataKey="_id" paginator rows={5}
scrollable scrollHeight="400px" scrollDirection="both" header={header} scrollable scrollHeight="400px" scrollDirection="both" header={header}
@ -135,7 +179,13 @@ const rightToolbarTemplate = () => {
globalFilter={globalFilter} emptyMessage="No hay administradores de comunidades registrados."> globalFilter={globalFilter} emptyMessage="No hay administradores de comunidades registrados.">
<Column selectionMode="multiple" headerStyle={{ width: '3rem' }}></Column> <Column selectionMode="multiple" headerStyle={{ width: '3rem' }}></Column>
<Column field="post" sortable header={headerPost} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column> <Column field="post" sortable header={headerPost} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column>
<Column
style={{
flexGrow: 1,
flexBasis: '80px',
minWidth: '80px'
}}
body={actions} />
</DataTable> </DataTable>
</div> </div>
</div> </div>
@ -150,7 +200,7 @@ const rightToolbarTemplate = () => {
<span className="p-inputgroup-addon p-button p-icon-input-khaki"> <span className="p-inputgroup-addon p-button p-icon-input-khaki">
<i className="pi pi-pencil"></i> <i className="pi pi-pencil"></i>
</span> </span>
<InputTextarea id="txt_comunicado" rows="4"/> <InputTextarea id="txt_comunicado" rows="4" />
</div> </div>
</div> </div>
</div> </div>