From d517a19872e5e6c8542674895d0542b9bdc56e2c Mon Sep 17 00:00:00 2001 From: Eduardo Quiros Date: Sun, 21 Aug 2022 20:27:04 -0600 Subject: [PATCH 01/13] agregar titulos a botones --- web-ui/web-react/src/components/Inquilinos.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 812af9ae..fb9568b7 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -246,7 +246,7 @@ const Inquilinos = () => { text = 'Activar Inquilino' } else if (rowData.status === '1') { icono = 'pi pi-eye-slash' - text = 'Inactivar Inquilino' + text = 'Desactivar Inquilino' } return (
@@ -254,6 +254,7 @@ const Inquilinos = () => { icon="pi pi-exclamation-circle" className="p-button-rounded p-button-info mt-2 mx-2" onClick={() => infoTenant(rowData)} + title="Ver Información" />
) From f31576573d560f7efc66320433c503a105b6e043 Mon Sep 17 00:00:00 2001 From: Eduardo Quiros Date: Mon, 22 Aug 2022 00:07:33 -0600 Subject: [PATCH 02/13] =?UTF-8?q?agregar=20edici=C3=B3n=20de=20inquilinos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api-gateway/src/app.controller.ts | 8 +- api-gateway/src/app.service.ts | 6 + servicio-usuarios/src/users/users.service.ts | 13 -- web-ui/web-react/src/components/Inquilinos.js | 127 +++++++++++++----- 4 files changed, 108 insertions(+), 46 deletions(-) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 7e6fe785..adff4cf7 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -65,6 +65,7 @@ export class AppController { @Body('status') status: string, @Body('date_entry') date_entry: Date, @Body('community_id') community_id: string, + @Body('number_house') number_house: string, ) { return this.appService.createUser( dni, @@ -77,11 +78,13 @@ export class AppController { status, date_entry, community_id, + number_house, ); } - @Put('user/updateUser') + @Put('user/updateUser/:id') updateUser( + @Param('id') id: string, @Body('dni') dni: string, @Body('name') name: string, @Body('last_name') last_name: string, @@ -92,8 +95,10 @@ export class AppController { @Body('status') status: string, @Body('date_entry') date_entry: Date, @Body('community_id') community_id: string, + @Body('number_house') number_house: string, ) { return this.appService.updateUser( + id, dni, name, last_name, @@ -104,6 +109,7 @@ export class AppController { status, date_entry, community_id, + number_house, ); } diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index c3396486..965b4005 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -34,6 +34,7 @@ export class AppService { status: string, date_entry: Date, community_id: string, + number_house: string, ) { const pattern = { cmd: 'createUser' }; const payload = { @@ -47,6 +48,7 @@ export class AppService { status: status, date_entry: date_entry, community_id: community_id, + number_house: number_house, }; return this.clientUserApp .send(pattern, payload) @@ -54,6 +56,7 @@ export class AppService { } updateUser( + _id: string, dni: string, name: string, last_name: string, @@ -64,9 +67,11 @@ export class AppService { status: string, date_entry: Date, community_id: string, + number_house: string, ) { const pattern = { cmd: 'updateUser' }; const payload = { + id: _id, dni: dni, name: name, last_name: last_name, @@ -77,6 +82,7 @@ export class AppService { status: status, date_entry: date_entry, community_id: community_id, + number_house: number_house, }; return this.clientUserApp .send(pattern, payload) diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 413cb497..d117beeb 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -143,19 +143,6 @@ export class UsersService { return await this.userModel.find({ community_id: pcommunity_id, user_type: 4 }) - .then(async (users) => { - if (users) { - await Promise.all( - users.map(async (u) => { - //buscar al usuario con el id de la comunidad anexado - let number_house = await this.findNumHouseTenant(pcommunity_id, u['_id']); - u['number_house'] = number_house; - return u; - }), - ) - } - return users; - }) } diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index fb9568b7..a73f6b3d 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -42,10 +42,12 @@ const Inquilinos = () => { const [deleteTenantDialog, setDeleteTenantDialog] = useState(false) const [deleteTenantsDialog, setDeleteTenantsDialog] = useState(false) const [community, setCommunity] = useState([]) + const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar") const [houseNumber, setHouseNumber] = useState([]) const [housesList, setHousesList] = useState([]) const [submitted, setSubmitted] = useState(false) const [infoDialogVisible, setShowInfoDialog] = useState(false) + const [cancelSaveButtonVisible, setCancelSaveButtonVisible] = useState(false) const toast = useRef(null) const dt = useRef(null) const [cookies] = useCookies() @@ -101,40 +103,69 @@ const Inquilinos = () => { }, []) const saveTenant = () => { - if (tenant.email && tenant.number_house && tenant.dni - && tenant.name && tenant.last_name && tenant.phone) { - let _tenants = [...tenants] - let _tenant = { ...tenant } - _tenant.community_id = cookies.community_id; - _tenant.number_house = houseNumber; - _tenant.password = _tenant.email; + if (tenant._id === null) { + if (tenant.email && tenant.number_house && tenant.dni + && tenant.name && tenant.last_name && tenant.phone) { + let _tenants = [...tenants] + let _tenant = { ...tenant } + _tenant.community_id = cookies.community_id; + _tenant.number_house = houseNumber; + _tenant.password = _tenant.email; + console.log(`Registrando nuevo inquilino: ${_tenant}`) - fetch(`http://localhost:4000/user/createUser`, { + fetch(`http://localhost:4000/user/createUser`, { + cache: 'no-cache', + method: 'POST', + body: JSON.stringify(_tenant), + headers: { + 'Content-Type': 'application/json', + }, + }) + .then((response) => { + if (response.status !== 200) + console.log(`Hubo un error en el servicio: ${response.status}`) + else return response.json() + }) + .then(() => { + _tenants.push(_tenant) + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Inquilino creado', + life: 3000, + }) + setTenants(_tenants) + setTenant(emptyTenant) + setHouseNumber('') + }) + .catch((error) => console.log(`Ocurrió un error: ${error}`)) + } else setSubmitted(true) + } else { + let _tenant = { ..._tenant, number_house: houseNumber }; + console.log(`Actualizando inquilino: ${_tenant}`) + fetch(`http://localhost:4000/user/updateUser/${tenant._id}`, { cache: 'no-cache', - method: 'POST', + method: 'PUT', body: JSON.stringify(_tenant), headers: { 'Content-Type': 'application/json', }, + }).then((response) => { + if (response.status !== 200) + console.log(`Hubo un error en el servicio: ${response.status}`) + else return response.json() + }).then(() => { + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Inquilino editado', + life: 3000, + }) + tenantsList() + setTenant(emptyTenant) + setHouseNumber('') }) - .then((response) => { - if (response.status !== 201) - console.log(`Hubo un error en el servicio: ${response.status}`) - else return response.json() - }) - .then(() => { - _tenants.push(_tenant) - toast.current.show({ - severity: 'success', - summary: 'Éxito', - detail: 'Inquilino creado', - life: 3000, - }) - setTenants(_tenants) - setTenant(emptyTenant) - }) - .catch((error) => console.log(`Ocurrió un error: ${error}`)) - } else setSubmitted(true) + } } const deleteTenant = () => { @@ -238,6 +269,20 @@ const Inquilinos = () => { setShowInfoDialog(true); } + const editTenant = (tenant) => { + setTenant(tenant); + console.log(tenant); + setSaveButtonTitle('Actualizar'); + setHouseNumber(tenant.number_house); + } + + const cancelEdit = () => { + setTenant(emptyTenant); + setSaveButtonTitle('Registrar'); + setCancelSaveButtonVisible(false); + setHouseNumber(''); + } + const actionsTenant = (rowData) => { let icono = '' let text = '' @@ -250,6 +295,12 @@ const Inquilinos = () => { } return (
+
- From 06468fa60114e3bf52534f1a93e29a8bfafebf09 Mon Sep 17 00:00:00 2001 From: Eduardo Quiros Date: Mon, 22 Aug 2022 04:04:36 -0600 Subject: [PATCH 06/13] eliminar espaciado excesivo --- .../src/components/GuardasSeguridad.js | 1174 ++++++++--------- 1 file changed, 587 insertions(+), 587 deletions(-) diff --git a/web-ui/web-react/src/components/GuardasSeguridad.js b/web-ui/web-react/src/components/GuardasSeguridad.js index 85fd4cc2..811575c1 100644 --- a/web-ui/web-react/src/components/GuardasSeguridad.js +++ b/web-ui/web-react/src/components/GuardasSeguridad.js @@ -16,601 +16,601 @@ import { useCookies } from "react-cookie"; const GuardasSeguridad = () => { - let emptyGuarda = { - _id: null, - dni: '', - name: '', - last_name: '', - email: '', - phone: '', - password: '', - user_type: '1', - status: '1', - status_text: '', - community_id: '', + let emptyGuarda = { + _id: null, + dni: '', + name: '', + last_name: '', + email: '', + phone: '', + password: '', + user_type: '1', + status: '1', + status_text: '', + community_id: '', + }; + + + 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 [saveButtonTitle, setSaveButtonTitle] = useState("Registrar"); + 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 + cookies.community_id), { method: 'GET' }); + let listaGuardasRes = await nombres.json(); + 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(); + }, []) + + function registrarGuarda() { + var data = { + dni: document.getElementById('identificacion').value, + name: document.getElementById('nombre').value, + last_name: document.getElementById('apellidos').value, + email: document.getElementById('correo_electronico').value, + phone: document.getElementById('telefono').value, + password: document.getElementById('correo_electronico').value, + user_type: "4", //4 es guarda + status: "1", + community_id: cookies.community_id }; - - - 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 [saveButtonTitle, setSaveButtonTitle] = useState("Registrar"); - 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 + cookies.community_id), { method: 'GET' }); - let listaGuardasRes = await nombres.json(); - 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(); - }, []) - - function registrarGuarda() { - var data = { - dni: document.getElementById('identificacion').value, - name: document.getElementById('nombre').value, - last_name: document.getElementById('apellidos').value, - email: document.getElementById('correo_electronico').value, - phone: document.getElementById('telefono').value, - password: document.getElementById('correo_electronico').value, - user_type: "4", //4 es guarda - status: "1", - community_id: cookies.community_id - }; - console.log('ssss'); - fetch('http://localhost:4000/user/createGuard', { - cache: 'no-cache', - method: 'POST', - mode: 'cors', - 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) { - listaGuardasF(); - } - ) - .catch( - err => console.log('Ocurrió un error con el fetch', err) - ); - } - - 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'; + console.log('ssss'); + fetch('http://localhost:4000/user/createGuard', { + cache: 'no-cache', + method: 'POST', + mode: 'cors', + 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(); } - 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 deleteGuarda = () => { - - fetch('http://localhost:4000/user/deleteAdminSystem/' + guarda._id, { - cache: 'no-cache', - method: 'DELETE', - 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) { - let _guarda = listaGuardas.filter(val => val._id !== guarda._id); - setListaGuardas(_guarda); - setDeleteGuardaDialog(false); - setGuarda(emptyGuarda); - toast.current.show({ severity: 'success', summary: 'Éxito', detail: 'Administrador del Sistema Eliminado', life: 3000 }); - } - ) - .catch( - err => { - console.log('Ocurrió un error con el fetch', err) - toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Administrador del Sistema no se pudo Eliminar', life: 3000 }); - } - ); - } - - const deleteSelectedGuardas = () => { - let _guardas = listaGuardas.filter(val => !selectedGuardas.includes(val)); - selectedGuardas.map((item) => { - fetch('http://localhost:4000/user/deleteAdminSystem/' + item._id, { - cache: 'no-cache', - method: 'DELETE', - headers: { - 'Content-Type': 'application/json' - } - }) - }) - setListaGuardas(_guardas); - setDeleteGuardasDialog(false); - setSelectedGuardas(null); - toast.current.show({ severity: 'success', summary: 'Éxito', detail: 'Administradores del Sistema Eliminados', life: 3000 }); - } - - 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 editGuard = (guard) => { - setGuarda(guard); - console.log(guard); - setSaveButtonTitle("Actualizar"); - } - - const cancelEdit = () => { - setGuarda(emptyGuarda); - setSaveButtonTitle("Registrar"); - } - - 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" - + ) + .then( + function(response) { + listaGuardasF(); } - return ( -
-
- ); + ) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } + + 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'; } - - const leftToolbarTemplate = () => { - return ( - -
-
-
- ) - } - - const rightToolbarTemplate = () => { - return ( - -