From 176a6931cedeb3e76030eafc10cbcf0d824ffd77 Mon Sep 17 00:00:00 2001 From: Eduardo Quiros Date: Thu, 18 Aug 2022 20:31:54 -0600 Subject: [PATCH 01/17] add node to devshell --- devshell.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/devshell.toml b/devshell.toml index 4b8c8bff..d7746d94 100644 --- a/devshell.toml +++ b/devshell.toml @@ -2,3 +2,8 @@ [[commands]] package = "devshell.cli" help = "Per project developer environments" + +[[commands]] +package = "nodejs" +help = "Node.js" + From 2a69b1ff16d59397a1641a4339a029f7688cabb3 Mon Sep 17 00:00:00 2001 From: Eduardo Quiros Date: Thu, 18 Aug 2022 21:03:34 -0600 Subject: [PATCH 02/17] corregir puerto de api para crear inquilino --- web-ui/web-react/src/components/Inquilinos.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 4325bcf5..5d6630d2 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -116,7 +116,7 @@ const Inquilinos = () => { status_text: '', } - fetch('http://localhost:3000/api/createUser', { + fetch('http://localhost:4000/api/createUser', { method: 'POST', cache: 'no-cache', body: JSON.stringify(newTenant), From f6ce86909fddceaf5c93ec4736e40ce71f30cc10 Mon Sep 17 00:00:00 2001 From: Eduardo Quiros Date: Sat, 20 Aug 2022 02:41:46 -0600 Subject: [PATCH 03/17] add name to servicio comunidad viviendas --- servicio-comunidad-viviendas/package-lock.json | 1 + 1 file changed, 1 insertion(+) diff --git a/servicio-comunidad-viviendas/package-lock.json b/servicio-comunidad-viviendas/package-lock.json index 46dd3dd0..22c95f9b 100644 --- a/servicio-comunidad-viviendas/package-lock.json +++ b/servicio-comunidad-viviendas/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "servicio-comunidad-viviendas", "version": "0.0.1", "license": "UNLICENSED", "dependencies": { From dc65cdda4fa73af5eef20745cf7825a6bfc12dd2 Mon Sep 17 00:00:00 2001 From: Eduardo Quiros Date: Sat, 20 Aug 2022 02:42:33 -0600 Subject: [PATCH 04/17] clean up saveTenant function --- web-ui/web-react/src/components/Inquilinos.js | 72 ++++++++++--------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 5d6630d2..e16249f2 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -98,38 +98,39 @@ const Inquilinos = () => { value: item._id, })) - function registrarInquilino() { - let newTenant = { - _id: null, - dni: '', - name: '', - last_name: '', - email: document.getElementById('correo_electronico').value, - phone: '', - password: '', - community_id: document.getElementById('numero_vivienda').value, - community_name: '', - number_house: 'Sin número de vivienda', - date_entry: new Date(), - user_type: '3', - status: '1', - status_text: '', - } + const saveTenant = () => { + if (tenant.email && tenant.number_house) { + let _tenants = [...tenants] + let _tenant = { ...tenant } + _tenant.community_id = communityId + console.log(_tenant) - fetch('http://localhost:4000/api/createUser', { - method: 'POST', - cache: 'no-cache', - body: JSON.stringify(newTenant), - headers: { - 'Content-Type': 'application/json', - }, - }).then((response) => { - if (response.ok) { - alert('Inquilino registrado correctamente') - } else { - alert('Error al registrar inquilino') - } - }) + 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 !== 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 = () => { @@ -418,6 +419,13 @@ const Inquilinos = () => { ) } + const onInputChange = (e) => { + const value = (e.target && e.target.value) || '' + let _tenant = { ...tenant } + _tenant[`${name}`] = value + setTenant(_tenant) + } + return (
@@ -618,7 +626,7 @@ const Inquilinos = () => { onChange={(e) => setCommunityId(e.value)} />
-
From 435af70439534c03d8036e598824d95493728cf3 Mon Sep 17 00:00:00 2001 From: Eduardo Quiros Date: Sat, 20 Aug 2022 03:44:14 -0600 Subject: [PATCH 05/17] set emptyTenant to constant --- web-ui/web-react/src/components/Inquilinos.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index e16249f2..dd76474b 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -17,7 +17,7 @@ import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons' import { useCookies } from 'react-cookie' const Inquilinos = () => { - let emptyTenant = { + const emptyTenant = { _id: null, dni: '', name: '', From 2a325d4e2e0d4ae55083906e6122c6f1dec6c68c Mon Sep 17 00:00:00 2001 From: Eduardo Quiros Date: Sat, 20 Aug 2022 04:40:07 -0600 Subject: [PATCH 06/17] add onInputChange to inputs --- web-ui/web-react/src/components/Inquilinos.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index dd76474b..30dbbea1 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -614,6 +614,7 @@ const Inquilinos = () => { type='email' className='form-control' id='correo_electronico' + onChange={(e) => onInputChange(e, 'email')} />
@@ -623,7 +624,7 @@ const Inquilinos = () => { id='numero_vivienda' value={communityId} options={cList} - onChange={(e) => setCommunityId(e.value)} + onChange={(e) => onInputChange(e, 'community_id')} />