Merge pull request #144 from DeimosPr4/US-28-EliminarÁreaComún
Eliminar Área Común
This commit is contained in:
commit
721c9f6fa7
|
@ -196,6 +196,12 @@ export class AppController {
|
||||||
return this.appService.findByCommunity(paramCommunityId);
|
return this.appService.findByCommunity(paramCommunityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Delete('commonArea/deleteCommonArea/:id')
|
||||||
|
deleteCommonArea(@Param('id') id: string) {
|
||||||
|
return this.appService.deleteCommonArea(id);
|
||||||
|
}
|
||||||
|
|
||||||
// #==== API GUEST
|
// #==== API GUEST
|
||||||
//#API userService - create user
|
//#API userService - create user
|
||||||
@Post('guest/createGuest')
|
@Post('guest/createGuest')
|
||||||
|
|
|
@ -258,6 +258,16 @@ export class AppService {
|
||||||
.pipe(map((message: string) => ({ message })));
|
.pipe(map((message: string) => ({ message })));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//DELETE parameter from API
|
||||||
|
deleteCommonArea(paramCommonAreaId: string) {
|
||||||
|
const pattern = { cmd: 'removeCommonArea' };
|
||||||
|
const payload = { id: paramCommonAreaId };
|
||||||
|
return this.clientCommonAreaApp
|
||||||
|
.send<string>(pattern, payload)
|
||||||
|
.pipe(map((message: string) => ({ message })));
|
||||||
|
}
|
||||||
|
|
||||||
// ====================== GUESTS ===============================
|
// ====================== GUESTS ===============================
|
||||||
|
|
||||||
//POST parameter from API
|
//POST parameter from API
|
||||||
|
|
|
@ -30,7 +30,7 @@ export class CommonAreasController {
|
||||||
|
|
||||||
@MessagePattern({ cmd: 'removeCommonArea' })
|
@MessagePattern({ cmd: 'removeCommonArea' })
|
||||||
remove(@Payload() id: string) {
|
remove(@Payload() id: string) {
|
||||||
let _id = id['_id'];
|
let _id = id['id'];
|
||||||
return this.commonAreasService.remove(_id);
|
return this.commonAreasService.remove(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ export class CommonAreasService {
|
||||||
return this.commonAreaModel.findOneAndUpdate({ _id: id }, {status: '-1'}, {
|
return this.commonAreaModel.findOneAndUpdate({ _id: id }, {status: '-1'}, {
|
||||||
new: true,
|
new: true,
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
async findByCommunity(community_id: string): Promise<CommonArea[]> {
|
async findByCommunity(community_id: string): Promise<CommonArea[]> {
|
||||||
return this.commonAreaModel.find({ community_id: community_id }).exec();
|
return this.commonAreaModel.find({ community_id: community_id }).exec();
|
||||||
|
|
|
@ -19,6 +19,9 @@ export class CommonArea {
|
||||||
@Prop()
|
@Prop()
|
||||||
bookable: number; //saber si es necesario reservarlo o no
|
bookable: number; //saber si es necesario reservarlo o no
|
||||||
|
|
||||||
|
@Prop()
|
||||||
|
status: string;
|
||||||
|
|
||||||
@Prop()
|
@Prop()
|
||||||
community_id: string;
|
community_id: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,11 +9,10 @@ import { Dialog } from 'primereact/dialog';
|
||||||
import { Toolbar } from 'primereact/toolbar';
|
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 { faPhoneAlt } from '@fortawesome/free-solid-svg-icons';
|
import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons';
|
||||||
import { faAt } from '@fortawesome/free-solid-svg-icons';
|
import { faAt } from '@fortawesome/free-solid-svg-icons';
|
||||||
import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons';
|
import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons';
|
||||||
import { faEllipsis } from '@fortawesome/free-solid-svg-icons';
|
import { faClipboardCheck } from '@fortawesome/free-solid-svg-icons';
|
||||||
import { faHomeAlt } from '@fortawesome/free-solid-svg-icons';
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { useCookies } from "react-cookie";
|
import { useCookies } from "react-cookie";
|
||||||
|
|
||||||
|
@ -29,6 +28,8 @@ const AreasComunes = () => {
|
||||||
community_id: '',
|
community_id: '',
|
||||||
bookable: '1',
|
bookable: '1',
|
||||||
bookable_text: '',
|
bookable_text: '',
|
||||||
|
status: '1',
|
||||||
|
status_text: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
const [commonAreaList, setCommonAreaList] = useState([]);
|
const [commonAreaList, setCommonAreaList] = useState([]);
|
||||||
|
@ -48,15 +49,27 @@ const AreasComunes = () => {
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then(data => data.message)
|
.then(data => data.message)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if(data) {
|
if (data) {
|
||||||
data.map(item => {
|
data.map(item => {
|
||||||
if(item.bookable == '1') {
|
if (item.bookable == '1') {
|
||||||
item.bookable_text = 'Disponible';
|
item.bookable_text = 'Necesaria';
|
||||||
} else{
|
} else {
|
||||||
item.bookable_text = 'Cerrado';
|
item.bookable_text = 'No es necesarioa';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.status == '1') {
|
||||||
|
item.status_text = 'Activo';
|
||||||
|
} else if (item.status == '0') {
|
||||||
|
item.status_text = 'Inactivo';
|
||||||
|
} else {
|
||||||
|
item.status_text = 'Eliminado';
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data = data.filter(
|
||||||
|
(val) => val.status != -1,
|
||||||
|
)
|
||||||
setCommonAreaList(data);
|
setCommonAreaList(data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -67,65 +80,66 @@ const AreasComunes = () => {
|
||||||
|
|
||||||
|
|
||||||
const deleteCommonArea = () => {
|
const deleteCommonArea = () => {
|
||||||
/* fetch('http://localhost:4000/community/deleteCommunity/' + community._id, {
|
fetch('http://localhost:4000/commonArea/deleteCommonArea/' + commonArea._id, {
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
function (response) {
|
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(
|
.then(
|
||||||
function (response) {
|
function (response) {
|
||||||
|
|
||||||
let _community = communities.filter(val => val._id !== community._id);
|
let _common_areas = commonAreaList.filter(
|
||||||
setCommunities(_community);
|
(val) => val._id !== commonArea._id,
|
||||||
setDeleteCommunityDialog(false);
|
);
|
||||||
setCommunity(emptyCommunity);
|
_common_areas = _common_areas.filter(
|
||||||
toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 });
|
(val) => val.status != -1,
|
||||||
}
|
)
|
||||||
)
|
setCommonAreaList(_common_areas);
|
||||||
.catch(
|
setDeleteCommonAreaDialog(false);
|
||||||
err => {
|
setCommonArea(emptyCommonArea);
|
||||||
console.log('Ocurrió un error con el fetch', err)
|
toast.current.show({
|
||||||
toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Comunidad de Viviendas no se pudo eliminar', life: 3000 });
|
severity: 'success',
|
||||||
}
|
summary: 'Área Común Eliminada',
|
||||||
);
|
life: 3000,
|
||||||
*/
|
});
|
||||||
let _common_areas = commonAreaList.filter(
|
}
|
||||||
(val) => val._id !== commonArea._id,
|
)
|
||||||
);
|
.catch(
|
||||||
setCommonAreaList(_common_areas);
|
err => {
|
||||||
setDeleteCommonAreaDialog(false);
|
console.log('Ocurrió un error con el fetch', err)
|
||||||
setCommonArea(emptyCommonArea);
|
toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Área Común no se pudo eliminar', life: 3000 });
|
||||||
toast.current.show({
|
}
|
||||||
severity: 'success',
|
);
|
||||||
summary: 'Área Común Eliminada',
|
|
||||||
life: 3000,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteSelectedCommonAreas = () => {
|
const deleteSelectedCommonAreas = () => {
|
||||||
let _commonareas = commonAreaList.filter(
|
let _common_areas = commonAreaList.filter(
|
||||||
(val) => !selectedCommonAreas.includes(val),
|
(val) => !selectedCommonAreas.includes(val),
|
||||||
);
|
);
|
||||||
/* selectedCommunities.map((item) => {
|
selectedCommonAreas.map((item) => {
|
||||||
fetch('http://localhost:4000/user/deleteCommunity/' + item._id, {
|
fetch('http://localhost:4000/commonArea/deleteCommonArea/' + item._id, {
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})*/
|
});
|
||||||
setCommonAreaList(_commonareas);
|
_common_areas = _common_areas.filter(
|
||||||
|
(val) => val.status != -1,
|
||||||
|
)
|
||||||
|
setCommonAreaList(_common_areas);
|
||||||
setDeleteCommonAreasDialog(false);
|
setDeleteCommonAreasDialog(false);
|
||||||
setSelectedCommonAreas(null);
|
setSelectedCommonAreas(null);
|
||||||
toast.current.show({
|
toast.current.show({
|
||||||
|
@ -246,24 +260,52 @@ const AreasComunes = () => {
|
||||||
const headerBookable = (
|
const headerBookable = (
|
||||||
<>
|
<>
|
||||||
<p> {' '}
|
<p> {' '}
|
||||||
<FontAwesomeIcon icon={faAt} style={{ color: "#D7A86E" }} />{' '}
|
<FontAwesomeIcon icon={faClipboardCheck} style={{ color: "#D7A86E" }} />{' '}
|
||||||
Reservable
|
Reservación
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
|
||||||
|
const headerStatus = (
|
||||||
|
<>
|
||||||
|
<p> {' '}
|
||||||
|
<FontAwesomeIcon icon={faCircleQuestion} style={{ color: "#C08135" }} />{' '}
|
||||||
|
Estado
|
||||||
</p>
|
</p>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
const bookableBodyTemplate = (rowData) => {
|
||||||
|
let class_color = '';
|
||||||
|
if(rowData.bookable == '1') {
|
||||||
|
class_color = '0';
|
||||||
|
} else {
|
||||||
|
class_color = '1';
|
||||||
|
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<span
|
||||||
|
className={`status status-${class_color}`}
|
||||||
|
>
|
||||||
|
{rowData.bookable_text}
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const statusBodyTemplate = (rowData) => {
|
const statusBodyTemplate = (rowData) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<span
|
<span
|
||||||
className={`status status-${rowData.bookable}`}
|
className={`status status-${rowData.status}`}
|
||||||
>
|
>
|
||||||
{rowData.bookable_text}
|
{rowData.status_text}
|
||||||
</span>
|
</span>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="grid">
|
<div className="grid">
|
||||||
|
@ -279,9 +321,10 @@ const AreasComunes = () => {
|
||||||
globalFilter={globalFilter} emptyMessage="No hay áreas comunes registrados.">
|
globalFilter={globalFilter} emptyMessage="No hay áreas comunes registrados.">
|
||||||
<Column selectionMode="multiple" headerStyle={{ width: '3rem' }}></Column>
|
<Column selectionMode="multiple" headerStyle={{ width: '3rem' }}></Column>
|
||||||
<Column field="name" sortable header={headerName} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column>
|
<Column field="name" sortable header={headerName} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column>
|
||||||
<Column field="hourMin" header={headerHourMin} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }} alignFrozen="left"></Column>
|
<Column field="hourMin" header={headerHourMin} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }} alignFrozen="left"></Column>
|
||||||
<Column field="hourMax" header={headerHourMax} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}> </Column>
|
<Column field="hourMax" header={headerHourMax} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}> </Column>
|
||||||
<Column field="bookable" sortable header={headerBookable} body={statusBodyTemplate} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column>
|
<Column field="bookable" sortable header={headerBookable} body={bookableBodyTemplate} style={{ flexGrow: 1, flexBasis: '200px', minWidth: '200px', wordBreak: 'break-word' }}></Column>
|
||||||
|
<Column field="status" sortable header={headerStatus} body={statusBodyTemplate} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column>
|
||||||
<Column style={{ flexGrow: 1, flexBasis: '130px', minWidth: '130px' }} body={actionsCommonArea}></Column>
|
<Column style={{ flexGrow: 1, flexBasis: '130px', minWidth: '130px' }} body={actionsCommonArea}></Column>
|
||||||
</DataTable>
|
</DataTable>
|
||||||
<Dialog visible={deleteCommonAreaDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteCommonAreaDialogFooter} onHide={hideDeleteCommonAreaDialog}>
|
<Dialog visible={deleteCommonAreaDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteCommonAreaDialogFooter} onHide={hideDeleteCommonAreaDialog}>
|
||||||
|
|
Loading…
Reference in New Issue