diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index d4a5c20b..e1199d79 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -269,6 +269,7 @@ export class AppService { hourMax: hourMax, bookable: bookable, community_id: community_id, + status: '1' }; return this.clientCommonAreaApp .send(pattern, payload) diff --git a/web-ui/web-react/src/components/AdministradoresSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js index 933d0381..10f299f2 100644 --- a/web-ui/web-react/src/components/AdministradoresSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -58,7 +58,7 @@ const AdministradoresSistema = () => { item.status_text = 'Inactivo'; } }) - setAdministrators(adminRes.message); + setAdministrators(await data); } useEffect(() => { fetchP(); @@ -614,12 +614,12 @@ const AdministradoresSistema = () => {
- +
- +
diff --git a/web-ui/web-react/src/components/AreasComunes.js b/web-ui/web-react/src/components/AreasComunes.js index 693467df..0850e31c 100644 --- a/web-ui/web-react/src/components/AreasComunes.js +++ b/web-ui/web-react/src/components/AreasComunes.js @@ -15,16 +15,15 @@ import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons'; import { faClipboardCheck } from '@fortawesome/free-solid-svg-icons'; import classNames from 'classnames'; import { useCookies } from "react-cookie"; - +import { RadioButton } from 'primereact/radiobutton'; const AreasComunes = () => { let emptyCommonArea = { _id: null, - dni: '', name: '', - hourMin: '', - hourMax: '', + hourMin: '00:00', + hourMax: '01:00', community_id: '', bookable: '1', bookable_text: '', @@ -32,6 +31,7 @@ const AreasComunes = () => { status_text: '', }; + const [commonAreaList, setCommonAreaList] = useState([]); const [commonArea, setCommonArea] = useState(emptyCommonArea); const [selectedCommonAreas, setSelectedCommonAreas] = useState(null); @@ -44,6 +44,8 @@ const AreasComunes = () => { const [cookies, setCookie] = useCookies(); + + async function getCommonAreas() { await fetch(`http://localhost:4000/commonArea/findByCommunity/${cookies.community_id}`, { method: 'GET' }) .then((response) => response.json()) @@ -78,6 +80,74 @@ const AreasComunes = () => { getCommonAreas(); }, []); + const saveCommonArea = () => { + if ( + commonArea.name && + commonArea.hourMin < commonArea.hourMax + ) { + let _common_areas = [...commonAreaList]; + let _common_area = { ...commonArea }; + _common_area.community_id = cookies.community_id; + + // console.log(houses) + fetch('http://localhost:4000/commonArea/createCommonArea', { + cache: 'no-cache', + method: 'POST', + body: JSON.stringify(_common_area), + 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 (data) { + return data.message; + }) + .then((data) => { + if (data) { + if (data.bookable == '1') { + data.bookable_text = 'Necesaria'; + } else { + data.bookable_text = 'No es necesaria'; + } + + if (data.status == '1') { + data.status_text = 'Activo'; + } else if (data.status == '0') { + data.status_text = 'Inactivo'; + } else { + data.status_text = 'Eliminado'; + } + } + _common_areas.push(data); + + toast.current.show({ + severity: 'success', + summary: 'Registro exitoso', + detail: 'Área Común Creada', + life: 3000, + }); + setCommonAreaList(_common_areas); + setCommonArea(emptyCommonArea); + }) + .catch((err) => { + console.log('Ocurrió un error con el fetch', err); + toast.current.show({ + severity: 'danger', + summary: 'Error', + detail: 'No se pudo registrar el área común', + life: 3000 + }); + + }); + } else { + setSubmitted(true); + } + }; + const deleteCommonArea = () => { fetch('http://localhost:4000/commonArea/deleteCommonArea/' + commonArea._id, { @@ -167,8 +237,6 @@ const AreasComunes = () => { setDeleteCommonAreasDialog(true); }; - - const actionsCommonArea = (rowData) => { return (
@@ -181,6 +249,18 @@ const AreasComunes = () => { ); }; + const onBookableChange = (e) => { + let _commonArea = { ...commonArea }; + _commonArea['bookable'] = e.value; + setCommonArea(_commonArea); + }; + + const onInputChange = (e, name) => { + const val = (e.target && e.target.value) || ''; + let _commonArea = { ...commonArea }; + _commonArea[`${name}`] = val; + setCommonArea(_commonArea); + }; const deleteCommonAreaDialogFooter = ( <> @@ -278,7 +358,7 @@ const AreasComunes = () => { const bookableBodyTemplate = (rowData) => { let class_color = ''; - if(rowData.bookable == '1') { + if (rowData.bookable == '1') { class_color = '0'; } else { class_color = '1'; @@ -307,6 +387,18 @@ const AreasComunes = () => { ); }; + + function compareTimesMinRequired(hour1, hour2) { + var timeFormat1 = Number(hour1.replace(/[:]/g, '')); + var timeFormat2 = Number(hour2.replace(/[:]/g, '')); + if (timeFormat1 <= timeFormat2) { + return true; + } else { + return false; + } + } + + return (
@@ -341,6 +433,124 @@ const AreasComunes = () => {
+
+
+
Registro de área común
+
+
+ +
+ +
+ + + + onInputChange(e, 'name')} + value={commonArea.name} + required + autoFocus + className={classNames({ + 'p-invalid': submitted && commonArea.name === '', + })} + /> +
+ {submitted && commonArea.name === '' && ( + Nombre es requirido. + )} +
+
+
+ +
+
+ + + + onInputChange(e, 'hourMin')} + value={commonArea.hourMin} + required + autoFocus + className={classNames({ + 'p-invalid': submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin), + })} + /> +
+ {submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin) && ( + La hora de apertura debe ser menor que la hora de cierre. + )} +
+
+
+ +
+
+ + + + onInputChange(e, 'hourMax')} + value={commonArea.hourMax} + required + autoFocus + className={classNames({ + 'p-invalid': submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin), + })} + /> +
+ {submitted && compareTimesMinRequired(commonArea.hourMax, commonArea.hourMin) && ( + La hora de cierre debe ser mayor que la hora de apertura + )} +
+
+
+ +
+
+ + + +
+
+ + +
+
+
+ + +
+
+
+
); diff --git a/web-ui/web-react/src/components/GuardasSeguridad.js b/web-ui/web-react/src/components/GuardasSeguridad.js index a092910f..1b2f069f 100644 --- a/web-ui/web-react/src/components/GuardasSeguridad.js +++ b/web-ui/web-react/src/components/GuardasSeguridad.js @@ -11,18 +11,11 @@ import { faUserAlt } 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 { faCircleQuestion } from '@fortawesome/free-solid-svg-icons'; +import { useCookies } from "react-cookie"; const GuardasSeguridad = () => { - const [listaGuardas, setListaGuardas] = useState([]); - const [urlFetch, setUrlFetch] = useState('http://localhost:4000/user/findGuards/62be68215692582bbfd77134'); - const [guarda, setGuarda] = useState(emptyGuarda); - const [selectedGuardas, setSelectedGuardas] = useState(null); - const [globalFilter, setGlobalFilter] = useState(null); - const [deleteGuardaDialog, setDeleteGuardaDialog] = useState(false); - const [deleteGuardasDialog, setDeleteGuardasDialog] = useState(false); - const toast = useRef(null); - const dt = useRef(null); + let emptyGuarda = { _id: null, dni: '', @@ -32,16 +25,44 @@ const GuardasSeguridad = () => { phone: '', password: '', user_type: '1', - status: '' + status: '1', + status_text: '', }; + const [listaGuardas, setListaGuardas] = useState([]); + const [urlFetch, setUrlFetch] = useState('http://localhost:4000/user/findGuards/'); + const [guarda, setGuarda] = useState(emptyGuarda); + const [selectedGuardas, setSelectedGuardas] = useState(null); + const [globalFilter, setGlobalFilter] = useState(null); + const [deleteGuardaDialog, setDeleteGuardaDialog] = useState(false); + const [deleteGuardasDialog, setDeleteGuardasDialog] = useState(false); + const toast = useRef(null); + const dt = useRef(null); + + const [cookies, setCookie] = useCookies(); + const [changeStatusGuardDialog, setChangeStatusGuardDialog] = useState(false); + + const [guardDialog, setGuardDialog] = useState(false); + const [submitted, setSubmitted] = useState(false); + async function listaGuardasF() { - let nombres = await fetch(urlFetch, { method: 'GET' }); + let nombres = await fetch((urlFetch + cookies.community_id), { method: 'GET' }); let listaGuardasRes = await nombres.json(); - setListaGuardas(listaGuardasRes.message); + let data = await listaGuardasRes.message.filter( + (val) => val.status != -1, + ) + await data.map((item) => { + if (item.status == '1') { + item.status_text = 'Activo'; + } else if (item.status == '0') { + item.status_text = 'Inactivo'; + } + }) + setListaGuardas(await data); } + useEffect(() => { listaGuardasF(); }, []) @@ -56,7 +77,7 @@ const GuardasSeguridad = () => { password: document.getElementById('correo_electronico').value, user_type: "4", //4 es guarda status: "1", - community_id: "62be68215692582bbfd77134" + community_id: cookies.community_id }; var data2 = { dni: "11979037", @@ -66,7 +87,7 @@ const GuardasSeguridad = () => { phone: 84664515, password: "1203", user_type: "2", - status: "4", + status: "1", community_id: "62be68215692582bbfd77134" } console.log('ssss'); @@ -74,7 +95,7 @@ const GuardasSeguridad = () => { cache: 'no-cache', method: 'POST', mode: 'cors', - body: JSON.stringify(data2), + body: JSON.stringify(data), headers: { 'Content-Type': 'application/json' } @@ -89,7 +110,6 @@ const GuardasSeguridad = () => { ) .then( function (response) { - console.log('fff'); listaGuardasF(); } ) @@ -98,22 +118,51 @@ const GuardasSeguridad = () => { ); } - const hideDeleteGuardaDialog = () => { - setDeleteGuardaDialog(false); + const cambiarStatusUser = () => { + if (guarda.status == '1') { + guarda.status = '0'; + guarda.status_text = 'Inactivo'; + + } else if (guarda.status == '0') { + guarda.status = '1'; + guarda.status_text = 'Activo'; + } + var data = { + id: guarda._id, + status: guarda.status, + }; + fetch('http://localhost:4000/user/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) { + setChangeStatusGuardDialog(false); + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Guarda de Seguridad Actualizado', + life: 3000, + }); + } + ) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); } - const hideDeleteGuardasDialog = () => { - setDeleteGuardasDialog(false); - } - - const confirmDeleteGuarda = (guarda) => { - setGuarda(guarda); - setDeleteGuardaDialog(true); - } - - const confirmDeleteSelected = () => { - setDeleteGuardasDialog(true); - } const deleteGuarda = () => { @@ -166,10 +215,70 @@ const GuardasSeguridad = () => { toast.current.show({ severity: 'success', summary: 'Éxito', detail: 'Administradores del Sistema Eliminados', life: 3000 }); } - const actionsAdmin = (rowData) => { + const hideDeleteGuardaDialog = () => { + setDeleteGuardaDialog(false); + } + + const hideDeleteGuardasDialog = () => { + setDeleteGuardasDialog(false); + } + + const confirmDeleteGuarda = (guarda) => { + setGuarda(guarda); + setDeleteGuardaDialog(true); + } + + const confirmDeleteSelected = () => { + setDeleteGuardasDialog(true); + } + + const hideChangeStatusGuardDialog = () => { + setChangeStatusGuardDialog(false); + }; + + const confirmChangeStatusGuard = (guard) => { + setGuarda(guard); + setChangeStatusGuardDialog(true); + }; + + const hideGuardDialog = () => { + setSubmitted(false); + setGuardDialog(false); + }; + + const infoGuard = (guard) => { + setGuarda(guard); + setGuardDialog(true); + }; + + + const actionsGuard = (rowData) => { + let icono = ''; + let text = ''; + if (rowData.status == '0') { + icono = "pi pi-eye"; + text = "Activar Guarda de Seguridad" + } else if (rowData.status == '1') { + icono = "pi pi-eye-slash"; + text = "Inactivar Guarda de Seguridad" + + } return (
-
); } @@ -178,7 +287,11 @@ const GuardasSeguridad = () => { return (
-
) @@ -187,7 +300,9 @@ const GuardasSeguridad = () => { const rightToolbarTemplate = () => { return ( -
diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 8beac1d8..26971e1f 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -331,14 +331,14 @@ const Inquilinos = () => { const deleteTenantDialogFooter = ( <>