Merge pull request #115 from DeimosPr4/UH-registroComunidadVivienda
registroComunidadVivienda
This commit is contained in:
commit
b8492a2ea7
|
@ -78,16 +78,15 @@ export class AppController {
|
|||
@Body('canton') canton: string,
|
||||
@Body('district') district: string,
|
||||
@Body('num_houses') num_houses: number,
|
||||
@Body('phone') phone: number,
|
||||
@Body('quote') quote: number,
|
||||
@Body('phone') phone: string,
|
||||
@Body('status') status: string,
|
||||
@Body('date_entry') date_entry: Date,
|
||||
@Body('houses') houses: [{}],
|
||||
@Body('houses') houses: [],
|
||||
|
||||
) {
|
||||
return this.appService.createCommunity(name, province, canton,
|
||||
district, num_houses, phone,
|
||||
quote, status, date_entry, houses);
|
||||
status, date_entry, houses);
|
||||
}
|
||||
|
||||
@Get('community/allCommunities')
|
||||
|
|
|
@ -131,11 +131,11 @@ export class AppService {
|
|||
|
||||
//POST parameter from API
|
||||
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, status: string, date_entry: Date, houses: []) {
|
||||
const pattern = { cmd: 'createCommunity' };
|
||||
const payload = {
|
||||
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, status: status, date_entry: date_entry, houses: houses
|
||||
};
|
||||
return this.clientCommunityApp
|
||||
.send<string>(pattern, payload)
|
||||
|
|
|
@ -30,6 +30,7 @@ export class CommunitiesService {
|
|||
.then(async community => {
|
||||
if (community) {
|
||||
await Promise.all(community.map(async c => {
|
||||
//buscar al usuario con el id de la comunidad anexado
|
||||
let admin = await this.findCommunityAdmin(c["_id"], "2")
|
||||
if (admin) {
|
||||
c["id_admin"] = admin["_id"]
|
||||
|
@ -37,14 +38,9 @@ export class CommunitiesService {
|
|||
}
|
||||
return c
|
||||
}))
|
||||
|
||||
console.log(community)
|
||||
}
|
||||
|
||||
return community;
|
||||
})
|
||||
|
||||
//buscar al usuario con el id de la comunidad anexado
|
||||
}
|
||||
|
||||
findOne(id: string): Promise<Community> {
|
||||
|
|
|
@ -10,7 +10,7 @@ export class Community {
|
|||
@Prop()
|
||||
id_admin: string;
|
||||
|
||||
@Prop({ default: "Sin Administrador" })
|
||||
@Prop()
|
||||
name_admin: string ;
|
||||
|
||||
@Prop()
|
||||
|
@ -29,10 +29,7 @@ export class Community {
|
|||
num_houses: number;
|
||||
|
||||
@Prop()
|
||||
phone: number;
|
||||
|
||||
@Prop()
|
||||
quote: number;
|
||||
phone: string;
|
||||
|
||||
@Prop()
|
||||
status: string;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
|
||||
import e from 'express';
|
||||
import { Document } from 'mongoose';
|
||||
import { empty } from 'rxjs';
|
||||
import { Tenant, TenantSchema } from './tenant.schema';
|
||||
|
||||
|
||||
|
@ -9,13 +11,10 @@ export class House extends Document {
|
|||
@Prop({ default: " " })
|
||||
number_house: string;
|
||||
|
||||
@Prop({ default: " " })
|
||||
description: string;
|
||||
|
||||
@Prop({ default: "desocupada" })
|
||||
state: string;
|
||||
|
||||
@Prop({ type: TenantSchema, default: " " })
|
||||
@Prop({ type: TenantSchema })
|
||||
tenants: Tenant;
|
||||
}
|
||||
export const HouseSchema = SchemaFactory.createForClass(House);
|
|
@ -4,7 +4,7 @@ import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
|
|||
|
||||
@Schema()
|
||||
export class Tenant {
|
||||
@Prop()
|
||||
@Prop( {default: ''})
|
||||
tenant_id: string;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,489 @@
|
|||
[
|
||||
{
|
||||
"name": "San José",
|
||||
"code": "101",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Escazú",
|
||||
"code": "102",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Desamparados",
|
||||
"code": "103",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Puriscal",
|
||||
"code": "104",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Tarrazú",
|
||||
"code": "105",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Aserrí",
|
||||
"code": "106",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Mora",
|
||||
"code": "107",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Goicoechea",
|
||||
"code": "108",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Santa Ana",
|
||||
"code": "109",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Alajuelita",
|
||||
"code": "110",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Vasquez de Coronado",
|
||||
"code": "111",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Acosta",
|
||||
"code": "112",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Tibás",
|
||||
"code": "113",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Moravia",
|
||||
"code": "114",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Montes de Oca",
|
||||
"code": "115",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Turrubares",
|
||||
"code": "116",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Dota",
|
||||
"code": "117",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Curridabat",
|
||||
"code": "118",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Pérez Zeledón",
|
||||
"code": "119",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "León Cortés",
|
||||
"code": "120",
|
||||
"parentCode": "1",
|
||||
"isoParent": "SJ"
|
||||
},
|
||||
{
|
||||
"name": "Alajuela",
|
||||
"code": "201",
|
||||
"parentCode": "2",
|
||||
"isoParent": "ALAJ"
|
||||
},
|
||||
{
|
||||
"name": "San Ramón",
|
||||
"code": "202",
|
||||
"parentCode": "2",
|
||||
"isoParent": "ALAJ"
|
||||
},
|
||||
{
|
||||
"name": "Grecia",
|
||||
"code": "203",
|
||||
"parentCode": "2",
|
||||
"isoParent": "ALAJ"
|
||||
},
|
||||
{
|
||||
"name": "San Mateo",
|
||||
"code": "204",
|
||||
"parentCode": "2",
|
||||
"isoParent": "ALAJ"
|
||||
},
|
||||
{
|
||||
"name": "Atenas",
|
||||
"code": "205",
|
||||
"parentCode": "2",
|
||||
"isoParent": "ALAJ"
|
||||
},
|
||||
{
|
||||
"name": "Naranjo",
|
||||
"code": "206",
|
||||
"parentCode": "2",
|
||||
"isoParent": "ALAJ"
|
||||
},
|
||||
{
|
||||
"name": "Palmares",
|
||||
"code": "207",
|
||||
"parentCode": "2",
|
||||
"isoParent": "ALAJ"
|
||||
},
|
||||
{
|
||||
"name": "Poás",
|
||||
"code": "208",
|
||||
"parentCode": "2",
|
||||
"isoParent": "ALAJ"
|
||||
},
|
||||
{
|
||||
"name": "Orotina",
|
||||
"code": "209",
|
||||
"parentCode": "2",
|
||||
"isoParent": "ALAJ"
|
||||
},
|
||||
{
|
||||
"name": "San Carlos",
|
||||
"code": "210",
|
||||
"parentCode": "2",
|
||||
"isoParent": "ALAJ"
|
||||
},
|
||||
{
|
||||
"name": "Alfaro Ruiz",
|
||||
"code": "211",
|
||||
"parentCode": "2",
|
||||
"isoParent": "ALAJ"
|
||||
},
|
||||
{
|
||||
"name": "Valverde Vega",
|
||||
"code": "212",
|
||||
"parentCode": "2",
|
||||
"isoParent": "ALAJ"
|
||||
},
|
||||
{
|
||||
"name": "Upala",
|
||||
"code": "213",
|
||||
"parentCode": "2",
|
||||
"isoParent": "ALAJ"
|
||||
},
|
||||
{
|
||||
"name": "Los Chiles",
|
||||
"code": "214",
|
||||
"parentCode": "2",
|
||||
"isoParent": "ALAJ"
|
||||
},
|
||||
{
|
||||
"name": "Guatuso",
|
||||
"code": "215",
|
||||
"parentCode": "2",
|
||||
"isoParent": "ALAJ"
|
||||
},
|
||||
{
|
||||
"name": "Cartago",
|
||||
"code": "301",
|
||||
"parentCode": "3",
|
||||
"isoParent": "CAR"
|
||||
},
|
||||
{
|
||||
"name": "Paraíso",
|
||||
"code": "302",
|
||||
"parentCode": "3",
|
||||
"isoParent": "CAR"
|
||||
},
|
||||
{
|
||||
"name": "La Unión",
|
||||
"code": "303",
|
||||
"parentCode": "3",
|
||||
"isoParent": "CAR"
|
||||
},
|
||||
{
|
||||
"name": "Jiménez",
|
||||
"code": "304",
|
||||
"parentCode": "3",
|
||||
"isoParent": "CAR"
|
||||
},
|
||||
{
|
||||
"name": "Turrialba",
|
||||
"code": "305",
|
||||
"parentCode": "3",
|
||||
"isoParent": "CAR"
|
||||
},
|
||||
{
|
||||
"name": "Alvarado",
|
||||
"code": "306",
|
||||
"parentCode": "3",
|
||||
"isoParent": "CAR"
|
||||
},
|
||||
{
|
||||
"name": "Oreamuno",
|
||||
"code": "307",
|
||||
"parentCode": "3",
|
||||
"isoParent": "CAR"
|
||||
},
|
||||
{
|
||||
"name": "El Guarco",
|
||||
"code": "308",
|
||||
"parentCode": "3",
|
||||
"isoParent": "CAR"
|
||||
},
|
||||
{
|
||||
"name": "Heredia",
|
||||
"code": "401",
|
||||
"parentCode": "4",
|
||||
"isoParent": "HER"
|
||||
},
|
||||
{
|
||||
"name": "Barva",
|
||||
"code": "402",
|
||||
"parentCode": "4",
|
||||
"isoParent": "HER"
|
||||
},
|
||||
{
|
||||
"name": "Santo Domingo",
|
||||
"code": "403",
|
||||
"parentCode": "4",
|
||||
"isoParent": "HER"
|
||||
},
|
||||
{
|
||||
"name": "Santa Bárbara",
|
||||
"code": "404",
|
||||
"parentCode": "4",
|
||||
"isoParent": "HER"
|
||||
},
|
||||
{
|
||||
"name": "San Rafael",
|
||||
"code": "405",
|
||||
"parentCode": "4",
|
||||
"isoParent": "HER"
|
||||
},
|
||||
{
|
||||
"name": "San Isidro",
|
||||
"code": "406",
|
||||
"parentCode": "4",
|
||||
"isoParent": "HER"
|
||||
},
|
||||
{
|
||||
"name": "Belén",
|
||||
"code": "407",
|
||||
"parentCode": "4",
|
||||
"isoParent": "HER"
|
||||
},
|
||||
{
|
||||
"name": "Flores",
|
||||
"code": "408",
|
||||
"parentCode": "4",
|
||||
"isoParent": "HER"
|
||||
},
|
||||
{
|
||||
"name": "San Pablo",
|
||||
"code": "409",
|
||||
"parentCode": "4",
|
||||
"isoParent": "HER"
|
||||
},
|
||||
{
|
||||
"name": "Sarapiquí ",
|
||||
"code": "410",
|
||||
"parentCode": "4",
|
||||
"isoParent": "HER"
|
||||
},
|
||||
{
|
||||
"name": "Liberia",
|
||||
"code": "501",
|
||||
"parentCode": "5",
|
||||
"isoParent": "GUANA"
|
||||
},
|
||||
{
|
||||
"name": "Nicoya",
|
||||
"code": "502",
|
||||
"parentCode": "5",
|
||||
"isoParent": "GUANA"
|
||||
},
|
||||
{
|
||||
"name": "Santa Cruz",
|
||||
"code": "503",
|
||||
"parentCode": "5",
|
||||
"isoParent": "GUANA"
|
||||
},
|
||||
{
|
||||
"name": "Bagaces",
|
||||
"code": "504",
|
||||
"parentCode": "5",
|
||||
"isoParent": "GUANA"
|
||||
},
|
||||
{
|
||||
"name": "Carrillo",
|
||||
"code": "505",
|
||||
"parentCode": "5",
|
||||
"isoParent": "GUANA"
|
||||
},
|
||||
{
|
||||
"name": "Cañas",
|
||||
"code": "506",
|
||||
"parentCode": "5",
|
||||
"isoParent": "GUANA"
|
||||
},
|
||||
{
|
||||
"name": "Abangares",
|
||||
"code": "507",
|
||||
"parentCode": "5",
|
||||
"isoParent": "GUANA"
|
||||
},
|
||||
{
|
||||
"name": "Tilarán",
|
||||
"code": "508",
|
||||
"parentCode": "5",
|
||||
"isoParent": "GUANA"
|
||||
},
|
||||
{
|
||||
"name": "Nandayure",
|
||||
"code": "509",
|
||||
"parentCode": "5",
|
||||
"isoParent": "GUANA"
|
||||
},
|
||||
{
|
||||
"name": "La Cruz",
|
||||
"code": "510",
|
||||
"parentCode": "5",
|
||||
"isoParent": "GUANA"
|
||||
},
|
||||
{
|
||||
"name": "Hojancha",
|
||||
"code": "511",
|
||||
"parentCode": "5",
|
||||
"isoParent": "GUANA"
|
||||
},
|
||||
{
|
||||
"name": "Puntarenas",
|
||||
"code": "601",
|
||||
"parentCode": "6",
|
||||
"isoParent": "PUNT"
|
||||
},
|
||||
{
|
||||
"name": "Esparza",
|
||||
"code": "602",
|
||||
"parentCode": "6",
|
||||
"isoParent": "PUNT"
|
||||
},
|
||||
{
|
||||
"name": "Buenos Aires",
|
||||
"code": "603",
|
||||
"parentCode": "6",
|
||||
"isoParent": "PUNT"
|
||||
},
|
||||
{
|
||||
"name": "Montes de Oro",
|
||||
"code": "604",
|
||||
"parentCode": "6",
|
||||
"isoParent": "PUNT"
|
||||
},
|
||||
{
|
||||
"name": "Osa",
|
||||
"code": "605",
|
||||
"parentCode": "6",
|
||||
"isoParent": "PUNT"
|
||||
},
|
||||
{
|
||||
"name": "Aguirre",
|
||||
"code": "606",
|
||||
"parentCode": "6",
|
||||
"isoParent": "PUNT"
|
||||
},
|
||||
{
|
||||
"name": "Golfito",
|
||||
"code": "607",
|
||||
"parentCode": "6",
|
||||
"isoParent": "PUNT"
|
||||
},
|
||||
{
|
||||
"name": "Coto Brus",
|
||||
"code": "608",
|
||||
"parentCode": "6",
|
||||
"isoParent": "PUNT"
|
||||
},
|
||||
{
|
||||
"name": "Parrita",
|
||||
"code": "609",
|
||||
"parentCode": "6",
|
||||
"isoParent": "PUNT"
|
||||
},
|
||||
{
|
||||
"name": "Corredores",
|
||||
"code": "610",
|
||||
"parentCode": "6",
|
||||
"isoParent": "PUNT"
|
||||
},
|
||||
{
|
||||
"name": "Garabito",
|
||||
"code": "611",
|
||||
"parentCode": "6",
|
||||
"isoParent": "PUNT"
|
||||
},
|
||||
{
|
||||
"name": "Limón",
|
||||
"code": "701",
|
||||
"parentCode": "7",
|
||||
"isoParent": "LIM"
|
||||
},
|
||||
{
|
||||
"name": "Pococí",
|
||||
"code": "702",
|
||||
"parentCode": "7",
|
||||
"isoParent": "LIM"
|
||||
},
|
||||
{
|
||||
"name": "Siquirres ",
|
||||
"code": "703",
|
||||
"parentCode": "7",
|
||||
"isoParent": "LIM"
|
||||
},
|
||||
{
|
||||
"name": "Talamanca",
|
||||
"code": "704",
|
||||
"parentCode": "7",
|
||||
"isoParent": "LIM"
|
||||
},
|
||||
{
|
||||
"name": "Matina",
|
||||
"code": "705",
|
||||
"parentCode": "7",
|
||||
"isoParent": "LIM"
|
||||
},
|
||||
{
|
||||
"name": "Guácimo",
|
||||
"code": "706",
|
||||
"parentCode": "7",
|
||||
"isoParent": "LIM"
|
||||
}
|
||||
]
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,30 @@
|
|||
[
|
||||
{
|
||||
"name":"San José",
|
||||
"code":"1"
|
||||
},
|
||||
{
|
||||
"name":"Alajuela",
|
||||
"code":"2"
|
||||
},
|
||||
{
|
||||
"name":"Cartago",
|
||||
"code":"3"
|
||||
},
|
||||
{
|
||||
"name":"Heredia",
|
||||
"code":"4"
|
||||
},
|
||||
{
|
||||
"name":"Guanacaste",
|
||||
"code":"5"
|
||||
},
|
||||
{
|
||||
"name":"Puntarenas",
|
||||
"code":"6"
|
||||
},
|
||||
{
|
||||
"name":"Limón",
|
||||
"code":"7"
|
||||
}
|
||||
]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -9,7 +9,7 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<link rel="icon" type="image/x-icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<link id="theme-link" rel="stylesheet" href="%PUBLIC_URL%/assets/themes/lara-light-indigo/theme.css">
|
||||
<link id="theme-link" rel="stylesheet" href="%PUBLIC_URL%/assets/themes/khaki/theme.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
|
@ -9,7 +9,7 @@ export const AppConfig = (props) => {
|
|||
const [active, setActive] = useState(false);
|
||||
const [scale, setScale] = useState(14);
|
||||
const [scales] = useState([12, 13, 14, 15, 16]);
|
||||
const [theme, setTheme] = useState('lara-light-indigo');
|
||||
const [theme, setTheme] = useState('khaki');
|
||||
const config = useRef(null);
|
||||
let outsideClickListener = useRef(null);
|
||||
|
||||
|
@ -187,6 +187,11 @@ export const AppConfig = (props) => {
|
|||
|
||||
<h6>Material Design</h6>
|
||||
<div className="grid free-themes">
|
||||
<div className="col-3 text-center">
|
||||
<button className="p-link" onClick={e => changeTheme(e, 'md-light-indigo', 'light')}>
|
||||
<img src="assets/layout/images/themes/md-light-indigo.svg" alt="Material Light Indigo" />
|
||||
</button>
|
||||
</div>
|
||||
<div className="col-3 text-center">
|
||||
<button className="p-link" onClick={e => changeTheme(e, 'md-light-indigo', 'light')}>
|
||||
<img src="assets/layout/images/themes/md-light-indigo.svg" alt="Material Light Indigo" />
|
||||
|
@ -253,6 +258,11 @@ export const AppConfig = (props) => {
|
|||
|
||||
<h6>PrimeOne Design - 2022</h6>
|
||||
<div className="grid free-themes">
|
||||
<div className="col-3 text-center">
|
||||
<button className="p-link" onClick={(e) => changeTheme(e, 'khaki', 'light')}>
|
||||
<img src="assets/layout/images/themes/lara-light-indigo.png" alt="Khaki" />
|
||||
</button>
|
||||
</div>
|
||||
<div className="col-3 text-center">
|
||||
<button className="p-link" onClick={(e) => changeTheme(e, 'lara-light-indigo', 'light')}>
|
||||
<img src="assets/layout/images/themes/lara-light-indigo.png" alt="Lara Light Indigo" />
|
||||
|
|
|
@ -1,31 +1,234 @@
|
|||
import React, { useEffect, useState } from 'react';
|
||||
import React, { useEffect, useState, useRef } from 'react';
|
||||
import { InputText } from 'primereact/inputtext';
|
||||
import { Button } from 'primereact/button';
|
||||
import { DataTable } from 'primereact/datatable';
|
||||
import { Column } from 'primereact/column';
|
||||
import { Dropdown } from 'primereact/dropdown';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import classNames from 'classnames';
|
||||
|
||||
|
||||
const Communities = () => {
|
||||
const [communitiesList, setCommunitiesList] = useState([]);
|
||||
const [housesList, setHousesList] = useState([]);
|
||||
|
||||
let emptyCommunity = {
|
||||
name: '',
|
||||
province: provinciaId,
|
||||
canton: cantonId,
|
||||
district: districtId,
|
||||
phone: '',
|
||||
num_houses: 0,
|
||||
status: 'activo',
|
||||
date_entry: new Date(),
|
||||
houses: [],
|
||||
};
|
||||
|
||||
|
||||
const [communitiesList, setCommunitiesList] = useState([]);
|
||||
const [community, setCommunity] = useState(emptyCommunity);
|
||||
|
||||
const [housesList, setHousesList] = useState([]);
|
||||
const [provincesList, setProvincesList] = useState([]);
|
||||
const [provinciaId, setProvinciaId] = useState(null);
|
||||
const [cantonsList, setCantonsList] = useState([]);
|
||||
const [cantonId, setCantonId] = useState(null);
|
||||
const [districtsList, setDistrictsList] = useState([]);
|
||||
const [districtId, setDistrictId] = useState(null);
|
||||
const [codeHouses, setCodeHouses] = useState(null);
|
||||
const [submitted, setSubmitted] = useState(false);
|
||||
const toast = useRef(null);
|
||||
const dt = useRef(null);
|
||||
|
||||
|
||||
|
||||
const p = provincesList.map((item) => ({
|
||||
label: item.name,
|
||||
value: item.code
|
||||
}))
|
||||
|
||||
|
||||
const c = cantonsList.map((item) => ({
|
||||
label: item.name,
|
||||
value: item.code,
|
||||
parent: item.parentCode
|
||||
}))
|
||||
|
||||
const d = districtsList.map((item) => ({
|
||||
label: item.name,
|
||||
value: item.code,
|
||||
parent: item.parentCode
|
||||
}))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
fillProvinces();
|
||||
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
fillCantons();
|
||||
}, [provinciaId])
|
||||
|
||||
useEffect(() => {
|
||||
fillDistricts();
|
||||
}, [cantonId])
|
||||
|
||||
async function getProvinces() {
|
||||
const response = await fetch('assets/demo/data/provincias.json', { method: 'GET' });
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
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 districts = await resJson.filter(function (i, n) {
|
||||
return i.parentCode === cantonId;
|
||||
});
|
||||
setDistrictsList(await districts);
|
||||
}
|
||||
|
||||
const handleProvinces = (event) => {
|
||||
const getprovinciaId = event.target.value;
|
||||
setProvinciaId(getprovinciaId);
|
||||
}
|
||||
|
||||
const handleCanton = (event) => {
|
||||
const getCantonId = event.target.value;
|
||||
setCantonId(getCantonId);
|
||||
}
|
||||
|
||||
const handleDistrict = (event) => {
|
||||
const getDistrictId = event.target.value;
|
||||
setDistrictId(getDistrictId);
|
||||
}
|
||||
|
||||
|
||||
const handleCodeHouses = (event) => {
|
||||
const getcodehouse = event.target.value;
|
||||
setCodeHouses(getcodehouse);
|
||||
}
|
||||
|
||||
async function getCommunites() {
|
||||
let response = await fetch('http://localhost:4000/community/allCommunities', { method: 'GET' });
|
||||
let list = await response.json();
|
||||
setCommunitiesList(list.message);
|
||||
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: codeHouses + (i+1),
|
||||
})
|
||||
}
|
||||
// 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();
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
|
||||
_community.province = provincesList.find(p => p.code === _community.province).name
|
||||
_community.canton = cantonsList.find(p => p.code === _community.canton).name
|
||||
_community.district = districtsList.find(p => p.code === _community.district).name
|
||||
|
||||
_communities.push(_community);
|
||||
toast.current.show({ severity: 'success', summary: 'Registro exitoso', detail: 'Comunidad de vivienda Creada', life: 3000 });
|
||||
|
||||
setCommunitiesList(_communities);
|
||||
|
||||
|
||||
setProvinciaId('');
|
||||
setCantonId('');
|
||||
setDistrictId('');
|
||||
setCodeHouses('');
|
||||
|
||||
setCommunity(emptyCommunity);
|
||||
})
|
||||
.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 (
|
||||
<div className="grid">
|
||||
<div className="col-12">
|
||||
<div className="card">
|
||||
<h5>Comunidades de Viviendas</h5>
|
||||
|
||||
<DataTable value={communitiesList} scrollable scrollHeight="400px" scrollDirection="both" className="mt-3">
|
||||
<Column field="name" header="Nombre" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
||||
<Column field="province" header="Provincia" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
||||
|
@ -33,11 +236,107 @@ const Communities = () => {
|
|||
<Column field="district" header="Distrito" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
||||
<Column field="phone" header="Telefóno" style={{ flexGrow: 1, flexBasis: '180px' }}></Column>
|
||||
<Column field="num_houses" header="Número de viviendas" style={{ flexGrow: 1, flexBasis: '180px' }}></Column>
|
||||
<Column field="quote" header="Cuota mensual" style={{ flexGrow: 1, flexBasis: '180px' }}></Column>
|
||||
<Column field="name_admin" header="Administrador" style={{ flexGrow: 1, flexBasis: '180px' }}></Column>
|
||||
</DataTable>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-12">
|
||||
<div className="card">
|
||||
<Toast ref={toast} />
|
||||
|
||||
<h5>Registro de comunidad de viviendas</h5>
|
||||
<div className="p-fluid formgrid grid">
|
||||
<div className="field col-12 md:col-12">
|
||||
<label htmlFor="name">Nombre</label>
|
||||
<div className="p-0 col-12 md:col-12">
|
||||
<div className="p-inputgroup">
|
||||
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||
<i className="pi pi-home"></i>
|
||||
</span>
|
||||
<InputText id="name" value={community.name} onChange={(e) => onInputChange(e, 'name')} required autoFocus className={classNames( submitted && community.name==='' ? 'p-invalid' : '' )} />
|
||||
</div>
|
||||
{submitted && community.name==='' && <small className="p-invalid">Nombre es requirido.</small>}
|
||||
</div>
|
||||
</div>
|
||||
<div className="field col-12 md:col-6">
|
||||
<label htmlFor="provinces">Provincia</label>
|
||||
<div className="p-0 col-12 md:col-12">
|
||||
<div className="p-inputgroup">
|
||||
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||
<i className="pi pi-map-marker"></i>
|
||||
</span>
|
||||
<Dropdown placeholder="--Seleccione Provincia--" value={provinciaId} options={p} onChange={handleProvinces} required autoFocus className={classNames({ 'p-invalid': submitted && !provinciaId } )} />
|
||||
</div>
|
||||
{submitted && !provinciaId && <small className="p-invalid">Provincia es requirido.</small>}
|
||||
</div>
|
||||
</div>
|
||||
<div className="field col-12 md:col-6">
|
||||
<label htmlFor="cantons">Cantón</label>
|
||||
<div className="p-0 col-12 md:col-12">
|
||||
<div className="p-inputgroup">
|
||||
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||
<i className="pi pi-map-marker"></i>
|
||||
</span>
|
||||
<Dropdown placeholder="--Seleccione Cantón--" value={cantonId} options={c} onChange={handleCanton} required autoFocus className={classNames({ 'p-invalid': submitted && !cantonId } )}/>
|
||||
</div>
|
||||
{submitted && !cantonId && <small className="p-invalid">Cantón es requirido.</small>}
|
||||
</div>
|
||||
</div>
|
||||
<div className="field col-12 md:col-6">
|
||||
<label htmlFor="districts">Distrito</label>
|
||||
<div className="p-0 col-12 md:col-12">
|
||||
<div className="p-inputgroup">
|
||||
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||
<i className="pi pi-map-marker"></i>
|
||||
</span>
|
||||
<Dropdown placeholder="--Seleccione Distrito--" value={districtId} options={d} onChange={handleDistrict} required autoFocus className={classNames({ 'p-invalid': submitted && !districtId } )}/>
|
||||
</div>
|
||||
{submitted && !districtId && <small className="p-invalid">Distrito es requirido.</small>}
|
||||
</div>
|
||||
</div>
|
||||
<div className="field col-12 md:col-6">
|
||||
<label htmlFor="telefono">Número de Teléfono</label>
|
||||
<div className="p-0 col-12 md:col-12">
|
||||
<div className="p-inputgroup">
|
||||
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||
<i className="pi pi-phone"></i>
|
||||
</span>
|
||||
<InputText id="phone" value={community.phone} onChange={(e) => onInputChange(e, 'phone')} required autoFocus className={classNames({ 'p-invalid': submitted && community.phone==='' } )} />
|
||||
</div>
|
||||
{submitted && community.phone==='' && <small className="p-invalid">Número de teléfono es requirido.</small>}
|
||||
</div>
|
||||
</div>
|
||||
<div className="field col-12 md:col-6">
|
||||
<label htmlFor="numHouse">Numero de Viviendas</label>
|
||||
<div className="p-0 col-12 md:col-12">
|
||||
<div className="p-inputgroup">
|
||||
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||
<i className="pi pi-hashtag"></i>
|
||||
</span>
|
||||
<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>
|
||||
{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 className="field col-12 md:col-6">
|
||||
<label htmlFor="numHouse">Ingrese el prefijo para el código de las viviendas</label>
|
||||
<div className="p-0 col-12 md:col-12">
|
||||
<div className="p-inputgroup">
|
||||
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||
<i className="pi pi-hashtag"></i>
|
||||
</span>
|
||||
<InputText id="code_houses" value={codeHouses} onChange={handleCodeHouses} required autoFocus className={classNames({ 'p-invalid': submitted && !codeHouses } )} />
|
||||
</div>
|
||||
{submitted && !codeHouses && <small className="p-invalid">El código para las viviendas es requirido.</small>}
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-12 md:col-12 py-2">
|
||||
<Button label="Registrar" icon="pi pi-check" onClick={saveCommunity}></Button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div >
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue