Merge pull request #174 from DeimosPr4/US-29-Activar/DesactivarÁreaComún

activar/desactivar area comun
This commit is contained in:
Eduardo Quiros 2022-08-19 21:39:13 +00:00 committed by GitHub
commit 18fd3064fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 144 additions and 3 deletions

View File

@ -215,6 +215,8 @@ export class AppController {
) { ) {
return this.appService.changeStatusCommunity(pId, pStatus); return this.appService.changeStatusCommunity(pId, pStatus);
} }
// #==== API Common Areas // #==== API Common Areas
@Post('commonArea/createCommonArea') @Post('commonArea/createCommonArea')
createCommonArea( createCommonArea(
@ -254,6 +256,14 @@ export class AppController {
return this.appService.deleteCommonArea(id); return this.appService.deleteCommonArea(id);
} }
@Post('commonArea/changeStatus')
changeStatusCommonArea(
@Body('id') pId: string,
@Body('status') pStatus: string,
) {
return this.appService.changeStatusCommonArea(pId, pStatus);
}
// #==== API GUEST // #==== API GUEST
//#API userService - create user //#API userService - create user
@Post('guest/createGuest') @Post('guest/createGuest')

View File

@ -343,6 +343,15 @@ export class AppService {
.pipe(map((message: string) => ({ message }))); .pipe(map((message: string) => ({ message })));
} }
changeStatusCommonArea(pId: string, pStatus: string) {
const pattern = { cmd: 'changeStatus' };
const payload = { id: pId, status: pStatus };
return this.clientCommonAreaApp
.send<string>(pattern, payload)
.pipe(map((message: string) => ({ message })));
}
// ====================== GUESTS =============================== // ====================== GUESTS ===============================
//POST parameter from API //POST parameter from API

View File

@ -39,4 +39,12 @@ export class CommonAreasController {
let _community_id = id['community_id']; let _community_id = id['community_id'];
return this.commonAreasService.findByCommunity(_community_id); return this.commonAreasService.findByCommunity(_community_id);
} }
//cambiar de estado
@MessagePattern({ cmd: 'changeStatus' })
changeStatus(@Payload() body: string) {
let pid = body['id'];
let pstatus = body['status'];
return this.commonAreasService.changeStatus(pid,pstatus);
}
} }

View File

@ -41,4 +41,10 @@ export class CommonAreasService {
return this.commonAreaModel.find({ community_id: community_id }).exec(); return this.commonAreaModel.find({ community_id: community_id }).exec();
} }
async changeStatus(id: string, status: string) {
return this.commonAreaModel.findOneAndUpdate({ _id: id }, {status: status}, {
new: true,
});
}
} }

View File

