registro de comunidad
This commit is contained in:
parent
c44e732b1c
commit
df2c932646
|
@ -78,11 +78,11 @@ export class AppController {
|
||||||
@Body('canton') canton: string,
|
@Body('canton') canton: string,
|
||||||
@Body('district') district: string,
|
@Body('district') district: string,
|
||||||
@Body('num_houses') num_houses: number,
|
@Body('num_houses') num_houses: number,
|
||||||
@Body('phone') phone: number,
|
@Body('phone') phone: string,
|
||||||
@Body('quote') quote: number,
|
@Body('quote') quote: number,
|
||||||
@Body('status') status: string,
|
@Body('status') status: string,
|
||||||
@Body('date_entry') date_entry: Date,
|
@Body('date_entry') date_entry: Date,
|
||||||
@Body('houses') houses: [{}],
|
@Body('houses') houses: [],
|
||||||
|
|
||||||
) {
|
) {
|
||||||
return this.appService.createCommunity(name, province, canton,
|
return this.appService.createCommunity(name, province, canton,
|
||||||
|
|
|
@ -131,11 +131,11 @@ export class AppService {
|
||||||
|
|
||||||
//POST parameter from API
|
//POST parameter from API
|
||||||
createCommunity(name: string, province: string, canton: string, district: string
|
createCommunity(name: string, province: string, canton: string, district: string
|
||||||
, num_houses: number, phone: number, quote: number, status: string, date_entry: Date, houses: [{}]) {
|
, num_houses: number, phone: string, quote: number, status: string, date_entry: Date, houses: []) {
|
||||||
const pattern = { cmd: 'createCommunity' };
|
const pattern = { cmd: 'createCommunity' };
|
||||||
const payload = {
|
const payload = {
|
||||||
name: name, province: province, canton: canton, district: district, num_houses: num_houses,
|
name: name, province: province, canton: canton, district: district, num_houses: num_houses,
|
||||||
phone: phone, quote: quote, status: status, date_entry: date_entry, houses
|
phone: phone, quote: quote, status: status, date_entry: date_entry, houses: houses
|
||||||
};
|
};
|
||||||
return this.clientCommunityApp
|
return this.clientCommunityApp
|
||||||
.send<string>(pattern, payload)
|
.send<string>(pattern, payload)
|
||||||
|
|
|
@ -10,7 +10,7 @@ export class Community {
|
||||||
@Prop()
|
@Prop()
|
||||||
id_admin: string;
|
id_admin: string;
|
||||||
|
|
||||||
@Prop({ default: "Sin Administrador" })
|
@Prop()
|
||||||
name_admin: string ;
|
name_admin: string ;
|
||||||
|
|
||||||
@Prop()
|
@Prop()
|
||||||
|
@ -29,7 +29,7 @@ export class Community {
|
||||||
num_houses: number;
|
num_houses: number;
|
||||||
|
|
||||||
@Prop()
|
@Prop()
|
||||||
phone: number;
|
phone: string;
|
||||||
|
|
||||||
@Prop()
|
@Prop()
|
||||||
quote: number;
|
quote: number;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
|
import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
|
||||||
|
import e from 'express';
|
||||||
import { Document } from 'mongoose';
|
import { Document } from 'mongoose';
|
||||||
|
import { empty } from 'rxjs';
|
||||||
import { Tenant, TenantSchema } from './tenant.schema';
|
import { Tenant, TenantSchema } from './tenant.schema';
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +17,7 @@ export class House extends Document {
|
||||||
@Prop({ default: "desocupada" })
|
@Prop({ default: "desocupada" })
|
||||||
state: string;
|
state: string;
|
||||||
|
|
||||||
@Prop({ type: TenantSchema, default: " " })
|
@Prop({ type: TenantSchema })
|
||||||
tenants: Tenant;
|
tenants: Tenant;
|
||||||
}
|
}
|
||||||
export const HouseSchema = SchemaFactory.createForClass(House);
|
export const HouseSchema = SchemaFactory.createForClass(House);
|
|
@ -4,7 +4,7 @@ import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
|
||||||
|
|
||||||
@Schema()
|
@Schema()
|
||||||
export class Tenant {
|
export class Tenant {
|
||||||
@Prop()
|
@Prop( {default: ''})
|
||||||
tenant_id: string;
|
tenant_id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,44 @@
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState, useRef } from 'react';
|
||||||
import { InputText } from 'primereact/inputtext';
|
import { InputText } from 'primereact/inputtext';
|
||||||
import { Button } from 'primereact/button';
|
import { Button } from 'primereact/button';
|
||||||
import { DataTable } from 'primereact/datatable';
|
import { DataTable } from 'primereact/datatable';
|
||||||
import { Column } from 'primereact/column';
|
import { Column } from 'primereact/column';
|
||||||
import { Dropdown } from 'primereact/dropdown';
|
import { Dropdown } from 'primereact/dropdown';
|
||||||
|
import { Toast } from 'primereact/toast';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
|
|
||||||
const Communities = () => {
|
const Communities = () => {
|
||||||
|
|
||||||
|
let emptyCommunity = {
|
||||||
|
name: '',
|
||||||
|
province: provinciaId,
|
||||||
|
canton: cantonId,
|
||||||
|
district: districtId,
|
||||||
|
phone: '',
|
||||||
|
num_houses: 0,
|
||||||
|
status: 'activo',
|
||||||
|
date_entry: new Date(),
|
||||||
|
houses: [],
|
||||||
|
quote: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const [communitiesList, setCommunitiesList] = useState([]);
|
const [communitiesList, setCommunitiesList] = useState([]);
|
||||||
|
const [community, setCommunity] = useState(emptyCommunity);
|
||||||
|
|
||||||
const [housesList, setHousesList] = useState([]);
|
const [housesList, setHousesList] = useState([]);
|
||||||
const [provincesList, setProvincesList] = useState([]);
|
const [provincesList, setProvincesList] = useState([]);
|
||||||
const [provinciaId, setProvinciaId] = useState();
|
const [provinciaId, setProvinciaId] = useState(null);
|
||||||
const [cantonsList, setCantonsList] = useState([]);
|
const [cantonsList, setCantonsList] = useState([]);
|
||||||
const [cantonId, setCantonId] = useState(null);
|
const [cantonId, setCantonId] = useState(null);
|
||||||
const [districtsList, setDistrictsList] = useState([]);
|
const [districtsList, setDistrictsList] = useState([]);
|
||||||
const [districtId, setDistrictId] = useState(null);
|
const [districtId, setDistrictId] = useState(null);
|
||||||
|
const [submitted, setSubmitted] = useState(false);
|
||||||
|
const toast = useRef(null);
|
||||||
|
const dt = useRef(null);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const p = provincesList.map((item) => ({
|
const p = provincesList.map((item) => ({
|
||||||
label: item.name,
|
label: item.name,
|
||||||
|
@ -35,36 +59,56 @@ const Communities = () => {
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
||||||
async function getCommunites() {
|
|
||||||
let response = await fetch('http://localhost:4000/community/allCommunities', { method: 'GET' });
|
|
||||||
let list = await response.json();
|
|
||||||
setCommunitiesList(list.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getCommunites();
|
fillProvinces();
|
||||||
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getProvinces();
|
fillCantons();
|
||||||
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
getCantons();
|
|
||||||
}, [provinciaId])
|
}, [provinciaId])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getDistricts();
|
fillDistricts();
|
||||||
}, [cantonId])
|
}, [cantonId])
|
||||||
|
|
||||||
|
|
||||||
async function getProvinces() {
|
async function getProvinces() {
|
||||||
const response = await fetch('assets/demo/data/provincias.json', { method: 'GET' });
|
const response = await fetch('assets/demo/data/provincias.json', { method: 'GET' });
|
||||||
const getP = await response.json();
|
return await response.json();
|
||||||
setProvincesList(await getP)
|
}
|
||||||
|
|
||||||
|
async function fillProvinces() {
|
||||||
|
const getP = await getProvinces();
|
||||||
|
setProvincesList(await getP);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getCantons() {
|
||||||
|
const response = await fetch('assets/demo/data/cantones.json', { method: 'GET' });
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fillCantons() {
|
||||||
|
const resJson = await getCantons();
|
||||||
|
const cantones = await resJson.filter(function (i, n) {
|
||||||
|
return i.parentCode === provinciaId;
|
||||||
|
});
|
||||||
|
setCantonsList(await cantones);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getDistricts() {
|
||||||
|
const response = await fetch('assets/demo/data/distritos.json', { method: 'GET' });
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fillDistricts() {
|
||||||
|
const resJson = await getDistricts();
|
||||||
|
const cantones = await resJson.filter(function (i, n) {
|
||||||
|
return i.parentCode === provinciaId;
|
||||||
|
});
|
||||||
|
setCantonsList(await cantones);
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleProvinces = (event) => {
|
const handleProvinces = (event) => {
|
||||||
|
@ -72,36 +116,106 @@ const Communities = () => {
|
||||||
setProvinciaId(getprovinciaId);
|
setProvinciaId(getprovinciaId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function getCantons() {
|
|
||||||
const response = await fetch('assets/demo/data/cantones.json', { method: 'GET' });
|
|
||||||
const resJson = await response.json();
|
|
||||||
const cantones = await resJson.filter(function (i, n) {
|
|
||||||
return i.parentCode === provinciaId;
|
|
||||||
});
|
|
||||||
setCantonsList(await cantones);
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleCanton = (event) => {
|
const handleCanton = (event) => {
|
||||||
const getCantonId = event.target.value;
|
const getCantonId = event.target.value;
|
||||||
setCantonId(getCantonId);
|
setCantonId(getCantonId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getDistricts() {
|
const handleDistrict = (event) => {
|
||||||
const response = await fetch('assets/demo/data/distritos.json', { method: 'GET' });
|
const getDistrictId = event.target.value;
|
||||||
const resJson = await response.json();
|
setDistrictId(getDistrictId);
|
||||||
const distrits = await resJson.filter(function (i, n) {
|
|
||||||
return i.parentCode === cantonId;
|
|
||||||
});
|
|
||||||
setDistrictsList(await distrits);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getCommunites() {
|
||||||
|
let response = await fetch('http://localhost:4000/community/allCommunities', { method: 'GET' });
|
||||||
|
let resJson = await response.json();
|
||||||
|
let pList = await getProvinces();
|
||||||
|
let cList = await getCantons();
|
||||||
|
let dList = await getDistricts();
|
||||||
|
await resJson.message.map((item) => {
|
||||||
|
item.province = pList.find(p => p.code === item.province).name
|
||||||
|
item.canton = cList.find(p => p.code === item.canton).name
|
||||||
|
item.district = dList.find(p => p.code === item.district).name
|
||||||
|
})
|
||||||
|
setCommunitiesList(await resJson.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getCommunites();
|
||||||
|
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
|
const saveCommunity = () => {
|
||||||
|
setSubmitted(true);
|
||||||
|
|
||||||
|
if (community.name.trim()) {
|
||||||
|
let _communities = [...communitiesList];
|
||||||
|
let _community = { ...community };
|
||||||
|
_community.province = provinciaId;
|
||||||
|
_community.canton = cantonId;
|
||||||
|
_community.district = districtId;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (let i = 0; i < _community.num_houses; i++){
|
||||||
|
_community.houses.push({
|
||||||
|
number_house: i+1,
|
||||||
|
description: "es esta descripcion",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_communities.push(_community);
|
||||||
|
toast.current.show({ severity: 'success', summary: 'Successful', detail: 'Community Created', life: 3000 });
|
||||||
|
|
||||||
|
setCommunitiesList(_communities);
|
||||||
|
|
||||||
|
setProvinciaId('');
|
||||||
|
setCantonId('');
|
||||||
|
setDistrictId('');
|
||||||
|
setCommunity(emptyCommunity);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// console.log(houses)
|
||||||
|
fetch('http://localhost:4000/community/createCommunity', {
|
||||||
|
cache: 'no-cache',
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(_community),
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.catch(
|
||||||
|
err => console.log('Ocurrió un error con el fetch', err)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const onInputChange = (e, name) => {
|
||||||
|
const val = (e.target && e.target.value) || '';
|
||||||
|
let _community = { ...community };
|
||||||
|
_community[`${name}`] = val;
|
||||||
|
|
||||||
|
setCommunity(_community);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="grid">
|
<div className="grid">
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
<div className="card">
|
<div className="card">
|
||||||
<h5>Comunidades de Viviendas</h5>
|
<h5>Comunidades de Viviendas</h5>
|
||||||
|
|
||||||
<DataTable value={communitiesList} scrollable scrollHeight="400px" scrollDirection="both" className="mt-3">
|
<DataTable value={communitiesList} scrollable scrollHeight="400px" scrollDirection="both" className="mt-3">
|
||||||
<Column field="name" header="Nombre" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
<Column field="name" header="Nombre" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
||||||
<Column field="province" header="Provincia" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
<Column field="province" header="Provincia" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
||||||
|
@ -116,81 +230,84 @@ const Communities = () => {
|
||||||
</div>
|
</div>
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
<div className="card">
|
<div className="card">
|
||||||
|
<Toast ref={toast} />
|
||||||
|
|
||||||
<h5>Registro de comunidad de viviendas</h5>
|
<h5>Registro de comunidad de viviendas</h5>
|
||||||
<div className="p-fluid formgrid grid">
|
<div className="p-fluid formgrid grid">
|
||||||
<div className="field col-12 md:col-6">
|
<div className="field col-12 md:col-6">
|
||||||
<label htmlFor="name">Nombre</label>
|
<label htmlFor="name">Nombre</label>
|
||||||
<div className="p-0 col-12 md:col-12">
|
<div className="p-0 col-12 md:col-12">
|
||||||
<div className="p-inputgroup">
|
<div className="p-inputgroup">
|
||||||
<span className="p-inputgroup-addon p-button p-icon-input">
|
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||||
<i className="pi pi-home"></i>
|
<i className="pi pi-home"></i>
|
||||||
</span>
|
</span>
|
||||||
<InputText id="name" type="text" />
|
<InputText id="name" value={community.name} onChange={(e) => onInputChange(e, 'name')} required autoFocus className={classNames({ 'p-invalid': submitted && !community.name } )} />
|
||||||
</div>
|
</div>
|
||||||
|
{submitted && community.name==='' && <small className="p-invalid">Nombre es requirido.</small>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="field col-12 md:col-6">
|
<div className="field col-12 md:col-6">
|
||||||
<label htmlFor="districts">Provincia</label>
|
<label htmlFor="provinces">Provincia</label>
|
||||||
<div className="p-0 col-12 md:col-12">
|
<div className="p-0 col-12 md:col-12">
|
||||||
<div className="p-inputgroup">
|
<div className="p-inputgroup">
|
||||||
<span className="p-inputgroup-addon p-button p-icon-input">
|
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||||
<i className="pi pi-map-marker"></i>
|
<i className="pi pi-map-marker"></i>
|
||||||
</span>
|
</span>
|
||||||
<Dropdown placeholder="--Seleccione Provincia--" value={provinciaId} options={p} onChange={handleProvinces} />
|
<Dropdown placeholder="--Seleccione Provincia--" value={provinciaId} options={p} onChange={handleProvinces} required autoFocus className={classNames({ 'p-invalid': submitted && !community.province } )} />
|
||||||
</div>
|
</div>
|
||||||
|
{submitted && !community.province && <small className="p-invalid">Provincia es requirido.</small>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="field col-12 md:col-6">
|
<div className="field col-12 md:col-6">
|
||||||
<label htmlFor="cantons">Cantón</label>
|
<label htmlFor="cantons">Cantón</label>
|
||||||
<div className="p-0 col-12 md:col-12">
|
<div className="p-0 col-12 md:col-12">
|
||||||
<div className="p-inputgroup">
|
<div className="p-inputgroup">
|
||||||
<span className="p-inputgroup-addon p-button p-icon-input">
|
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||||
<i className="pi pi-map-marker"></i>
|
<i className="pi pi-map-marker"></i>
|
||||||
</span>
|
</span>
|
||||||
<Dropdown placeholder="--Seleccione Cantón--" value={cantonId} options={c} onChange={handleCanton} />
|
<Dropdown placeholder="--Seleccione Cantón--" value={cantonId} options={c} onChange={handleCanton} required autoFocus className={classNames({ 'p-invalid': submitted && !community.canton } )}/>
|
||||||
</div>
|
</div>
|
||||||
|
{submitted && !community.canton && <small className="p-invalid">Cantón es requirido.</small>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="field col-12 md:col-6">
|
<div className="field col-12 md:col-6">
|
||||||
<label htmlFor="districts">Distrito</label>
|
<label htmlFor="districts">Distrito</label>
|
||||||
<div className="p-0 col-12 md:col-12">
|
<div className="p-0 col-12 md:col-12">
|
||||||
<div className="p-inputgroup">
|
<div className="p-inputgroup">
|
||||||
<span className="p-inputgroup-addon p-button p-icon-input">
|
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||||
<i className="pi pi-map-marker"></i>
|
<i className="pi pi-map-marker"></i>
|
||||||
</span>
|
</span>
|
||||||
<Dropdown placeholder="--Seleccione Distrito--" value={districtId} options={d} />
|
<Dropdown placeholder="--Seleccione Distrito--" value={districtId} options={d} onChange={handleDistrict} required autoFocus className={classNames({ 'p-invalid': submitted && !community.district } )}/>
|
||||||
</div>
|
</div>
|
||||||
|
{submitted && !community.district && <small className="p-invalid">Distrito es requirido.</small>}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="field col-12 md:col-6">
|
<div className="field col-12 md:col-6">
|
||||||
<label htmlFor="telefono">Teléfono</label>
|
<label htmlFor="telefono">Número de Teléfono</label>
|
||||||
<div className="p-0 col-12 md:col-12">
|
<div className="p-0 col-12 md:col-12">
|
||||||
<div className="p-inputgroup">
|
<div className="p-inputgroup">
|
||||||
<span className="p-inputgroup-addon p-button p-icon-input">
|
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||||
<i className="pi pi-phone"></i>
|
<i className="pi pi-phone"></i>
|
||||||
</span>
|
</span>
|
||||||
<InputText id="telefono" type="text" rows="4" />
|
<InputText id="phone" value={community.phone} onChange={(e) => onInputChange(e, 'phone')} required autoFocus className={classNames({ 'p-invalid': submitted && !community.phone } )} />
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
{submitted && community.phone==='' && <small className="p-invalid">Número de teléfono es requirido.</small>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="field col-12 md:col-6">
|
<div className="field col-12 md:col-6">
|
||||||
<label htmlFor="numHouse">Numero de Viviendas</label>
|
<label htmlFor="numHouse">Numero de Viviendas</label>
|
||||||
<div className="p-0 col-12 md:col-12">
|
<div className="p-0 col-12 md:col-12">
|
||||||
<div className="p-inputgroup">
|
<div className="p-inputgroup">
|
||||||
<span className="p-inputgroup-addon p-button p-icon-input">
|
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||||
<i className="pi pi-hashtag"></i>
|
<i className="pi pi-hashtag"></i>
|
||||||
</span>
|
</span>
|
||||||
<InputText id="num" type="number" rows="4" />
|
<InputText id="num_houses" value={community.num_houses} onChange={(e) => onInputChange(e, 'num_houses')} required autoFocus className={classNames({ 'p-invalid': submitted && community.num_houses < 1 } )} />
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
{submitted && community.num_houses < 1 && <small className="p-invalid">Número de viviendas es requirido y debe ser mayor que 0.</small>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-12 md:col-12 py-2">
|
<div className="col-12 md:col-12 py-2">
|
||||||
<Button label="Registrar" icon="pi pi-check"></Button>
|
<Button label="Registrar" icon="pi pi-check" onClick={saveCommunity}></Button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue