From ff5c6e55ffb46cdf2db3fde8e7aae9849b1f6f74 Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 16 Aug 2022 16:36:06 -0600 Subject: [PATCH 01/39] agregar numero de vivienda a inquilino --- api-gateway/src/app.controller.ts | 8 +++++ api-gateway/src/app.service.ts | 19 +++++++++++ servicio-usuarios/src/users/users.service.ts | 18 +++++++++- web-ui/web-react/src/components/Inquilinos.js | 33 ++++++++++++++++--- 4 files changed, 73 insertions(+), 5 deletions(-) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index abc90be1..39e15aad 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -215,6 +215,14 @@ export class AppController { ) { return this.appService.changeStatusCommunity(pId, pStatus); } + + @Get('community/findHousesCommunity/:id') + findHousesCommunity( + @Param('id') community_id: string, + ) { + return this.appService.findHousesCommunity(community_id); + } + // #==== API Common Areas @Post('commonArea/createCommonArea') createCommonArea( diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index a5df9129..78425570 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -1,6 +1,7 @@ import { Injectable, Inject } from '@nestjs/common'; import { ClientProxy } from '@nestjs/microservices'; import { map } from 'rxjs/operators'; +import { lastValueFrom } from 'rxjs'; @Injectable() export class AppService { @@ -283,6 +284,24 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + + async findHousesCommunity(community_id: string) { + const pattern = { cmd: 'findOneCommunity' } + const payload = { _id: community_id } + + let callback = await this.clientCommunityApp + .send(pattern, payload) + .pipe( + map((response: string) => ({ response })) + ) + const finalValue = await lastValueFrom(callback); + const response = finalValue['response']; + const houses = response['houses']; + + return houses; + } + + // ====================== COMMON AREAS =============================== //POST parameter from API createCommonArea( diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 2015ef45..5f9f50b5 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -154,7 +154,6 @@ export class UsersService { }) } - async testSendMail(user: UserDocument) { let passwordEncriptada = Md5.init(user.password); user.password = passwordEncriptada; @@ -228,5 +227,22 @@ export class UsersService { new: true, }); } + + + async findHousesCommunity(community_id: string) { + const pattern = { cmd: 'findOneCommunity' } + const payload = { _id: community_id } + + let callback = await this.clientCommunityApp + .send(pattern, payload) + .pipe( + map((response: string) => ({ response })) + ) + const finalValue = await lastValueFrom(callback); + const response = finalValue['response']; + const houses = response['houses']; + + return houses; + } } diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 4325bcf5..10380a21 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -45,7 +45,8 @@ const Inquilinos = () => { const [submitted, setSubmitted] = useState(false) const toast = useRef(null) const dt = useRef(null) - + const [housesList, setHousesList] = useState([]) + const [houseId, setHouseId] = useState(null) const [cookies, setCookie] = useCookies() const [changeStatusTenantDialog, setChangeStatusTenantDialog] = useState(false) @@ -85,10 +86,27 @@ const Inquilinos = () => { setCommunitiesList(await list) } + + async function getHouses() { + let response = await fetch( + `http://localhost:4000/community/findHousesCommunity/${cookies.community_id}`, + { method: 'GET' }, + ) + .then(res => res.json()) + .then(res => console.log()) + let resList = await response.json() + let list = await resList.message + setHousesList(await list) + } + useEffect(() => { tenantsList() }, [tenantsList]) + useEffect(() => { + getHouses() + }, []) + useEffect(() => { getCommunites() }, []) @@ -98,6 +116,13 @@ const Inquilinos = () => { value: item._id, })) + const hList = housesList.map((item) => ({ + label: item.number_house, + value: item._id, + })) + + + function registrarInquilino() { let newTenant = { _id: null, @@ -613,9 +638,9 @@ const Inquilinos = () => { setCommunityId(e.value)} + value={houseId} + options={hList} + onChange={(e) => setHouseId(e.value)} /> + + )} +
From 999175a246b3202cdcc8e5d68c0e34fa4ec85e0b Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 01:12:02 -0600 Subject: [PATCH 05/39] frontend hecho --- .../src/components/AdministradoresSistema.js | 220 +++++++++++++----- 1 file changed, 161 insertions(+), 59 deletions(-) diff --git a/web-ui/web-react/src/components/AdministradoresSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js index b47ce821..890d1ebe 100644 --- a/web-ui/web-react/src/components/AdministradoresSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -70,46 +70,73 @@ const AdministradoresSistema = () => { fetchP(); }, []) - function registrarAdmin() { - var data = { - dni: document.getElementById('identificacion').value, - name: document.getElementById('nombre').value, - last_name: document.getElementById('apellidos').value, - email: document.getElementById('correo_electronico').value, - phone: document.getElementById('telefono').value, - password: document.getElementById('correo_electronico').value, - user_type: "1", //1 es admin - status: "1" - }; - setSysAdmin(data) - - fetch('http://localhost:4000/user/createAdminSystem/', { - cache: 'no-cache', - method: 'POST', - body: JSON.stringify(data), - headers: { - 'Content-Type': 'application/json' + const findIndexById = (id) => { + let index = -1; + for (let i = 0; i < administrators.length; i++) { + if (administrators[i]._id === id) { + index = i; + break; } - }) - .then( - function (response) { - if (response.status != 201) - console.log('Ocurrió un error con el servicio: ' + response.status); - else - return response.json(); + } + return index; + + } + + function guardarAdmin() { + let _administrators = [...administrators]; + let _admin = { ...sysadmin }; + if (sysadmin._id) { + const index = findIndexById(sysadmin._id); + + _administrators[index] = _admin; + toast.current.show({ + severity: 'success', + summary: 'Exito', + detail: 'Administrador Actualizado', + life: 3000, + }); + setAdministrators(_administrators) + setEditAdminDialog(false); + setSysAdmin(emptySysAdmin); + } else { + var data = { + dni: document.getElementById('identificacion').value, + name: document.getElementById('nombre').value, + last_name: document.getElementById('apellidos').value, + email: document.getElementById('correo_electronico').value, + phone: document.getElementById('telefono').value, + password: document.getElementById('correo_electronico').value, + user_type: "1", //1 es admin + status: "1" + }; + setSysAdmin(data) + + fetch('http://localhost:4000/user/createAdminSystem/', { + cache: 'no-cache', + method: 'POST', + body: JSON.stringify(data), + headers: { + 'Content-Type': 'application/json' } - ) - .then( - function (response) { - let _administrators = [...administrators]; - let _admin = { ...sysadmin }; - _administrators.push(_admin); - setAdministrators(_administrators) - } - ) - .catch( - err => console.log('Ocurrió un error con el fetch', err) - ); + }) + .then( + function (response) { + if (response.status != 201) + console.log('Ocurrió un error con el servicio: ' + response.status); + else + return response.json(); + } + ) + .then( + function (response) { + _administrators.push(_admin); + setAdministrators(_administrators) + } + ) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } } const cambiarStatusUser = () => { @@ -301,7 +328,7 @@ const AdministradoresSistema = () => { title="Editar Administrador" /> - + +
)} @@ -841,7 +943,7 @@ const AdministradoresSistema = () => { - + From 05600cb829ee17bd6262988c3a5debe63bcfc850 Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 01:22:32 -0600 Subject: [PATCH 06/39] editar funciones para editar administrador en backend --- api-gateway/src/app.controller.ts | 14 +++++ api-gateway/src/app.service.ts | 13 +++++ .../src/users/users.controller.ts | 8 ++- .../src/components/AdministradoresSistema.js | 58 +++++++++++++++---- 4 files changed, 80 insertions(+), 13 deletions(-) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index adff4cf7..e8f6326a 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -179,6 +179,20 @@ export class AppController { return this.appService.changeStatusUser(pId, pStatus); } + + @Post('user/updateAdminSystem') + updateAdminSystem( + //Nombre, Apellidos, Correo electrónico, Cédula, Teléfono, Contraseña + @Body('_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, + ) { + return this.appService.updateAdminSystem(_id, dni, name, last_name, email, phone); + } + // #==== API Communities @Post('community/createCommunity') createCommunity( diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 965b4005..0cf32af5 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -223,6 +223,19 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + updateAdminSystem(_id: string, dni: string, name: string, + last_name: string, email: string, phone: number + ) { + const pattern = { cmd: 'updateAdminSystem' }; + const payload = { + _id: _id, dni: dni, name: name, last_name: last_name, + email: email, phone: phone + }; + return this.clientUserApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + //GET parameter from API findCommunityAdmin(community_id: string) { const pattern = { cmd: 'findCommunityAdmin' }; diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index a13bae7c..6a663394 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -66,7 +66,7 @@ export class UsersController { @MessagePattern({ cmd: 'updateUser' }) update(@Payload() user: UserDocument) { - return this.userService.update(user.id, user); + return this.userService.update(user._id, user); } @MessagePattern({ cmd: 'removeUser' }) @@ -74,7 +74,11 @@ export class UsersController { let dni = id['dni']; return this.userService.remove(dni); } - + + @MessagePattern({ cmd: 'updateAdminSystem' }) + updateAdminSystem(@Payload() user: UserDocument) { + return this.userService.update(user._id, user); + } //inicio de sesion @MessagePattern({ cmd: 'loginUser' }) findLogin(@Payload() body: string) { diff --git a/web-ui/web-react/src/components/AdministradoresSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js index 890d1ebe..dd3f84af 100644 --- a/web-ui/web-react/src/components/AdministradoresSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -86,18 +86,54 @@ const AdministradoresSistema = () => { let _administrators = [...administrators]; let _admin = { ...sysadmin }; if (sysadmin._id) { - const index = findIndexById(sysadmin._id); - _administrators[index] = _admin; - toast.current.show({ - severity: 'success', - summary: 'Exito', - detail: 'Administrador Actualizado', - life: 3000, - }); - setAdministrators(_administrators) - setEditAdminDialog(false); - setSysAdmin(emptySysAdmin); + if (sysadmin.name && sysadmin.dni && sysadmin.last_name && sysadmin.email && + sysadmin.phone) { + + fetch('http://localhost:4000/user/updateAdminSystem/', { + cache: 'no-cache', + method: 'POST', + body: JSON.stringify(_admin), + 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) { + const index = findIndexById(sysadmin._id); + + _administrators[index] = _admin; + toast.current.show({ + severity: 'success', + summary: 'Exito', + detail: 'Administrador Actualizado', + life: 3000, + }); + setAdministrators(_administrators) + setEditAdminDialog(false); + setSysAdmin(emptySysAdmin); + } + ) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + + } else { + setSubmitted(true); + + } + + + + } else { var data = { dni: document.getElementById('identificacion').value, From 6d66a783b7e66822935ffd5d2b9ab14cda97fefc Mon Sep 17 00:00:00 2001 From: Eduardo Quiros Date: Mon, 22 Aug 2022 05:59:30 -0600 Subject: [PATCH 07/39] format --- .../src/components/RegistroComunicado.js | 146 +++++++++--------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/web-ui/web-react/src/components/RegistroComunicado.js b/web-ui/web-react/src/components/RegistroComunicado.js index e2d756a9..1739f993 100644 --- a/web-ui/web-react/src/components/RegistroComunicado.js +++ b/web-ui/web-react/src/components/RegistroComunicado.js @@ -27,13 +27,13 @@ const RegistroComunicado = () => { community_id: '' }; - useEffect(()=>{ - listaComunis(); - },[]) + useEffect(() => { + listaComunis(); + }, []) const [comunicado, setComunicado] = useState(emptyComunicado); - const [comunicados,setComuicados]=useState([]); + const [comunicados, setComuicados] = useState([]); const [comunicadoId, setComunicadoId] = useState(null); const [submitted, setSubmitted] = useState(false); const toast = useRef(null); @@ -42,103 +42,103 @@ const RegistroComunicado = () => { const [globalFilter, setGlobalFilter] = useState(null); async function listaComunis() { - let comunicadosA=await fetch('http://localhost:4000/post/allPosts', {method:'GET'}); - let comunicadosRes= await comunicadosA.json(); - setComuicados(comunicadosRes.message); - console.log(comunicadosRes.message); - } + let comunicadosA = await fetch('http://localhost:4000/post/allPosts', { method: 'GET' }); + let comunicadosRes = await comunicadosA.json(); + setComuicados(comunicadosRes.message); + console.log(comunicadosRes.message); + } + - const saveComunicado = () => { var data = { post: document.getElementById('txt_comunicado').value, user_id: cookies.id, community_id: cookies.community_id - }; - - fetch('http://localhost:4000/post/createPost', { + }; + + fetch('http://localhost:4000/post/createPost', { 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(); - } + function(response) { + if (response.status != 201) + console.log('Ocurrió un error con el servicio: ' + response.status); + else + return response.json(); + } ) .then( - function (response) { - - } + function(response) { + + } ) .catch( - err => console.log('Ocurrió un error con el fetch', err) + err => console.log('Ocurrió un error con el fetch', err) ); } const header = ( - - -
-
Comunicados de la comunidad
- - - setGlobalFilter(e.target.value)} placeholder="Buscar..." /> - -
-
- ); - const headerPost = ( - <> -

- {' '} - {' '} - Descripción comunicado

- - ) - - const leftToolbarTemplate = () => { - return ( -
-
+
+ ) + } + + const rightToolbarTemplate = () => { + return ( + + + + + + ); From 553351d1d9603d390d7e26fc15300b9b81e58a2b Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 12:02:45 -0600 Subject: [PATCH 16/39] acomodar formato estandar de editar --- .../src/components/AdministradoresSistema.js | 158 +++--------------- web-ui/web-react/src/components/Inquilinos.js | 2 +- 2 files changed, 25 insertions(+), 135 deletions(-) diff --git a/web-ui/web-react/src/components/AdministradoresSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js index 7bd0bd6b..6fa70310 100644 --- a/web-ui/web-react/src/components/AdministradoresSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -51,6 +51,7 @@ const AdministradoresSistema = () => { const [submitted, setSubmitted] = useState(false); const [editAdminDialog, setEditAdminDialog] = useState(false); + const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar") async function fetchP() { @@ -276,16 +277,16 @@ const AdministradoresSistema = () => { }; - const hideEditAdminDialog = () => { - setSubmitted(false); - setEditAdminDialog(false); - setSysAdmin(emptySysAdmin); - }; + const cancelEdit = () => { + setSaveButtonTitle('Registrar'); + setSubmitted(false); + setSysAdmin(emptySysAdmin); + } const editAdmin = (sysadmin) => { setSysAdmin({ ...sysadmin }); - setEditAdminDialog(true); + setSaveButtonTitle('Actualizar'); }; const deleteSysAdmin = () => { @@ -853,138 +854,12 @@ const AdministradoresSistema = () => { )} - - {sysadmin && (
-
- -
-
- - - - onInputChange(e, 'name')} - required - autoFocus - className={classNames({ - 'p-invalid': submitted && sysadmin.name === '', - })} - /> -
- {submitted && sysadmin.name === '' && - Nombre es requirido.} - -
-
-
- -
-
- - - - onInputChange(e, 'last_name')} - required - autoFocus - className={classNames({ - 'p-invalid': submitted && sysadmin.last_name === '', - })} - /> -
- {submitted && sysadmin.last_name === '' && ( - Apellido(s) es requerido. - )} -
-
-
- -
-
- - - - onInputChange(e, 'email')} - required - autoFocus - className={classNames({ - 'p-invalid': submitted && (sysadmin.email === '' || findRepeated('email', sysadmin.email) > 0), - })} - /> -
- {submitted && sysadmin.email === '' && ( - Correo electrónico es requerido. - )} - {submitted && findRepeated('email', sysadmin.email) > 0 && - Correo electrónico se encuentra repetido. - } -
-
-
- -
-
- - - - onInputChange(e, 'dni')} - required - autoFocus - className={classNames({ - 'p-invalid': submitted && (sysadmin.dni === '' || findRepeated('dni', sysadmin.dni)), - })} - /> -
- {submitted && sysadmin.dni === '' && ( - Identificación es requerida. - )} - {submitted && findRepeated('dni', sysadmin.dni) > 0 && - Identificación se encuentra repetida. - } -
-
-
- -
-
- - - - onInputChange(e, 'phone')} - required - autoFocus - className={classNames({ - 'p-invalid': submitted && sysadmin.phone === '', - })} - /> -
- {submitted && sysadmin.phone === '' && ( - Teléfono es requerido. - )} -
-
- -
- )} -
-
Registro de un administrador del sistema
+
Mantenimiento Administrador del Sistema
@@ -1098,7 +973,22 @@ const AdministradoresSistema = () => { )}
- +
+
diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 244196da..6be6da53 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -858,7 +858,7 @@ const Inquilinos = () => { /> {saveButtonTitle === 'Actualizar' && (
From 2cea9bc217d2fd378c65dbf55760cf69288a9fde Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 12:35:40 -0600 Subject: [PATCH 17/39] asignar numero de vivienda --- api-gateway/src/app.service.ts | 31 +++++++++++++++++++ .../src/users/users.controller.ts | 6 ++++ servicio-usuarios/src/users/users.service.ts | 26 ++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 99ec6d7a..be6a794c 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -56,6 +56,37 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + createTenant( + dni: string, + name: string, + last_name: string, + email: string, + phone: number, + user_type: string, + status: string, + date_entry: Date, + community_id: string, + number_house: string, + ) { + const pattern = { cmd: 'createTenant' }; + const payload = { + dni: dni, + name: name, + last_name: last_name, + email: email, + phone: phone, + password: this.generatePassword(), + user_type: user_type, + status: status, + date_entry: date_entry, + community_id: community_id, + number_house: number_house, + }; + return this.clientUserApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + updateUser( _id: string, dni: string, diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index 05c13169..cedf2263 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -29,6 +29,12 @@ export class UsersController { return this.userService.createAdminCommunity(user); } + @MessagePattern({ cmd: 'createTenant' }) + createTenant(@Payload() user: UserDocument) { + return this.userService.createTenant(user); + } + + @MessagePattern({ cmd: 'findAllUsers' }) findAll() { return this.userService.findAll(); diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 255d2504..d9b442fc 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -24,6 +24,32 @@ export class UsersService { } + async createTenant(user: UserDocument) { + let password = user.password; + let passwordEncriptada = Md5.init(user.password); + user.password = passwordEncriptada; + this.userModel.create(user) + + await this.saveTenantNumHouse(user.community_id, user.number_house, user._id); + + let community = await this.findCommunity(user.community_id); + user.community_id = community['name']; + + const pattern = { cmd: 'emailCreateUserTenant' }; + const payload = { + email: user['email'], password: password, name: user['name'], + date_entry: user['date_entry'], community_name: community['name'], + number_house:['number_house'] + }; + + return this.clientNotificationtApp + .send(pattern, payload) + .pipe( + map((message: string) => ({ message })), + ); + } + + async createAdminCommunity(user: UserDocument) { let password = user.password; let passwordEncriptada = Md5.init(user.password); From c89e501005afa2c7118bd8b6b0fe4cbf22c5ee4f Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 12:57:33 -0600 Subject: [PATCH 18/39] agregar funciones de edici[on de agregar inquilino --- api-gateway/src/app.controller.ts | 29 +++++++++++++++++++ .../src/communities/communities.service.ts | 23 +++++++++++++++ servicio-usuarios/src/users/users.service.ts | 12 ++++++++ web-ui/web-react/src/components/Inquilinos.js | 10 ++++++- 4 files changed, 73 insertions(+), 1 deletion(-) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 67adc7db..2975a60a 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -82,6 +82,35 @@ export class AppController { ); } + + @Post('user/createTenant') + createTenant( + @Body('dni') dni: string, + @Body('name') name: string, + @Body('last_name') last_name: string, + @Body('email') email: string, + @Body('phone') phone: number, + @Body('user_type') user_type: string, + @Body('status') status: string, + @Body('date_entry') date_entry: Date, + @Body('community_id') community_id: string, + @Body('number_house') number_house: string, + ) { + return this.appService.createTenant( + dni, + name, + last_name, + email, + phone, + user_type, + status, + date_entry, + community_id, + number_house, + ); + } + + @Put('user/updateGuard/:id') updateGuard( @Param('id') id: string, diff --git a/servicio-comunidad-viviendas/src/communities/communities.service.ts b/servicio-comunidad-viviendas/src/communities/communities.service.ts index c494222b..90c47cee 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.service.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.service.ts @@ -87,6 +87,29 @@ export class CommunitiesService { await community.houses.map(house => { if(house.number_house == number_house){ house.tenants.tenant_id = tenant_id + house.state = "ocupada" + } + return house; + }) + + console.log(community.houses) + + return await this.communityModel.findOneAndUpdate({ _id: id }, community, { + new: true, + }); + } + + + async deleteTenant(id: string, number_house: string, tenant_id: string) { + + let community = await this.findOne(id); + + await community.houses.map(house => { + if(house.number_house == number_house && + house.tenants.tenant_id == tenant_id){ + house.tenants = null; + house.state = "desocupada" + } return house; }) diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index d9b442fc..41257a2e 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -268,5 +268,17 @@ export class UsersService { map((response: string) => ({ response })) ) } + + + async deleteTenantNumHouse(community_id: string, number_house:string, tenant_id: string) { + const pattern = { cmd: 'deleteTenant' } + const payload = { _id: community_id, number_house: number_house, tenant_id: tenant_id } + + return await this.clientCommunityApp + .send(pattern, payload) + .pipe( + map((response: string) => ({ response })) + ) + } } diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 8a21fc72..72c61df1 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -122,7 +122,7 @@ const Inquilinos = () => { _tenant.password = _tenant.email; console.log(`Registrando nuevo inquilino: ${_tenant}`) - fetch(`http://localhost:4000/user/createUser`, { + fetch(`http://localhost:4000/user/createTenant`, { cache: 'no-cache', method: 'POST', body: JSON.stringify(_tenant), @@ -136,6 +136,13 @@ const Inquilinos = () => { else return response.json() }) .then(() => { + if (_tenant.status === '1') { + _tenant.status = '0' + _tenant.status_text = 'Inactivo' + } else if (_tenant.status === '0') { + _tenant.status = '1' + _tenant.status_text = 'Activo' + } _tenants.push(_tenant) toast.current.show({ severity: 'success', @@ -143,6 +150,7 @@ const Inquilinos = () => { detail: 'Inquilino creado', life: 3000, }) + setTenants(_tenants) setTenant(emptyTenant) setHouseNumber('') From b7984b374885e3a2de5746f78732059a84cca0f7 Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 13:10:32 -0600 Subject: [PATCH 19/39] update funciones de notificaciones --- servicio-notificaciones/.env | 4 +- .../src/email.controller.ts | 35 +++++++++++++++++ .../dto/create-notification.dto.ts | 1 - .../dto/update-notification.dto.ts | 6 --- .../notifications/notifications.controller.ts | 38 ------------------- .../src/notifications/notifications.module.ts | 9 ----- .../notifications/notifications.service.ts | 26 ------------- .../schemas/notification.schemas.ts | 1 - 8 files changed, 37 insertions(+), 83 deletions(-) delete mode 100644 servicio-notificaciones/src/notifications/dto/create-notification.dto.ts delete mode 100644 servicio-notificaciones/src/notifications/dto/update-notification.dto.ts delete mode 100644 servicio-notificaciones/src/notifications/notifications.controller.ts delete mode 100644 servicio-notificaciones/src/notifications/notifications.module.ts delete mode 100644 servicio-notificaciones/src/notifications/notifications.service.ts delete mode 100644 servicio-notificaciones/src/notifications/schemas/notification.schemas.ts diff --git a/servicio-notificaciones/.env b/servicio-notificaciones/.env index 80c3aee2..7b8f623a 100644 --- a/servicio-notificaciones/.env +++ b/servicio-notificaciones/.env @@ -1,7 +1,7 @@ # mail MAIL_HOST=smtp.gmail.com -MAIL_USER=mbonilla.guti@gmail.com -MAIL_PASSWORD=laofghlofgffmyry +MAIL_USER=katoikiap4@gmail.com +MAIL_PASSWORD=snxwbncohehilkkz MAIL_FROM=noreply@example.com # optional diff --git a/servicio-notificaciones/src/email.controller.ts b/servicio-notificaciones/src/email.controller.ts index d1363138..b342079f 100644 --- a/servicio-notificaciones/src/email.controller.ts +++ b/servicio-notificaciones/src/email.controller.ts @@ -77,4 +77,39 @@ export class EmailController { }); return response; } + + + @MessagePattern({ cmd: 'emailCreateUserTenant' }) + async emailCreateUserTenant(@Payload() user: any) { + const url = "http://localhost:3000/"; + const image = "images/email.png"; + const logo = "images/Logo Katoikia.png"; + var response = await this.mailService.sendMail({ + to: user["email"], + from: "mbonilla.guti@gmail.com", + subject: 'Usuario registrado', + template: 'emailCreateUserTenant', + context: { + name: user["name"], + password: user["password"], + date_entry: user["date_entry"], + email: user["email"], + community_name: user['community_name'], + url + }, + attachments: [ + { + filename: 'email.png', + path: __dirname + '/mails/images/email.png', + cid: 'image_email' //my mistake was putting "cid:logo@cid" here! + }, + { + filename: 'Logo_Katoikia.png', + path: __dirname + '/mails/images/Logo_Katoikia.png', + cid: 'logoKatoikia' //my mistake was putting "cid:logo@cid" here! + } + ] + }); + return response; + } } diff --git a/servicio-notificaciones/src/notifications/dto/create-notification.dto.ts b/servicio-notificaciones/src/notifications/dto/create-notification.dto.ts deleted file mode 100644 index 98ca4791..00000000 --- a/servicio-notificaciones/src/notifications/dto/create-notification.dto.ts +++ /dev/null @@ -1 +0,0 @@ -export class CreateNotificationDto {} diff --git a/servicio-notificaciones/src/notifications/dto/update-notification.dto.ts b/servicio-notificaciones/src/notifications/dto/update-notification.dto.ts deleted file mode 100644 index f639cde4..00000000 --- a/servicio-notificaciones/src/notifications/dto/update-notification.dto.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { PartialType } from '@nestjs/mapped-types'; -import { CreateNotificationDto } from './create-notification.dto'; - -export class UpdateNotificationDto extends PartialType(CreateNotificationDto) { - id: number; -} diff --git a/servicio-notificaciones/src/notifications/notifications.controller.ts b/servicio-notificaciones/src/notifications/notifications.controller.ts deleted file mode 100644 index 4d8484f7..00000000 --- a/servicio-notificaciones/src/notifications/notifications.controller.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { Controller } from '@nestjs/common'; -import { MessagePattern, Payload } from '@nestjs/microservices'; -import { NotificationsService } from './notifications.service'; -import { CreateNotificationDto } from './dto/create-notification.dto'; -import { UpdateNotificationDto } from './dto/update-notification.dto'; - -@Controller() -export class NotificationsController { - constructor(private readonly notificationsService: NotificationsService) {} - - @MessagePattern({ cmd: 'createNotification' }) - create(@Payload() createNotificationDto: CreateNotificationDto) { - return this.notificationsService.create(createNotificationDto); - } - - @MessagePattern({ cmd: 'findAllNotifications' }) - findAll() { - return this.notificationsService.findAll(); - } - - @MessagePattern({ cmd: 'findOneNotification' }) - findOne(@Payload() id: number) { - return this.notificationsService.findOne(id); - } - - @MessagePattern({ cmd: 'updateNotification' }) - update(@Payload() updateNotificationDto: UpdateNotificationDto) { - return this.notificationsService.update( - updateNotificationDto.id, - updateNotificationDto, - ); - } - - @MessagePattern({ cmd: 'removeNotification' }) - remove(@Payload() id: number) { - return this.notificationsService.remove(id); - } -} diff --git a/servicio-notificaciones/src/notifications/notifications.module.ts b/servicio-notificaciones/src/notifications/notifications.module.ts deleted file mode 100644 index a3b7b79c..00000000 --- a/servicio-notificaciones/src/notifications/notifications.module.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Module } from '@nestjs/common'; -import { NotificationsService } from './notifications.service'; -import { NotificationsController } from './notifications.controller'; - -@Module({ - controllers: [NotificationsController], - providers: [NotificationsService], -}) -export class NotificationsModule {} diff --git a/servicio-notificaciones/src/notifications/notifications.service.ts b/servicio-notificaciones/src/notifications/notifications.service.ts deleted file mode 100644 index 41219fe1..00000000 --- a/servicio-notificaciones/src/notifications/notifications.service.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { CreateNotificationDto } from './dto/create-notification.dto'; -import { UpdateNotificationDto } from './dto/update-notification.dto'; - -@Injectable() -export class NotificationsService { - create(createNotificationDto: CreateNotificationDto) { - return 'This action adds a new notification'; - } - - findAll() { - return `This action returns all notifications`; - } - - findOne(id: number) { - return `This action returns a #${id} notification`; - } - - update(id: number, updateNotificationDto: UpdateNotificationDto) { - return `This action updates a #${id} notification`; - } - - remove(id: number) { - return `This action removes a #${id} notification`; - } -} diff --git a/servicio-notificaciones/src/notifications/schemas/notification.schemas.ts b/servicio-notificaciones/src/notifications/schemas/notification.schemas.ts deleted file mode 100644 index b79d7d57..00000000 --- a/servicio-notificaciones/src/notifications/schemas/notification.schemas.ts +++ /dev/null @@ -1 +0,0 @@ -export class Notification {} From 85e44d8c92a1ce40fed496a5926f42bada94e9f1 Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 13:18:46 -0600 Subject: [PATCH 20/39] agregar notificacion para inquilino registrado --- .../src/email.controller.ts | 10 +- .../src/mails/emailCreateUserAdmin.hbs | 2 +- .../mails/emailCreateUserAdminCommunity.hbs | 4 +- .../src/mails/emailCreateUserTenant.hbs | 459 ++++++++++++++++++ 4 files changed, 467 insertions(+), 8 deletions(-) create mode 100644 servicio-notificaciones/src/mails/emailCreateUserTenant.hbs diff --git a/servicio-notificaciones/src/email.controller.ts b/servicio-notificaciones/src/email.controller.ts index b342079f..0259684e 100644 --- a/servicio-notificaciones/src/email.controller.ts +++ b/servicio-notificaciones/src/email.controller.ts @@ -12,7 +12,7 @@ export class EmailController { sendMail(@Payload() toEmail: string) { var response = this.mailService.sendMail({ to: toEmail['email'], - from: 'mbonilla.guti@gmail.com', + from: 'katoikiap4@gmail.com', subject: 'Plain Text Email ✔', text: 'Welcome NestJS Email Sending Tutorial', }); @@ -25,7 +25,7 @@ export class EmailController { const image = "images/email.png"; var response = await this.mailService.sendMail({ to: user["email"], - from: "mbonilla.guti@gmail.com", + from: "katoikiap4@gmail.com", subject: 'HTML Dynamic Template', template: 'templateEmail', context: { @@ -51,7 +51,7 @@ export class EmailController { const logo = "images/Logo Katoikia.png"; var response = await this.mailService.sendMail({ to: user["email"], - from: "mbonilla.guti@gmail.com", + from: "katoikiap4@gmail.com", subject: 'Usuario registrado', template: 'emailCreateUserAdminCommunity', context: { @@ -86,7 +86,7 @@ export class EmailController { const logo = "images/Logo Katoikia.png"; var response = await this.mailService.sendMail({ to: user["email"], - from: "mbonilla.guti@gmail.com", + from: "katoikiap4@gmail.com", subject: 'Usuario registrado', template: 'emailCreateUserTenant', context: { @@ -95,7 +95,7 @@ export class EmailController { date_entry: user["date_entry"], email: user["email"], community_name: user['community_name'], - url + number_house: user['number_house'] }, attachments: [ { diff --git a/servicio-notificaciones/src/mails/emailCreateUserAdmin.hbs b/servicio-notificaciones/src/mails/emailCreateUserAdmin.hbs index 334dfd5b..4962f6cc 100644 --- a/servicio-notificaciones/src/mails/emailCreateUserAdmin.hbs +++ b/servicio-notificaciones/src/mails/emailCreateUserAdmin.hbs @@ -432,7 +432,7 @@

Información de contacto

    -
  • katoikiaapp@gmail.com
  • +
  • katoikiap4@gmail.com
diff --git a/servicio-notificaciones/src/mails/emailCreateUserAdminCommunity.hbs b/servicio-notificaciones/src/mails/emailCreateUserAdminCommunity.hbs index 9dc7ea9c..657f3c17 100644 --- a/servicio-notificaciones/src/mails/emailCreateUserAdminCommunity.hbs +++ b/servicio-notificaciones/src/mails/emailCreateUserAdminCommunity.hbs @@ -438,8 +438,8 @@

Información de contacto

    -
  • katoikiaapp@gmail.com
  • +
  • katoikiap4@gmail.com
diff --git a/servicio-notificaciones/src/mails/emailCreateUserTenant.hbs b/servicio-notificaciones/src/mails/emailCreateUserTenant.hbs new file mode 100644 index 00000000..3915f374 --- /dev/null +++ b/servicio-notificaciones/src/mails/emailCreateUserTenant.hbs @@ -0,0 +1,459 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌  +
+ +
+ + + \ No newline at end of file From c8da611700eb9afd266eb901efac3e282976f2bf Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 14:58:43 -0600 Subject: [PATCH 21/39] corregir agregar inquilino a comunidad --- .../src/communities/communities.controller.ts | 1 + .../src/communities/communities.service.ts | 41 +++++++++++++------ .../src/mails/emailCreateUserTenant.hbs | 2 +- .../src/users/users.controller.ts | 2 +- servicio-usuarios/src/users/users.service.ts | 9 ++-- web-ui/web-react/src/components/Inquilinos.js | 6 +-- 6 files changed, 40 insertions(+), 21 deletions(-) diff --git a/servicio-comunidad-viviendas/src/communities/communities.controller.ts b/servicio-comunidad-viviendas/src/communities/communities.controller.ts index 6ef0c9fc..1133b4d0 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.controller.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.controller.ts @@ -57,6 +57,7 @@ export class CommunitiesController { @MessagePattern({ cmd: 'saveTenant' }) saveTenant(@Payload() body: string) { + let id = body['_id']; let tenant_id = body['tenant_id']; let number_house = body['number_house']; diff --git a/servicio-comunidad-viviendas/src/communities/communities.service.ts b/servicio-comunidad-viviendas/src/communities/communities.service.ts index 90c47cee..48ad87b8 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.service.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.service.ts @@ -6,6 +6,7 @@ import { RpcException, ClientProxy } from '@nestjs/microservices'; import { from, lastValueFrom, map, scan, mergeMap } from 'rxjs'; import { Admin } from 'src/schemas/admin.entity'; import { appendFileSync } from 'fs'; +import { Tenant, TenantSchema } from 'src/schemas/tenant.schema'; @Injectable() export class CommunitiesService { @@ -80,21 +81,37 @@ export class CommunitiesService { } - async saveTenant(id: string, number_house: string, tenant_id: string) { - + async saveTenant(id: string, number_house: string, ptenant_id: string) { let community = await this.findOne(id); + console.log(ptenant_id) + await community.houses.map(house => { - if(house.number_house == number_house){ - house.tenants.tenant_id = tenant_id + if (house.number_house == number_house) { + if (house.tenants) { + console.log(house.tenants.tenant_id + '1') + + house.tenants.tenant_id = ptenant_id + console.log(house.tenants.tenant_id + '1') + console.log(house.tenants + '1') + } else { + let tenant = new Tenant() + + tenant.tenant_id = ptenant_id; + console.log(tenant) + + house.tenants = tenant; + console.log(house.tenants + '2') + + } + console.log(house.tenants + '3') + house.state = "ocupada" } return house; }) - console.log(community.houses) - - return await this.communityModel.findOneAndUpdate({ _id: id }, community, { + return await this.communityModel.findOneAndUpdate({ _id: id }, community, { new: true, }); } @@ -105,10 +122,10 @@ export class CommunitiesService { let community = await this.findOne(id); await community.houses.map(house => { - if(house.number_house == number_house && - house.tenants.tenant_id == tenant_id){ - house.tenants = null; - house.state = "desocupada" + if (house.number_house == number_house && + house.tenants.tenant_id == tenant_id) { + house.tenants = null; + house.state = "desocupada" } return house; @@ -116,7 +133,7 @@ export class CommunitiesService { console.log(community.houses) - return await this.communityModel.findOneAndUpdate({ _id: id }, community, { + return await this.communityModel.findOneAndUpdate({ _id: id }, community, { new: true, }); } diff --git a/servicio-notificaciones/src/mails/emailCreateUserTenant.hbs b/servicio-notificaciones/src/mails/emailCreateUserTenant.hbs index 3915f374..4669d4a8 100644 --- a/servicio-notificaciones/src/mails/emailCreateUserTenant.hbs +++ b/servicio-notificaciones/src/mails/emailCreateUserTenant.hbs @@ -393,7 +393,7 @@ {{date_entry}}
-

Fue asignado en la comunidad {{community_name}} en la vivienda #{{number_house}}

+

Fue asignado en la comunidad {{community_name}} en la vivienda # {{number_house}}

diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index cedf2263..06f9cd88 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -133,7 +133,7 @@ export class UsersController { @MessagePattern({ cmd: 'deleteTenant' }) deleteTenant(@Payload() user: any) { - return this.userService.deleteTenant(user['id']); + return this.userService.deleteTenant(user['_id']); } @MessagePattern({ cmd: 'changeStatus' }) diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 41257a2e..8061479e 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -28,9 +28,12 @@ export class UsersService { let password = user.password; let passwordEncriptada = Md5.init(user.password); user.password = passwordEncriptada; - this.userModel.create(user) + let userCreated = await this.userModel.create(user); + console.log(await userCreated); + let callback = await this.saveTenantNumHouse(user.community_id, user.number_house, userCreated['_id']); - await this.saveTenantNumHouse(user.community_id, user.number_house, user._id); + const finalValue = await lastValueFrom(callback); + const response = await finalValue['response']; let community = await this.findCommunity(user.community_id); user.community_id = community['name']; @@ -39,7 +42,7 @@ export class UsersService { const payload = { email: user['email'], password: password, name: user['name'], date_entry: user['date_entry'], community_name: community['name'], - number_house:['number_house'] + number_house: user['number_house'] }; return this.clientNotificationtApp diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 72c61df1..94e4ab4e 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -137,11 +137,9 @@ const Inquilinos = () => { }) .then(() => { if (_tenant.status === '1') { - _tenant.status = '0' - _tenant.status_text = 'Inactivo' - } else if (_tenant.status === '0') { - _tenant.status = '1' _tenant.status_text = 'Activo' + } else if (_tenant.status === '0') { + _tenant.status_text = 'Inactivo' } _tenants.push(_tenant) toast.current.show({ From 9e7ac1d91fd584c47635326ffcc75f859ef930b0 Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 15:04:47 -0600 Subject: [PATCH 22/39] arreglar correo de registro --- .../src/communities/communities.service.ts | 13 ------------- .../src/mails/emailCreateUserTenant.hbs | 4 ++-- servicio-usuarios/src/users/users.service.ts | 6 +----- 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/servicio-comunidad-viviendas/src/communities/communities.service.ts b/servicio-comunidad-viviendas/src/communities/communities.service.ts index 48ad87b8..fa7ed5b7 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.service.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.service.ts @@ -83,29 +83,16 @@ export class CommunitiesService { async saveTenant(id: string, number_house: string, ptenant_id: string) { let community = await this.findOne(id); - - console.log(ptenant_id) - await community.houses.map(house => { if (house.number_house == number_house) { if (house.tenants) { - console.log(house.tenants.tenant_id + '1') house.tenants.tenant_id = ptenant_id - console.log(house.tenants.tenant_id + '1') - console.log(house.tenants + '1') } else { let tenant = new Tenant() - tenant.tenant_id = ptenant_id; - console.log(tenant) - house.tenants = tenant; - console.log(house.tenants + '2') - } - console.log(house.tenants + '3') - house.state = "ocupada" } return house; diff --git a/servicio-notificaciones/src/mails/emailCreateUserTenant.hbs b/servicio-notificaciones/src/mails/emailCreateUserTenant.hbs index 4669d4a8..a4a7586c 100644 --- a/servicio-notificaciones/src/mails/emailCreateUserTenant.hbs +++ b/servicio-notificaciones/src/mails/emailCreateUserTenant.hbs @@ -362,7 +362,7 @@ - Logo Katoikia @@ -393,7 +393,7 @@ {{date_entry}}
-

Fue asignado en la comunidad {{community_name}} en la vivienda # {{number_house}}

+

Fue asignado en la comunidad "{{community_name}}" en la vivienda #{{number_house}}

diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 8061479e..96c973d7 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -29,11 +29,7 @@ export class UsersService { let passwordEncriptada = Md5.init(user.password); user.password = passwordEncriptada; let userCreated = await this.userModel.create(user); - console.log(await userCreated); - let callback = await this.saveTenantNumHouse(user.community_id, user.number_house, userCreated['_id']); - - const finalValue = await lastValueFrom(callback); - const response = await finalValue['response']; + await this.saveTenantNumHouse(user.community_id, user.number_house, userCreated['_id']); let community = await this.findCommunity(user.community_id); user.community_id = community['name']; From 456d9ce4d096a910b621e22f00b965a432c37cc5 Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 15:06:44 -0600 Subject: [PATCH 23/39] deleteTenant function community --- .../src/communities/communities.controller.ts | 9 +++++++++ .../src/communities/communities.service.ts | 5 +---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/servicio-comunidad-viviendas/src/communities/communities.controller.ts b/servicio-comunidad-viviendas/src/communities/communities.controller.ts index 1133b4d0..d8302399 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.controller.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.controller.ts @@ -63,4 +63,13 @@ export class CommunitiesController { let number_house = body['number_house']; return this.communitiesService.saveTenant(id, number_house, tenant_id); } + + @MessagePattern({ cmd: 'deleteTenant' }) + deleteTenant(@Payload() body: string) { + + let id = body['_id']; + let tenant_id = body['tenant_id']; + let number_house = body['number_house']; + return this.communitiesService.deleteTenant(id, number_house, tenant_id); + } } diff --git a/servicio-comunidad-viviendas/src/communities/communities.service.ts b/servicio-comunidad-viviendas/src/communities/communities.service.ts index fa7ed5b7..b718a024 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.service.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.service.ts @@ -111,15 +111,12 @@ export class CommunitiesService { await community.houses.map(house => { if (house.number_house == number_house && house.tenants.tenant_id == tenant_id) { - house.tenants = null; + house.tenants.tenant_id = ""; house.state = "desocupada" - } return house; }) - console.log(community.houses) - return await this.communityModel.findOneAndUpdate({ _id: id }, community, { new: true, }); From a9c02244a8d16ea5120c3f40c788da760174da44 Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 16:39:20 -0600 Subject: [PATCH 24/39] finalizar eliminar inquilino --- api-gateway/src/app.controller.ts | 26 ++++++---- api-gateway/src/app.service.ts | 8 +-- .../src/communities/communities.controller.ts | 1 - .../src/communities/communities.service.ts | 4 +- .../src/users/users.controller.ts | 5 +- servicio-usuarios/src/users/users.service.ts | 29 +++++++---- web-ui/web-react/src/components/Inquilinos.js | 52 +++++++++++++++---- 7 files changed, 85 insertions(+), 40 deletions(-) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 2975a60a..510dfeb9 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -2,7 +2,7 @@ import { Controller, Get, Post, Put, Body, Param, Delete } from '@nestjs/common' import { AppService } from './app.service'; @Controller() export class AppController { - constructor(private readonly appService: AppService) {} + constructor(private readonly appService: AppService) { } // #==== API Users @Post('user/createAdminSystem') createAdminSystem( @@ -15,8 +15,8 @@ export class AppController { @Body('status') status: string, @Body('date_entry') date_entry: Date, ) { - return this.appService.createAdminSystem(dni, name, last_name, email, phone, - user_type, status, date_entry); + return this.appService.createAdminSystem(dni, name, last_name, email, phone, + user_type, status, date_entry); } @Post('user/createGuard') @@ -33,7 +33,7 @@ export class AppController { @Body('community_id') community_id: string, ) { return this.appService.createGuard(dni, name, last_name, email, phone, - user_type, status, date_entry,community_id); + user_type, status, date_entry, community_id); } @Post('user/createAdminCommunity') @@ -47,10 +47,10 @@ export class AppController { @Body('user_type') user_type: string, @Body('status') status: string, @Body('date_entry') date_entry: Date, - @Body('community_id') community_id:string + @Body('community_id') community_id: string ) { return this.appService.createAdminCommunity(dni, name, last_name, email, phone, - user_type, status, date_entry,community_id); + user_type, status, date_entry, community_id); } @Post('user/createUser') @@ -82,7 +82,7 @@ export class AppController { ); } - + @Post('user/createTenant') createTenant( @Body('dni') dni: string, @@ -203,7 +203,7 @@ export class AppController { allUsersTenants(@Param('community_id') paramCommunity_id: string) { return this.appService.findTenantsCommunity(paramCommunity_id); } - + @Get('user/find/:dni') findUser(@Param('dni') paramUserDNI: string) { return this.appService.findUser(paramUserDNI); @@ -224,9 +224,13 @@ export class AppController { return this.appService.deleteAdminCommunity(id); } - @Delete('user/deleteTenant/:id') - deleteTenant(@Param('id') id: string) { - return this.appService.deleteTenant(id); + @Put('user/deleteTenant/:id') + deleteTenant( + @Param('id') id: string, + @Body('community_id') community_id: string, + @Body('number_house') number_house: string + ) { + return this.appService.deleteTenant(id, community_id, number_house); } @Post('user/changeStatus') diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index be6a794c..42475489 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -271,9 +271,9 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } - deleteTenant(id: string) { + deleteTenant(id: string, community_id: string, number_house: string) { const pattern = { cmd: 'deleteTenant' }; - const payload = { id: id }; + const payload = { _id: id, community_id: community_id, number_house: number_house }; return this.clientUserApp .send(pattern, payload) .pipe(map((message: string) => ({ message }))); @@ -382,7 +382,7 @@ export class AppService { const finalValue = await lastValueFrom(callback); const response = finalValue['response']; const houses = response['houses']; - + return houses; } @@ -393,7 +393,7 @@ export class AppService { .send(pattern, payload) .pipe(map((message: string) => ({ message }))); } - + // ====================== COMMON AREAS =============================== //POST parameter from API createCommonArea( diff --git a/servicio-comunidad-viviendas/src/communities/communities.controller.ts b/servicio-comunidad-viviendas/src/communities/communities.controller.ts index d8302399..a0fa2672 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.controller.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.controller.ts @@ -66,7 +66,6 @@ export class CommunitiesController { @MessagePattern({ cmd: 'deleteTenant' }) deleteTenant(@Payload() body: string) { - let id = body['_id']; let tenant_id = body['tenant_id']; let number_house = body['number_house']; diff --git a/servicio-comunidad-viviendas/src/communities/communities.service.ts b/servicio-comunidad-viviendas/src/communities/communities.service.ts index b718a024..dc3773e7 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.service.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.service.ts @@ -105,12 +105,10 @@ export class CommunitiesService { async deleteTenant(id: string, number_house: string, tenant_id: string) { - let community = await this.findOne(id); await community.houses.map(house => { - if (house.number_house == number_house && - house.tenants.tenant_id == tenant_id) { + if (house.number_house === number_house) { house.tenants.tenant_id = ""; house.state = "desocupada" } diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index 06f9cd88..07cee85d 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -133,7 +133,10 @@ export class UsersController { @MessagePattern({ cmd: 'deleteTenant' }) deleteTenant(@Payload() user: any) { - return this.userService.deleteTenant(user['_id']); + let tenant_id = user['_id']; + return this.userService.deleteTenant(tenant_id, + user['community_id'], + user['number_house']); } @MessagePattern({ cmd: 'changeStatus' }) diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 96c973d7..d42cffb9 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -29,7 +29,7 @@ export class UsersService { let passwordEncriptada = Md5.init(user.password); user.password = passwordEncriptada; let userCreated = await this.userModel.create(user); - await this.saveTenantNumHouse(user.community_id, user.number_house, userCreated['_id']); + await this.saveTenantNumHouse(user.community_id, user.number_house, userCreated['_id']); let community = await this.findCommunity(user.community_id); user.community_id = community['name']; @@ -195,7 +195,7 @@ export class UsersService { } async deleteAdminSystem(id: string) { - return this.userModel.findOneAndUpdate({ _id: id }, { status: '-1' }, { + return this.userModel.findOneAndUpdate({ _id: id }, { status: '-1', number_house:'' }, { new: true, }); } @@ -206,10 +206,18 @@ export class UsersService { }); } - async deleteTenant(id: string) { - return this.userModel.findOneAndUpdate({ _id: id }, { status: '-1' }, { - new: true, - }); + async deleteTenant(tenant_id: string, community_id: string, number_house: string) { + + try{ + this.userModel.findOneAndUpdate({ _id: tenant_id }, { status: '-1' }, { + new: true, + }); + + return await this.deleteTenantNumHouse(community_id, number_house, tenant_id); + } catch(error){ + console.log(error) + return error; + } } async validateEmail(email: string) { @@ -257,9 +265,9 @@ export class UsersService { } - async saveTenantNumHouse(community_id: string, number_house:string, tenant_id: string) { + async saveTenantNumHouse(community_id: string, number_house: string, tenant_id: string) { 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 } return await this.clientCommunityApp .send(pattern, payload) @@ -269,10 +277,9 @@ export class UsersService { } - async deleteTenantNumHouse(community_id: string, number_house:string, tenant_id: string) { + async deleteTenantNumHouse(community_id: string, number_house: string, tenant_id: string) { const pattern = { cmd: 'deleteTenant' } - 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 } return await this.clientCommunityApp .send(pattern, payload) .pipe( diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 94e4ab4e..0f8fa2a3 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -184,15 +184,49 @@ const Inquilinos = () => { } const deleteTenant = () => { - 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, - }) + + let _tenant = { + community_id: tenant.community_id, + number_house: tenant.number_house + }; + + fetch('http://localhost:4000/user/deleteTenant/' + tenant._id, { + cache: 'no-cache', + method: 'PUT', + body: JSON.stringify(_tenant), + 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 _tenants = tenants.filter((val) => val._id !== tenant._id) + setTenants(_tenants) + setDeleteTenantDialog(false) + setTenant(emptyTenant) + toast.current.show({ + severity: 'success', + summary: 'Inquilino Eliminado', + life: 3000, + }) } + ) + .catch( + err => { + console.log('Ocurrió un error con el fetch', err) + toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Inquilino no se pudo eliminar', life: 3000 }); + } + ); + + } const deleteSelectedTenants = () => { From 2dcfdf495f13278b036cd6bc83f6351413698b71 Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 16:43:52 -0600 Subject: [PATCH 25/39] arreglar ultimos detalles para el eliminar --- servicio-usuarios/src/users/users.service.ts | 4 +- web-ui/web-react/src/components/Inquilinos.js | 57 ++++++++++--------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index d42cffb9..e5a17fef 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -195,7 +195,7 @@ export class UsersService { } async deleteAdminSystem(id: string) { - return this.userModel.findOneAndUpdate({ _id: id }, { status: '-1', number_house:'' }, { + return this.userModel.findOneAndUpdate({ _id: id }, { status: '-1'}, { new: true, }); } @@ -209,7 +209,7 @@ export class UsersService { async deleteTenant(tenant_id: string, community_id: string, number_house: string) { try{ - this.userModel.findOneAndUpdate({ _id: tenant_id }, { status: '-1' }, { + await this.userModel.findOneAndUpdate({ _id: tenant_id }, { status: '-1', number_house:''}, { new: true, }); diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 0f8fa2a3..0e0350e9 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -60,7 +60,7 @@ const Inquilinos = () => { .then((response) => response.json()) .then((data) => data.message) .then((data) => { - data = data.filter((val) => val.status !== -1) + data = data.filter((val) => val.status != -1) data.map((item) => { if (item.status === '1') { item.status_text = 'Activo' @@ -120,7 +120,7 @@ const Inquilinos = () => { _tenant.community_id = cookies.community_id; _tenant.number_house = houseNumber; _tenant.password = _tenant.email; - console.log(`Registrando nuevo inquilino: ${_tenant}`) + console.log(`Registrando nuevo inquilino: ${_tenant}`) fetch(`http://localhost:4000/user/createTenant`, { cache: 'no-cache', @@ -135,7 +135,7 @@ const Inquilinos = () => { console.log(`Hubo un error en el servicio: ${response.status}`) else return response.json() }) - .then(() => { + .then((data) => { if (_tenant.status === '1') { _tenant.status_text = 'Activo' } else if (_tenant.status === '0') { @@ -184,7 +184,7 @@ const Inquilinos = () => { } const deleteTenant = () => { - + let _tenant = { community_id: tenant.community_id, number_house: tenant.number_house @@ -195,38 +195,39 @@ const Inquilinos = () => { method: 'PUT', body: JSON.stringify(_tenant), 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(); - } + function (response) { + if (response.status != 201) + console.log('Ocurrió un error con el servicio: ' + response.status); + else + return response.json(); + } ) .then( - function (response) { + function (response) { - 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, - }) } + 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, + }) + } ) .catch( - err => { - console.log('Ocurrió un error con el fetch', err) - toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Inquilino no se pudo eliminar', life: 3000 }); - } + err => { + console.log('Ocurrió un error con el fetch', err) + toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Inquilino no se pudo eliminar', life: 3000 }); + } ); - - + + } const deleteSelectedTenants = () => { From b9d79c8402a2028bf342f3f19b01749a64654acd Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 17:54:08 -0600 Subject: [PATCH 26/39] fix filtro de inquilinos eliminados --- 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 0e0350e9..459cee47 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -60,7 +60,7 @@ const Inquilinos = () => { .then((response) => response.json()) .then((data) => data.message) .then((data) => { - data = data.filter((val) => val.status != -1) + data = data.filter((val) => val.status !== -1) data.map((item) => { if (item.status === '1') { item.status_text = 'Activo' From 951031592ca9c4d7da866c27aca178d874d275e5 Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 17:57:55 -0600 Subject: [PATCH 27/39] 2 --- api-gateway/src/app.controller.ts | 38 ++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 5ebc741f..647eca29 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -208,6 +208,26 @@ export class AppController { return this.appService.changeStatusUser(pId, pStatus); } + @Put('user/updateAdminCommunity/:id') + updateAdminCommunity( + @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, + ) { + return this.appService.updateAdminCommunity( + id, + dni, + name, + last_name, + email, + phone, + community_id, + ); + } // #==== API Communities @Post('community/createCommunity') createCommunity( @@ -261,7 +281,23 @@ export class AppController { return this.appService.changeStatusCommunity(pId, pStatus); } - + @Get('community/findHousesCommunity/:id') + findHousesCommunity( + @Param('id') community_id: string, + ) { + return this.appService.findHousesCommunity(community_id); + } + + @Post('community/saveTenant') + saveTenant( + @Body('community_id') community_id: string, + @Body('number_house') number_house: string, + @Body('tenant_id') tenant_id: string, + ) { + return this.appService.saveTenant(community_id, number_house, tenant_id); + } + + // #==== API Common Areas @Post('commonArea/createCommonArea') createCommonArea( From 079e439bf0c0f97decb42e8b89d98421b6cb4e4a Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 17:58:07 -0600 Subject: [PATCH 28/39] 2 --- api-gateway/src/app.service.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 9307433c..29a84208 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -120,7 +120,29 @@ export class AppService { .send(pattern, payload) .pipe(map((message: string) => ({ message }))); } - + updateAdminCommunity( + _id: string, + dni: string, + name: string, + last_name: string, + email: string, + phone: number, + community_id: string, + ) { + const pattern = { cmd: 'updateAdminCommunity' }; + const payload = { + id: _id, + dni: dni, + name: name, + last_name: last_name, + email: email, + phone: phone, + 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) { From d7072e64cbb38ef6b71a68300ed1adb8bb4865e8 Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 17:58:28 -0600 Subject: [PATCH 29/39] 3 --- servicio-usuarios/src/users/users.controller.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index 05c13169..775ca4f0 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -74,6 +74,11 @@ export class UsersController { return this.userService.update(guard.id, guard); } + @MessagePattern({ cmd: 'updateAdminCommunity' }) + updateAdminCommunity(@Payload() user: UserDocument) { + return this.userService.update(user._id, user); + } + @MessagePattern({ cmd: 'removeUser' }) remove(@Payload() id: string) { let dni = id['dni']; From 81cb378a1a1b0b2dce3bc75eff8ee8762405f7ec Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 18:19:27 -0600 Subject: [PATCH 30/39] agregar funciones en backend --- .../components/AdministradoresComunidad.js | 165 ++++++++++++------ 1 file changed, 116 insertions(+), 49 deletions(-) diff --git a/web-ui/web-react/src/components/AdministradoresComunidad.js b/web-ui/web-react/src/components/AdministradoresComunidad.js index 0ec73891..ece37bf1 100644 --- a/web-ui/web-react/src/components/AdministradoresComunidad.js +++ b/web-ui/web-react/src/components/AdministradoresComunidad.js @@ -49,6 +49,7 @@ const AdministradoresComunidad = () => { const dt = useRef(null); const [changeStatusAdminCommunityDialog, setChangeStatusAdminCommunityDialog] = useState(false); + const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar"); async function listaAdmin() { @@ -151,22 +152,22 @@ const AdministradoresComunidad = () => { } ); - + }; const deleteSelectedAdminsCommunity = () => { let _admins = listaAdmins.filter( (val) => !selectedAdminsCommunities.includes(val), ); - selectedAdminsCommunities.map((item) => { - fetch('http://localhost:4000/user/deleteAdminCommunity/' + item._id, { - cache: 'no-cache', - method: 'DELETE', - headers: { - 'Content-Type': 'application/json' - } - }) - }) + selectedAdminsCommunities.map((item) => { + fetch('http://localhost:4000/user/deleteAdminCommunity/' + item._id, { + cache: 'no-cache', + method: 'DELETE', + headers: { + 'Content-Type': 'application/json' + } + }) + }) setListaAdmins(_admins); setDeleteAdminsCommunitiesDialog(false); setSelectedAdminsCommunities(null); @@ -225,51 +226,82 @@ const AdministradoresComunidad = () => { } const saveAdminCommunity = () => { - if (adminCommunity.name && adminCommunity.dni && adminCommunity.last_name && adminCommunity.email && adminCommunity.phone) { + let _administrators = [...listaAdmins]; - let _administrators = [...listaAdmins]; - let _adminCommunity = { ...adminCommunity }; - _adminCommunity.community_id = communityId; - console.log(_adminCommunity) - console.log(communityId) + if (adminCommunity._id) { + if (adminCommunity.name && adminCommunity.dni && + adminCommunity.last_name && adminCommunity.email && + adminCommunity.phone) { - fetch('http://localhost:4000/user/createAdminCommunity', { - cache: 'no-cache', - method: 'POST', - body: JSON.stringify(_adminCommunity), - 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(); + let _adminCommunity = { ...adminCommunity }; + _adminCommunity.community_id = communityId; + + fetch('http://localhost:4000/user/createAdminCommunity', { + cache: 'no-cache', + method: 'POST', + body: JSON.stringify(_adminCommunity), + headers: { + 'Content-Type': 'application/json' } - ) - .then(() => { - - // _adminCommunity.community_id = communitiesList.find(c => c._id === _adminCommunity.community_id).name - - _administrators.push(_adminCommunity); - toast.current.show({ severity: 'success', summary: 'Registro exitoso', detail: 'Administrador de Comunidad de vivienda Creada', life: 3000 }); - - setListaAdmins(_administrators); - - setAdminCommunity(emptyAdminCommunity); - }) - .catch( - err => console.log('Ocurrió un error con el fetch', err) - ); + .then( + function (response) { + if (response.status != 201) + console.log('Ocurrió un error con el servicio: ' + response.status); + else + return response.json(); + } + ) + .then(() => { + + // _adminCommunity.community_id = communitiesList.find(c => c._id === _adminCommunity.community_id).name + + _administrators.push(_adminCommunity); + toast.current.show({ severity: 'success', summary: 'Registro exitoso', detail: 'Administrador de Comunidad de vivienda Creada', life: 3000 }); + + setListaAdmins(_administrators); + + setAdminCommunity(emptyAdminCommunity); + + }) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } else { + setSubmitted(true); + } } else { - setSubmitted(true); + let _admin = { ...adminCommunity }; + console.log(`Actualizando admnistrador de comunidad: ${_admin}`) + fetch(`http://localhost:4000/user/updateAdminCommunity/${_admin._id}`, { + cache: 'no-cache', + method: 'PUT', + body: JSON.stringify(_admin), + headers: { + 'Content-Type': 'application/json', + }, + }).then((response) => { + if (response.status !== 200) + console.log(`Hubo un error en el servicio: ${response.status}`) + else return response.json() + }).then(() => { + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Inquilino editado', + life: 3000, + }) + _administrators.push(_admin); + toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Administrador de Comunidad de vivienda Actualizada', life: 3000 }); + setListaAdmins(_administrators); + + setAdminCommunity(emptyAdminCommunity); + }) } + } const hideDeleteAdminCommunityDialog = () => { @@ -298,6 +330,18 @@ const AdministradoresComunidad = () => { setChangeStatusAdminCommunityDialog(true); }; + const editAdmin = (admin) => { + setAdminCommunity(admin); + console.log(admin); + setSaveButtonTitle('Actualizar'); + } + + + const cancelEdit = () => { + setAdminCommunity(adminCommunity); + setSaveButtonTitle('Registrar'); + } + const actionsAdminCommunity = (rowData) => { let icono = ''; let text = ''; @@ -310,15 +354,22 @@ const AdministradoresComunidad = () => { } return (
+
@@ -503,7 +554,7 @@ const AdministradoresComunidad = () => { - +
@@ -617,7 +668,23 @@ const AdministradoresComunidad = () => { {submitted && !communityId && Comunidad es requirida.}
-