@ -44,7 +44,6 @@ const AdministradoresSistema = () => {
status_text: '', status_text: '',
}; };
async function fetchP() { async function fetchP() {
let nombres = await fetch(urlFetch, { method: 'GET' }); let nombres = await fetch(urlFetch, { method: 'GET' });
let adminRes = await nombres.json(); let adminRes = await nombres.json();
@ -60,11 +59,11 @@ const AdministradoresSistema = () => {
}) })
setAdministrators(await data); setAdministrators(await data);
} }
useEffect(() => { useEffect(() => {
fetchP(); fetchP();
}, []) }, [])
function registrarAdmin() { function registrarAdmin() {
var data = { var data = {
dni: document.getElementById('identificacion').value, dni: document.getElementById('identificacion').value,

View File

@ -43,6 +43,7 @@ const AreasComunes = () => {
const dt = useRef(null); const dt = useRef(null);
const [cookies, setCookie] = useCookies(); const [cookies, setCookie] = useCookies();
const [changeStatusAreaDialog, setChangeStatusAreaDialog] = useState(false);
@ -220,6 +221,51 @@ const AreasComunes = () => {
}); });
}; };
const cambiarStatuscommonArea = () => {
if (commonArea.status == '1') {
commonArea.status = '0';
commonArea.status_text = 'Inactivo';
} else if (commonArea.status == '0') {
commonArea.status = '1';
commonArea.status_text = 'Activo';
}
var data = {
id: commonArea._id,
status: commonArea.status,
};
fetch('http://localhost:4000/commonArea/changeStatus', {
cache: 'no-cache',
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
})
.then(
function (response) {
if (response.status != 201)
console.log('Ocurrió un error con el servicio: ' + response.status);
else
return response.json();
}
)
.then(
function (response) {
setChangeStatusAreaDialog(false);
toast.current.show({
severity: 'success',
summary: 'Éxito',
detail: 'Área Común Actualizada',
life: 3000,
});
}
)
.catch(
err => console.log('Ocurrió un error con el fetch', err)
);
}
const hideDeleteCommonAreaDialog = () => { const hideDeleteCommonAreaDialog = () => {
setDeleteCommonAreaDialog(false); setDeleteCommonAreaDialog(false);
} }
@ -237,9 +283,36 @@ const AreasComunes = () => {
setDeleteCommonAreasDialog(true); setDeleteCommonAreasDialog(true);
}; };
const hideChangeStatusAreaDialog = () => {
setChangeStatusAreaDialog(false);
};
const confirmChangeStatusArea = (commonArea) => {
setCommonArea(commonArea);
setChangeStatusAreaDialog(true);
};
const actionsCommonArea = (rowData) => { const actionsCommonArea = (rowData) => {
let icono = '';
let text = '';
if (rowData.status == '0') {
icono = "pi pi-eye";
text = "Activar Área Común"
} else if (rowData.status == '1') {
icono = "pi pi-eye-slash";
text = "Inactivar Área Común"
}
return ( return (
<div className="actions"> <div className="actions">
<Button
icon={`${icono}`}
className="p-button-rounded p-button-warning mt-2 mx-2"
onClick={() => confirmChangeStatusArea(rowData)}
title={`${text}`}
/>
<Button <Button
icon="pi pi-trash" icon="pi pi-trash"
className="p-button-rounded p-button-danger mt-2" className="p-button-rounded p-button-danger mt-2"
@ -276,6 +349,22 @@ const AreasComunes = () => {
</> </>
); );
const changeStatusAreaDialogFooter = (
<>
<Button
label="No"
icon="pi pi-times"
className="p-button-text"
onClick={hideChangeStatusAreaDialog}
/>
<Button
label="Yes"
icon="pi pi-check"
className="p-button-text"
onClick={cambiarStatuscommonArea}
/>
</>
);
const leftToolbarTemplate = () => { const leftToolbarTemplate = () => {
return ( return (
@ -431,6 +520,26 @@ const AreasComunes = () => {
{selectedCommonAreas && <span>¿Está seguro eliminar las áreas comunes seleccionadas?</span>} {selectedCommonAreas && <span>¿Está seguro eliminar las áreas comunes seleccionadas?</span>}
</div> </div>
</Dialog> </Dialog>
<Dialog
visible={changeStatusAreaDialog}
style={{ width: '450px' }}
header="Confirmar"
modal
footer={changeStatusAreaDialogFooter}
onHide={hideChangeStatusAreaDialog}
>
<div className="flex align-items-center justify-content-center">
<i
className="pi pi-exclamation-triangle mr-3"
style={{ fontSize: '2rem' }}
/>
{commonArea && (
<span>
¿Estás seguro que desea cambiar estado a <b>{commonArea.name}</b>?
</span>
)}
</div>
</Dialog>
</div> </div>
</div> </div>
<div className="col-12"> <div className="col-12">
@ -513,7 +622,7 @@ const AreasComunes = () => {
</div> </div>
<div className="field col-12 md:col-6"> <div className="field col-12 md:col-6">
<label htmlFor="bookable">¿Necesita Reservación?</label> <label htmlFor="bookable">¿Necesita Reservación?</label>
<div className="formgrid grid align-items-end" style={{marginTop: '12px', width: '300px'}}> <div className="formgrid grid align-items-end" style={{ marginTop: '12px', width: '300px' }}>
<div className="field-radiobutton col-6"> <div className="field-radiobutton col-6">
<RadioButton <RadioButton