Merge pull request #214 from DeimosPr4/US-12-PerfilAdministradordeComunidaddeViviendas

perfil admin de comunidad
This commit is contained in:
Eduardo Quiros 2022-08-31 13:38:26 +00:00 committed by GitHub
commit 4ee53476e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 480 additions and 12 deletions

View File

@ -1,4 +1,5 @@
import { Controller, Get, Post, Put, Body, Param, Delete } from '@nestjs/common'; import { Controller, Get, Post, Put, Body, Param, Delete } from '@nestjs/common';
import { Console } from 'console';
import { AppService } from './app.service'; import { AppService } from './app.service';
@Controller() @Controller()
export class AppController { export class AppController {
@ -305,6 +306,30 @@ export class AppController {
return this.appService.updateAdminSystem(_id, dni, name, last_name, email, phone); return this.appService.updateAdminSystem(_id, dni, name, last_name, email, phone);
} }
@Put('user/updateTenant/:id')
updateTenant(
@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('community_id') community_id: string,
@Body('number_house') number_house: string,
) {
return this.appService.updateTenant(
id,
dni,
name,
last_name,
email,
phone,
community_id,
number_house,
);
}
// #==== API Communities // #==== API Communities
@Post('community/createCommunity') @Post('community/createCommunity')
createCommunity( createCommunity(
@ -369,8 +394,9 @@ export class AppController {
saveTenant( saveTenant(
@Body('community_id') community_id: string, @Body('community_id') community_id: string,
@Body('number_house') number_house: string, @Body('number_house') number_house: string,
@Body('tenant_id') tenant_id: string, @Body('_id') tenant_id: string,
) { ) {
console.log(community_id + ' ' + number_house + ' ' + tenant_id)
return this.appService.saveTenant(community_id, number_house, tenant_id); return this.appService.saveTenant(community_id, number_house, tenant_id);
} }

View File

@ -175,6 +175,36 @@ export class AppService {
.send<string>(pattern, payload) .send<string>(pattern, payload)
.pipe(map((message: string) => ({ message }))); .pipe(map((message: string) => ({ message })));
} }
async updateTenant(
_id: string,
dni: string,
name: string,
last_name: string,
email: string,
phone: number,
community_id: string,
number_house: string,
) {
await this.saveTenant(community_id, number_house, _id);
const pattern = { cmd: 'updateTenant' };
const payload = {
id: _id,
dni: dni,
name: name,
last_name: last_name,
email: email,
phone: phone,
community_id: community_id,
number_house: number_house,
};
return this.clientUserApp
.send<string>(pattern, payload)
.pipe(map((message: string) => ({ message })));
}
//POST parameter from API //POST parameter from API
createAdminSystem(dni: string, name: string, last_name: string, email: string, phone: number createAdminSystem(dni: string, name: string, last_name: string, email: string, phone: number
, user_type: string, status: string, date_entry: Date) { , user_type: string, status: string, date_entry: Date) {
@ -791,4 +821,19 @@ export class AppService {
return pass; return pass;
} }
async saveTenantNumHouse(community_id: string, number_house: string, tenant_id: string) {
const pattern = { cmd: 'saveTenantNumHouse' }
const payload = { _id: community_id, number_house: number_house, tenant_id: tenant_id }
return await this.clientCommunityApp
.send<string>(pattern, payload)
.pipe(
map((response: string) => ({ response }))
)
}
} }

View File

@ -57,7 +57,6 @@ export class CommunitiesController {
@MessagePattern({ cmd: 'saveTenant' }) @MessagePattern({ cmd: 'saveTenant' })
saveTenant(@Payload() body: string) { saveTenant(@Payload() body: string) {
let id = body['_id']; let id = body['_id'];
let tenant_id = body['tenant_id']; let tenant_id = body['tenant_id'];
let number_house = body['number_house']; let number_house = body['number_house'];

View File

@ -88,7 +88,6 @@ export class CommunitiesService {
await community.houses.map(house => { await community.houses.map(house => {
if (house.number_house == number_house) { if (house.number_house == number_house) {
if (house.tenants) { if (house.tenants) {
house.tenants.tenant_id = ptenant_id house.tenants.tenant_id = ptenant_id
} else { } else {
let tenant = new Tenant() let tenant = new Tenant()
@ -109,6 +108,7 @@ export class CommunitiesService {
await community.houses.map(house => { await community.houses.map(house => {
if (house.number_house === number_house) { if (house.number_house === number_house) {
if(house.tenants)
house.tenants.tenant_id = ""; house.tenants.tenant_id = "";
house.state = "desocupada" house.state = "desocupada"
} }

View File

@ -77,7 +77,7 @@ export class UsersController {
@MessagePattern({ cmd: 'updateGuard' }) @MessagePattern({ cmd: 'updateGuard' })
updateGuard(@Payload() guard: UserDocument) { updateGuard(@Payload() guard: UserDocument) {
return this.userService.update(guard.id, guard); return this.userService.update(guard._id, guard);
} }
@MessagePattern({ cmd: 'updateAdminCommunity' }) @MessagePattern({ cmd: 'updateAdminCommunity' })
@ -85,6 +85,11 @@ export class UsersController {
return this.userService.update(user._id, user); return this.userService.update(user._id, user);
} }
@MessagePattern({ cmd: 'updateTenant' })
updateTenant(@Payload() tenant: UserDocument) {
return this.userService.updateTenant(tenant.id, tenant);
}
@MessagePattern({ cmd: 'removeUser' }) @MessagePattern({ cmd: 'removeUser' })
remove(@Payload() id: string) { remove(@Payload() id: string) {
let dni = id['dni']; let dni = id['dni'];

View File

@ -29,7 +29,7 @@ export class UsersService {
let passwordEncriptada = Md5.init(user.password); let passwordEncriptada = Md5.init(user.password);
user.password = passwordEncriptada; user.password = passwordEncriptada;
let userCreated = await this.userModel.create(user); let userCreated = await this.userModel.create(user);
await this.saveTenantNumHouse(user.community_id, user.number_house, userCreated['_id']); await this.saveTenant(user.community_id, user.number_house, userCreated['_id']);
let community = await this.findCommunity(user.community_id); let community = await this.findCommunity(user.community_id);
user.community_id = community['name']; user.community_id = community['name'];
@ -117,6 +117,9 @@ export class UsersService {
} }
async update(id: string, user: UserDocument) { async update(id: string, user: UserDocument) {
console.log(id)
console.log(user)
return this.userModel.findOneAndUpdate({ _id: id }, user, { return this.userModel.findOneAndUpdate({ _id: id }, user, {
new: true, new: true,
}); });
@ -131,6 +134,18 @@ export class UsersService {
}); });
} }
async updateTenant(id: string, user: UserDocument) {
await this.saveTenant(user.community_id, user.number_house, user.id);
return await this.userModel.findOneAndUpdate({ _id: id }, {
name: user['name'], last_name: user['last_name'],
dni: user['dni'], email: user['email'], phone: user['phone'],
number_house: user['number_house']
}, {
new: true,
});
}
/* async remove(id: string) { /* async remove(id: string) {
return this.userModel.findByIdAndRemove({ _id: id }).exec(); return this.userModel.findByIdAndRemove({ _id: id }).exec();
}*/ }*/
@ -293,7 +308,7 @@ export class UsersService {
} }
async saveTenantNumHouse(community_id: string, number_house: string, tenant_id: string) { async saveTenant(community_id: string, number_house: string, tenant_id: string) {
const pattern = { cmd: 'saveTenant' } const pattern = { cmd: 'saveTenant' }
const payload = { _id: community_id, number_house: number_house, tenant_id: tenant_id } const payload = { _id: community_id, number_house: number_house, tenant_id: tenant_id }

View File

@ -58,6 +58,7 @@ import { useCookies } from "react-cookie";
import LogInUser from './components/LogInUser'; import LogInUser from './components/LogInUser';
import Page404 from './components/Page404' import Page404 from './components/Page404'
import Reservaciones from './components/Reservaciones'; import Reservaciones from './components/Reservaciones';
import PerfilAdminComunidad from './components/PerfilAdminComunidad';
const App = () => { const App = () => {
@ -472,6 +473,7 @@ const App = () => {
<Route path="/reservaciones" component={Reservaciones} /> <Route path="/reservaciones" component={Reservaciones} />
<Route path="/registroComunicado" component={RegistroComunicado} /> <Route path="/registroComunicado" component={RegistroComunicado} />
<Route path="/invitadosComunidad" component={InvitadosComunidad} /> <Route path="/invitadosComunidad" component={InvitadosComunidad} />
<Route path="/pefilAdminComunidad" component={PerfilAdminComunidad} />
</> </>
) )
} else { } else {

View File

@ -88,10 +88,11 @@ export const AppTopbar = (props) => {
</button> </button>
</li> */} </li> */}
<li className='mx-2' hidden={!logged}> <li className='mx-2' hidden={!logged}>
<button className="p-link layout-topbar-button" > <a href="/pefilAdminComunidad"> <button className="p-link layout-topbar-button" >
<i className="pi pi-user" /> <i className="pi pi-user" />
<span>Perfil</span> <span>Perfil</span>
</button>
</button></a>
</li> </li>
<li className='mx-2' hidden={!logged}> <li className='mx-2' hidden={!logged}>
<button className="p-link layout-topbar-button" onClick={cerrarSesion} > <button className="p-link layout-topbar-button" onClick={cerrarSesion} >

View File

@ -72,6 +72,9 @@ const Inquilinos = () => {
item.number_house = 'Sin vivienda asignada' item.number_house = 'Sin vivienda asignada'
} }
}) })
data = data.filter(
(val) => val.status != -1,
);
setTenants(data) setTenants(data)
}) })
} }
@ -156,9 +159,9 @@ const Inquilinos = () => {
.catch((error) => console.log(`Ocurrió un error: ${error}`)) .catch((error) => console.log(`Ocurrió un error: ${error}`))
} else setSubmitted(true) } else setSubmitted(true)
} else { } else {
let _tenant = { ..._tenant, number_house: houseNumber }; let _tenant = { ...tenant, number_house: houseNumber };
console.log(`Actualizando inquilino: ${_tenant}`) console.log(`Actualizando inquilino: ${_tenant}`)
fetch(`http://localhost:4000/user/updateUser/${tenant._id}`, { fetch(`http://localhost:4000/user/updateTenant/${tenant._id}`, {
cache: 'no-cache', cache: 'no-cache',
method: 'PUT', method: 'PUT',
body: JSON.stringify(_tenant), body: JSON.stringify(_tenant),
@ -170,6 +173,17 @@ const Inquilinos = () => {
console.log(`Hubo un error en el servicio: ${response.status}`) console.log(`Hubo un error en el servicio: ${response.status}`)
else return response.json() else return response.json()
}).then(() => { }).then(() => {
fetch('http://localhost:4000/community/saveTenant',
{
cache: 'no-cache',
method: 'POST',
body: JSON.stringify(_tenant),
headers: {
'Content-Type': 'application/json',
}
});
toast.current.show({ toast.current.show({
severity: 'success', severity: 'success',
summary: 'Éxito', summary: 'Éxito',

View File

@ -0,0 +1,361 @@
import React, { useEffect, useState, useRef } from 'react';
import { useCookies } from "react-cookie";
import { DataTable } from 'primereact/datatable';
import { Column } from 'primereact/column';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faHome, faUserAlt } from '@fortawesome/free-solid-svg-icons';
import { faMapLocationDot } from '@fortawesome/free-solid-svg-icons';
import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons';
import { faHashtag } from '@fortawesome/free-solid-svg-icons';
import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons';
const PerfilAdminComunidad = () => {
let emptyAdminCommunity = {
_id: null,
dni: '',
name: '',
last_name: '',
email: '',
phone: '',
password: '',
confirmPassword: '',
community_id: '',
community_name: '',
user_type: '2',
date_entry: new Date(),
status: '1',
status_text: '',
};
let emptyCommunity = {
_id: null,
name: '',
province: '',
canton: '',
district: '',
phone: '',
num_houses: 0,
status: '1',
status_text: '',
date_entry: new Date(),
houses: [],
};
const [admin, setAdmin] = useState(emptyAdminCommunity);
const [community, setCommunity] = useState(emptyCommunity);
const [cookies, setCookie] = useCookies();
const [globalFilter, setGlobalFilter] = useState(null);
//para el perfil de la comunidad
const [tenants, setTenants] = useState([]);
const [commonAreaList, setCommonAreaList] = useState([]);
const [provincesList, setProvincesList] = useState([]);
const [cantonsList, setCantonsList] = useState([]);
const [districtsList, setDistrictsList] = useState([]);
async function getProvinces() {
const response = await fetch('assets/demo/data/provincias.json', {
method: 'GET',
});
return await response.json();
}
async function getCantons() {
const response = await fetch('assets/demo/data/cantones.json', {
method: 'GET',
});
return await response.json();
}
async function getDistricts() {
const response = await fetch('assets/demo/data/distritos.json', {
method: 'GET',
});
return await response.json();
}
async function getAdmin() {
await fetch('http://localhost:4000/user/findUserById/' + cookies.id, { method: 'GET' })
.then((response) => response.json())
.then(data => {
let item = data.message;
setAdmin(item);
if (item.community_id || item.community_id != '') {
getCommunity()
} else {
item.community_name = "Sin Comunidad Asignada";
}
})
}
useEffect(() => {
getAdmin();
}, [])
async function getCommunity() {
let pList = await getProvinces();
let cList = await getCantons();
let dList = await getDistricts();
await fetch(`http://localhost:4000/community/findCommunityName/${cookies.community_id}`, { method: 'GET' })
.then((response2) => response2.json())
.then(data => data.message)
.then(data => {
data.province = pList.find((p) => p.code === data.province).name;
data.canton = cList.find((p) => p.code === data.canton).name;
data.district = dList.find((p) => p.code === data.district).name;
setCommunity(data)
})
}
useEffect(() => {
getCommunity();
}, [])
async function tenantsList(id) {
await fetch(`http://localhost:4000/user/findTenants/${id}`, { method: 'GET' })
.then((response) => response.json())
.then(data => data.message)
.then(data => {
data = data.filter(
(val) => val.status != -1,
)
setTenants(data)
});
}
useEffect(() => {
tenantsList(cookies.community_id);
}, [])
function findNameTenant(tenant_id) {
let name = '';
if (tenant_id == '') {
name = 'Sin inquilino';
} else {
let tenant = tenants.find(t => t._id == tenant_id)
name = tenant['name'] + ' ' + tenant['last_name'];
}
return name;
}
const headerNumberHouses = (
<>
<p>
{' '}
<FontAwesomeIcon icon={faHashtag} style={{ color: '#D7A86E' }} />{' '}
Código de vivienda
</p>
</>
);
const headerTenant = (
<>
<p>
{' '}
<FontAwesomeIcon icon={faUserAlt} style={{ color: '#C08135' }} />{' '}
Inquilino
</p>
</>
);
const tenantsBodyTemplate = (rowData) => {
let tenants = rowData.tenants;
let name = 'Sin inquilino';
if (rowData.tenants) {
name = findNameTenant(tenants.tenant_id);
}
return (
<>
{name}
</>
)
}
return (
<>
<div className="grid justify-content-center">
<div className="col-6" >
<div className="card">
<div className='container text-center'>
<div className='row my-4'>
<div className=" col-12 md:col-12">
<h3>Información Básica</h3>
</div>
<div className=" col-6 md:col-6">
<i className="pi pi-home icon-khaki"></i>
<p><strong>Nombre Completo</strong></p>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className="p-inputgroup justify-content-evenly">
<p>{admin.name + ' ' + admin.last_name}</p>
</div>
</div>
</div>
<div className=" col-6 md:col-6">
<i className="pi pi-id-card icon-khaki"></i>
<p><strong>Identificación</strong></p>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className="p-inputgroup justify-content-evenly">
<p>{admin.dni}</p>
</div>
</div>
</div>
</div>
<div className='row my-4'>
<div className=" col-12 md:col-12">
<h3>Contacto</h3>
</div>
<div className=" col-6 md:col-6">
<i className="pi pi-at icon-khaki"></i>
<p><strong>Correo Electrónico</strong></p>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className="p-inputgroup justify-content-evenly">
<p>{admin.email}</p>
</div>
</div>
</div>
<div className=" col-6 md:col-6">
<i className="pi pi-phone icon-khaki"></i>
<p><strong>Número de teléfono</strong></p>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className="p-inputgroup justify-content-evenly">
<p>{admin.phone}</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div className='col-6'>
{community && (
<div className="card">
<div className='container text-center'>
<div className='row my-4'>
<div className=" col-12 md:col-12">
<h3>Comunidad Asignada</h3>
</div>
<div className=" col-4 md:col-4">
<i className="pi pi-home icon-khaki"></i>
<p><strong>Nombre</strong></p>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{community.name}</p>
</div>
</div>
</div>
<div className="col-4 md:col-4">
<i className="pi pi-phone icon-khaki"></i>
<p><strong>Teléfono Administrativo</strong></p>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{community.phone}</p>
</div>
</div>
</div>
<div className=" col-4 col-md-4 md:col-4">
<i className="pi pi-map-marker icon-khaki"></i>
<p><strong>Ubicación</strong></p>
<div className="p-0 col-10 md:col-10">
<div className="p-inputgroup align-items-center justify-content-evenly">
<p>{community.province}, {community.canton}, {community.district}</p>
</div>
</div>
</div>
</div>
<div className='row my-5'>
<div className=" col-12 md:col-12">
<h3>Viviendas de la Comunidad</h3>
</div>
<div className=" col-12 md:col-12">
<i className="pi pi-hashtag icon-khaki"></i>
<p><strong>Cantidad de Viviendas</strong></p>
<div className="p-0 col-2 md:col-2" style={{ margin: '0 auto' }}>
<div className="p-inputgroup justify-content-evenly">
<p>{community.num_houses}</p>
</div>
</div>
</div>
</div>
</div>
</div>
)}
</div>
</div>
<div className='grid justify-content-center'>
<div className='col-6'>
{community && (
<div className="card">
<div className='container text-center'>
<div className='row my-5'>
<div className=" col-12 md:col-12">
<h3> Viviendas</h3>
<div className="p-0 col-12 md:col-12" style={{ margin: '0 auto' }}>
<div className="p-inputgroup justify-content-evenly">
<DataTable
value={community.houses}
paginator
rows={5}
scrollable
scrollHeight="200px"
scrollDirection="both"
rowsPerPageOptions={[5, 10, 25]}
className="datatable-responsive mt-3"
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
currentPageReportTemplate="Mostrando {first} a {last} de {totalRecords} viviendas"
globalFilter={globalFilter}
>
<Column
field="number_house"
header={headerNumberHouses}
style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px' }}
></Column>
<Column
field="tenants"
header={headerTenant}
body={tenantsBodyTemplate}
style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px' }}
></Column>
</DataTable>
</div>
</div>
</div>
</div>
</div>
</div>
)}
</div>
</div>
</>
)
}
export default React.memo(PerfilAdminComunidad)