From 951031592ca9c4d7da866c27aca178d874d275e5 Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 17:57:55 -0600 Subject: [PATCH 1/9] 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 2/9] 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 3/9] 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 4/9] 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.}
-