diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..31ca1731 --- /dev/null +++ b/.envrc @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# ^ added for shellcheck and file-type detection + +# Watch & reload direnv on change +watch_file devshell.toml + +if [[ $(type -t use_flake) != function ]]; then + echo "ERROR: use_flake function missing." + echo "Please update direnv to v2.30.0 or later." + exit 1 +fi +use flake \ No newline at end of file diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 4d8a64fa..22f0a461 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -29,24 +29,3 @@ jobs: cd ./api-gateway npm ci npm run build --if-present - build-web: - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [14.x, 16.x, 18.x] - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ - steps: - - name: checkout - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - - name: Test - env: - NODE_OPTIONS: '--openssl-legacy-provider' - run: | - cd ./web-ui/web-react/ - npm ci - npm run build --if-present diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 5d2b9f92..abc90be1 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Post, Body, Param, Delete } from '@nestjs/common'; +import { Controller, Get, Post, Put, Body, Param, Delete } from '@nestjs/common'; import { AppService } from './app.service'; @Controller() export class AppController { @@ -80,6 +80,33 @@ export class AppController { ); } + @Put('user/updateUser') + updateUser( + @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.updateUser( + dni, + name, + last_name, + email, + phone, + password, + user_type, + status, + date_entry, + community_id, + ); + } + @Get('user/allUsers') allUsers() { return this.appService.allUsers(); diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index e1199d79..a5df9129 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -53,6 +53,36 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + updateUser( + 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: 'updateUser' }; + const payload = { + 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 new file mode 100644 index 00000000..4b8c8bff --- /dev/null +++ b/devshell.toml @@ -0,0 +1,4 @@ +# https://numtide.github.io/devshell +[[commands]] +package = "devshell.cli" +help = "Per project developer environments" diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..9066d086 --- /dev/null +++ b/flake.lock @@ -0,0 +1,92 @@ +{ + "nodes": { + "devshell": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1658746384, + "narHash": "sha256-CCJcoMOcXyZFrV1ag4XMTpAPjLWb4Anbv+ktXFI1ry0=", + "owner": "numtide", + "repo": "devshell", + "rev": "0ffc7937bb5e8141af03d462b468bd071eb18e1b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1642700792, + "narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "846b2ae0fc4cc943637d3d1def4454213e203cba", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1656928814, + "narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1643381941, + "narHash": "sha256-pHTwvnN4tTsEKkWlXQ8JMY423epos8wUOhthpwJjtpc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5efc8ca954272c4376ac929f4c5ffefcc20551d5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1659782844, + "narHash": "sha256-tM/qhHFE61puBxh9ebP3BIG1fkRAT4rHqD3jCM0HXGY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c85e56bb060291eac3fb3c75d4e0e64f6836fcfe", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "devshell": "devshell", + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..fb42e8a6 --- /dev/null +++ b/flake.nix @@ -0,0 +1,20 @@ +{ + description = "virtual environments"; + + inputs.devshell.url = "github:numtide/devshell"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = { self, flake-utils, devshell, nixpkgs }: + flake-utils.lib.eachDefaultSystem (system: { + devShell = + let pkgs = import nixpkgs { + inherit system; + + overlays = [ devshell.overlay ]; + }; + in + pkgs.devshell.mkShell { + imports = [ (pkgs.devshell.importTOML ./devshell.toml) ]; + }; + }); +} diff --git a/web-ui/web-react/src/App.js b/web-ui/web-react/src/App.js index 46d3b946..eecc9d49 100644 --- a/web-ui/web-react/src/App.js +++ b/web-ui/web-react/src/App.js @@ -33,6 +33,7 @@ import AdministradoresComunidad from './components/AdministradoresComunidad'; import GuardasSeguridad from './components/GuardasSeguridad'; import Communities from './components/ComunidadViviendas'; import Inquilinos from './components/Inquilinos'; +import InquilinosCompletar from "./components/InquilinosCompletar.js"; import Crud from './pages/Crud'; import EmptyPage from './pages/EmptyPage'; @@ -421,6 +422,7 @@ const App = () => { + diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 26971e1f..4325bcf5 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -1,27 +1,22 @@ -import { Button } from 'primereact/button'; +import { Button } from 'primereact/button' import { InputText } from 'primereact/inputtext' -import React, { useEffect, useState, useRef } from 'react' -import { DataTable } from 'primereact/datatable'; -import { Column } from 'primereact/column'; -import { Dropdown } from 'primereact/dropdown'; -import { Toast } from 'primereact/toast'; -import { Dialog } from 'primereact/dialog'; -import { Toolbar } from 'primereact/toolbar'; +import React, { useEffect, useRef, useState } from 'react' +import { DataTable } from 'primereact/datatable' +import { Column } from 'primereact/column' +import { Dropdown } from 'primereact/dropdown' +import { Toast } from 'primereact/toast' +import { Dialog } from 'primereact/dialog' +import { Toolbar } from 'primereact/toolbar' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import { faHome } from '@fortawesome/free-solid-svg-icons'; -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 { faHashtag } from '@fortawesome/free-solid-svg-icons'; -import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons'; - -import { useCookies } from "react-cookie"; - +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 { faHashtag } from '@fortawesome/free-solid-svg-icons' +import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons' +import { useCookies } from 'react-cookie' const Inquilinos = () => { - let emptyTenant = { _id: null, dni: '', @@ -37,66 +32,65 @@ const Inquilinos = () => { date_entry: new Date(), status: '1', status_text: '', - }; + } - const [tenants, setTenants] = useState([]); - const [tenant, setTenant] = useState(emptyTenant); - const [selectedTentants, setSelectedTenants] = useState(null); - const [globalFilter, setGlobalFilter] = useState(null); - const [deleteTenantDialog, setDeleteTenantDialog] = useState(false); - const [deleteTenantsDialog, setDeleteTenantsDialog,] = useState(false); - const [communitiesList, setCommunitiesList] = useState([]); - const [communityId, setCommunityId] = useState(null); - const [submitted, setSubmitted] = useState(false); - const toast = useRef(null); - const dt = useRef(null); - - const [cookies, setCookie] = useCookies(); - const [changeStatusTenantDialog, setChangeStatusTenantDialog] = useState(false); + const [tenants, setTenants] = useState([]) + const [tenant, setTenant] = useState(emptyTenant) + const [selectedTentants, setSelectedTenants] = useState(null) + const [globalFilter, setGlobalFilter] = useState(null) + const [deleteTenantDialog, setDeleteTenantDialog] = useState(false) + const [deleteTenantsDialog, setDeleteTenantsDialog] = useState(false) + const [communitiesList, setCommunitiesList] = useState([]) + const [communityId, setCommunityId] = useState(null) + const [submitted, setSubmitted] = useState(false) + const toast = useRef(null) + const dt = useRef(null) + const [cookies, setCookie] = useCookies() + const [changeStatusTenantDialog, setChangeStatusTenantDialog] = + useState(false) async function tenantsList() { - await fetch(`http://localhost:4000/user/findTenants/${cookies.community_id}`, { method: 'GET' }) + await fetch( + `http://localhost:4000/user/findTenants/${cookies.community_id}`, + { method: 'GET' }, + ) .then((response) => response.json()) - .then(data => data.message) - .then(data => { - data = data.filter( - (val) => val.status != -1, - ) + .then((data) => data.message) + .then((data) => { + data = data.filter((val) => val.status !== -1) data.map((item) => { - if (item.status == '1') { - item.status_text = 'Activo'; - } else if (item.status == '0') { - item.status_text = 'Inactivo'; + if (item.status === '1') { + item.status_text = 'Activo' + } else if (item.status === '0') { + item.status_text = 'Inactivo' } - - if (item.number_house == "") { - item.number_house = "Sin vivienda asignada"; + if (item.number_house === '') { + item.number_house = 'Sin vivienda asignada' } }) setTenants(data) - }); + }) } - async function getCommunites() { - let response = await fetch('http://localhost:4000/community/allCommunities', { method: 'GET' }); - let resList = await response.json(); - let list = await resList.message; - list = await list.filter( - (val) => val.status != -1, + let response = await fetch( + 'http://localhost:4000/community/allCommunities', + { method: 'GET' }, ) - setCommunitiesList(await list); + let resList = await response.json() + let list = await resList.message + list = await list.filter((val) => val.status !== -1) + setCommunitiesList(await list) } useEffect(() => { - tenantsList(); - }, []) - + tenantsList() + }, [tenantsList]) useEffect(() => { - getCommunites(); + getCommunites() }, []) const cList = communitiesList.map((item) => ({ @@ -105,206 +99,167 @@ const Inquilinos = () => { })) function registrarInquilino() { - let data = { - dni: document.getElementById('identificacion').value, - name: document.getElementById('nombre').value, - last_name: document.getElementById('apellidos').value, - phone: document.getElementById('telefono').value, + let newTenant = { + _id: null, + dni: '', + name: '', + last_name: '', email: document.getElementById('correo_electronico').value, + phone: '', + password: '', community_id: document.getElementById('numero_vivienda').value, - password: document.getElementById('password').value, + community_name: '', + number_house: 'Sin número de vivienda', + date_entry: new Date(), user_type: '3', status: '1', - }; + status_text: '', + } fetch('http://localhost:3000/api/createUser', { method: 'POST', cache: 'no-cache', - body: JSON.stringify(data), + body: JSON.stringify(newTenant), headers: { 'Content-Type': 'application/json', }, }).then((response) => { if (response.ok) { - alert('Inquilino registrado correctamente'); + alert('Inquilino registrado correctamente') } else { - alert('Error al registrar inquilino'); + alert('Error al registrar inquilino') } - }); + }) } const deleteTenant = () => { - /* fetch('http://localhost:4000/community/deleteCommunity/' + community._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 _community = communities.filter(val => val._id !== community._id); - setCommunities(_community); - setDeleteCommunityDialog(false); - setCommunity(emptyCommunity); - toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 }); - } - ) - .catch( - err => { - console.log('Ocurrió un error con el fetch', err) - toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Comunidad de Viviendas no se pudo eliminar', life: 3000 }); - } - ); - */ - let _tenants = tenants.filter( - (val) => val._id !== tenant._id, - ); - setTenants(_tenants); - setDeleteTenantDialog(false); - setTenant(emptyTenant); + let _tenants = tenants.filter((val) => val._id !== tenant._id) + setTenants(_tenants) + setDeleteTenantDialog(false) + setTenant(emptyTenant) toast.current.show({ severity: 'success', summary: 'Inquilino Eliminado', life: 3000, - }); - }; + }) + } const deleteSelectedTenants = () => { - let _tenants = tenants.filter( - (val) => !selectedTentants.includes(val), - ); - /* selectedCommunities.map((item) => { - fetch('http://localhost:4000/user/deleteCommunity/' + item._id, { - cache: 'no-cache', - method: 'DELETE', - headers: { - 'Content-Type': 'application/json' - } - }) - })*/ - setTenants(_tenants); - setDeleteTenantsDialog(false); - setSelectedTenants(null); + let _tenants = tenants.filter((val) => !selectedTentants.includes(val)) + setTenants(_tenants) + setDeleteTenantsDialog(false) + setSelectedTenants(null) toast.current.show({ severity: 'success', summary: 'Éxito', detail: 'Inquilinos Eliminados', life: 3000, - }); - }; + }) + } const cambiarStatusUser = () => { - if (tenant.status == '1') { - tenant.status = '0'; - tenant.status_text = 'Inactivo'; - - } else if (tenant.status == '0') { - tenant.status = '1'; - tenant.status_text = 'Activo'; + if (tenant.status === '1') { + tenant.status = '0' + tenant.status_text = 'Inactivo' + } else if (tenant.status === '0') { + tenant.status = '1' + tenant.status_text = 'Activo' } var data = { id: tenant._id, status: tenant.status, - }; + } fetch('http://localhost:4000/user/changeStatus', { cache: 'no-cache', method: 'POST', body: JSON.stringify(data), headers: { - 'Content-Type': 'application/json' - } + '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((response) => { + if (response.status !== 201) { + console.log('Ocurrió un error con el servicio: ' + response.status) + } else { + return response.json() } - ) - .then( - function (response) { - setChangeStatusTenantDialog(false); - toast.current.show({ - severity: 'success', - summary: 'Éxito', - detail: 'Inquilino Actualizado', - life: 3000, - }); - } - ) - .catch( - err => console.log('Ocurrió un error con el fetch', err) - ); + }) + .then(() => { + setChangeStatusTenantDialog(false) + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Inquilino Actualizado', + life: 3000, + }) + }) + .catch((err) => console.log('Ocurrió un error con el fetch', err)) } const hideDeleteTenantDialog = () => { - setDeleteTenantDialog(false); + setDeleteTenantDialog(false) } const hideDeleteTenantsDialog = () => { - setDeleteTenantsDialog(false); + setDeleteTenantsDialog(false) } const confirmDeleteTenant = (tenant) => { - setTenant(tenant); - setDeleteTenantDialog(true); + setTenant(tenant) + setDeleteTenantDialog(true) } const confirmDeleteSelected = () => { - setDeleteTenantsDialog(true); - }; + setDeleteTenantsDialog(true) + } const hideChangeStatusTenantDialog = () => { - setChangeStatusTenantDialog(false); - }; + setChangeStatusTenantDialog(false) + } const confirmChangeStatusTenant = (tenant) => { - setTenant(tenant); - setChangeStatusTenantDialog(true); - }; + setTenant(tenant) + setChangeStatusTenantDialog(true) + } const actionsTenant = (rowData) => { - let icono = ''; - let text = ''; - if (rowData.status == '0') { - icono = "pi pi-eye"; - text = "Activar Inquilino" - } else if (rowData.status == '1') { - icono = "pi pi-eye-slash"; - text = "Inactivar Inquilino" - + let icono = '' + let text = '' + if (rowData.status === '0') { + icono = 'pi pi-eye' + text = 'Activar Inquilino' + } else if (rowData.status === '1') { + icono = 'pi pi-eye-slash' + text = 'Inactivar Inquilino' } return ( -
-
- ); + ) } const leftToolbarTemplate = () => { return ( -
-
) @@ -313,95 +268,141 @@ const Inquilinos = () => { const rightToolbarTemplate = () => { return ( -