diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 06773f17..e5096af7 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -82,6 +82,35 @@ export class AppController { ); } + @Put('user/updateGuard/:id') + updateGuard( + @Param('id') id: string, + @Body('dni') dni: string, + @Body('name') name: string, + @Body('last_name') last_name: string, + @Body('email') email: string, + @Body('phone') phone: number, + @Body('password') password: string, + @Body('user_type') user_type: string, + @Body('status') status: string, + @Body('date_entry') date_entry: Date, + @Body('community_id') community_id: string, + ) { + return this.appService.updateGuard( + id, + dni, + name, + last_name, + email, + phone, + password, + user_type, + status, + date_entry, + community_id, + ); + } + @Put('user/updateUser/:id') updateUser( @Param('id') id: string, diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 0cf32af5..55dfb993 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -89,6 +89,38 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + updateGuard( + _id: string, + dni: string, + name: string, + last_name: string, + email: string, + phone: number, + password: string, + user_type: string, + status: string, + date_entry: Date, + community_id: string, + ) { + const pattern = { cmd: 'updateGuard' }; + const payload = { + id: _id, + dni: dni, + name: name, + last_name: last_name, + email: email, + phone: phone, + password: password, + user_type: user_type, + status: status, + date_entry: date_entry, + community_id: community_id, + }; + return this.clientUserApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + //POST parameter from API createAdminSystem(dni: string, name: string, last_name: string, email: string, phone: number , user_type: string, status: string, date_entry: Date) { diff --git a/devshell.toml b/devshell.toml index 046ba4a0..3713822c 100644 --- a/devshell.toml +++ b/devshell.toml @@ -6,3 +6,8 @@ help = "Per project developer environments" [[commands]] package = "nodejs" help = "Node.js" + +[[commands]] +package = "nodePackages.expo-cli" +help = "Expo CLI" + diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index 1f49a3fc..abcb86ee 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -69,6 +69,11 @@ export class UsersController { return this.userService.update(user._id, user); } + @MessagePattern({ cmd: 'updateGuard' }) + updateGuard(@Payload() guard: UserDocument) { + return this.userService.update(guard.id, guard); + } + @MessagePattern({ cmd: 'removeUser' }) remove(@Payload() id: string) { let dni = id['dni']; diff --git a/web-ui/web-react/src/components/GuardasSeguridad.js b/web-ui/web-react/src/components/GuardasSeguridad.js index 1b2f069f..1654a330 100644 --- a/web-ui/web-react/src/components/GuardasSeguridad.js +++ b/web-ui/web-react/src/components/GuardasSeguridad.js @@ -13,582 +13,655 @@ import { faAt } from '@fortawesome/free-solid-svg-icons'; import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons'; import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons'; import { useCookies } from "react-cookie"; +import classNames from 'classnames'; const GuardasSeguridad = () => { - let emptyGuarda = { - _id: null, - dni: '', - name: '', - last_name: '', - email: '', - phone: '', - password: '', - user_type: '1', - status: '1', - status_text: '', + let emptyGuarda = { + _id: null, + dni: '', + name: '', + last_name: '', + email: '', + phone: '', + password: '', + user_type: '1', + status: '1', + status_text: '', + date_entry: Date.now(), + 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('dni').value, + name: document.getElementById('name').value, + last_name: document.getElementById('last_name').value, + email: document.getElementById('email').value, + phone: document.getElementById('phone').value, + password: document.getElementById('email').value, + user_type: "4", //4 es guarda + status: "1", + date_entry: Date.now(), + 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 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(() => { + if (guarda._id === null) { + 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((response) => { + if (response.status != 201) + console.log(`Ocurrió un error con el servicio: ${response.status}`); + else + return response.json(); + }).then(() => { listaGuardasF(); - }, []) + }).catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } else { + data._id = guarda._id; + console.log(`Actualizando guarda: ${data}`); + fetch(`http://localhost:4000/user/updateGuard/${guarda._id}`, { + cache: 'no-cache', + method: 'PUT', + body: JSON.stringify(data), + 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(() => { + toast.current.show({ + severity: 'success', + summary: 'Guarda actualizada', + detail: 'Guarda actualizado correctamente' + }); + setGuarda(emptyGuarda); + listaGuardasF(); + }) + } + setSaveButtonTitle("Registrar"); + } - 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 - }; - var data2 = { - dni: "11979037", - name: "Jorge", - last_name: "Soto", - email: "jorgesoto@gmail.com", - phone: 84664515, - password: "1203", - user_type: "2", - status: "1", - community_id: "62be68215692582bbfd77134" + 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((response) => { + if (response.status != 201) + console.log(`Ocurrió un error con el servicio: ${response.status}`); + else + return response.json(); + }).then(() => { + 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((response) => { + if (response.status != 201) + console.log(`Ocurrió un error con el servicio: ${response.status}`); + else + return response.json(); + }).then(function() { + 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' } - 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) - ); + }) + }) + 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" } - - 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 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 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 ( -
-
- ); - } - - const leftToolbarTemplate = () => { - return ( - -
-
-
- ) - } - - const rightToolbarTemplate = () => { - return ( - - - - - - +
+
); + } + + const leftToolbarTemplate = () => { + return ( + +
+
+
+ ) + } + + const rightToolbarTemplate = () => { + return ( + +