From 49cb71e767831e9017c2665212dcd012b364a819 Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 23 Aug 2022 00:32:13 -0600 Subject: [PATCH 01/13] eliminar y eliminar id comunidad de administradores --- api-gateway/src/app.controller.ts | 5 ++ api-gateway/src/app.service.ts | 9 +++ .../src/communities/communities.controller.ts | 30 ++++----- .../src/communities/communities.service.ts | 13 ++++ .../src/users/users.controller.ts | 7 ++ servicio-usuarios/src/users/users.service.ts | 6 ++ .../src/components/ComunidadViviendas.js | 66 +++++++++---------- 7 files changed, 86 insertions(+), 50 deletions(-) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 3753431b..4def7296 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -323,6 +323,11 @@ export class AppController { ) { return this.appService.saveTenant(community_id, number_house, tenant_id); } + + @Delete('community/deleteCommunity/:id') + deleteCommunity(@Param('id') paramCommunityId: string) { + return this.appService.deleteCommunity(paramCommunityId); + } // #==== API Common Areas @Post('commonArea/createCommonArea') createCommonArea( diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 1e173a1c..fbe5a423 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -407,6 +407,15 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + deleteCommunity(id: string) { + const pattern = { cmd: 'removeCommunity' }; + const payload = { _id: id }; + return this.clientCommunityApp + .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 a0fa2672..f71e2524 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.controller.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.controller.ts @@ -5,7 +5,7 @@ import { Community, CommunityDocument } from 'src/schemas/community.schema'; @Controller() export class CommunitiesController { - constructor(private readonly communitiesService: CommunitiesService) {} + constructor(private readonly communitiesService: CommunitiesService) { } @MessagePattern({ cmd: 'createCommunity' }) create(@Payload() community: CommunityDocument) { @@ -46,17 +46,17 @@ export class CommunitiesController { return this.communitiesService.remove(_id); } - //cambiar de estado - @MessagePattern({ cmd: 'changeStatus' }) - changeStatus(@Payload() body: string) { - let pid = body['id']; - let pstatus = body['status']; - return this.communitiesService.changeStatus(pid,pstatus); - } + //cambiar de estado + @MessagePattern({ cmd: 'changeStatus' }) + changeStatus(@Payload() body: string) { + let pid = body['id']; + let pstatus = body['status']; + return this.communitiesService.changeStatus(pid, pstatus); + } - @MessagePattern({ cmd: 'saveTenant' }) - saveTenant(@Payload() body: string) { + @MessagePattern({ cmd: 'saveTenant' }) + saveTenant(@Payload() body: string) { let id = body['_id']; let tenant_id = body['tenant_id']; @@ -66,9 +66,9 @@ 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']; - return this.communitiesService.deleteTenant(id, number_house, tenant_id); - } + 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 dc3773e7..93f7cbe2 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.service.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.service.ts @@ -57,6 +57,7 @@ export class CommunitiesService { } async remove(id: string) { + await this.removeIdCommunity(id); return this.communityModel.findOneAndUpdate({ _id: id }, { status: '-1' }, { new: true, }); @@ -119,4 +120,16 @@ export class CommunitiesService { new: true, }); } + + async removeIdCommunity(community: string) { + const pattern = { cmd: 'removeIdCommunity' }; + const payload = { community_id: community}; + + let callback = await this.clientUserApp + .send(pattern, payload) + .pipe(map((response: string) => ({ response }))); + + const finalValue = await lastValueFrom(callback); + return finalValue['response']; + } } diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index be7deb01..53f32074 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -142,6 +142,13 @@ export class UsersController { user['number_house']); } + @MessagePattern({ cmd: 'removeIdCommunity' }) + removeIdCommunity(@Payload() user: any) { + let community_id = user['community_id']; + return this.userService.removeIdCommunity(community_id); + } + + @MessagePattern({ cmd: 'changeStatus' }) changeStatus(@Payload() body: string) { let pid = body['id']; diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 1393b2bd..bc8ea288 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -295,5 +295,11 @@ export class UsersService { map((response: string) => ({ response })) ) } + + async removeIdCommunity(community_id: string){ + return this.userModel.updateMany({community_id: community_id, user_type:'2' }, {"$set":{"community_id": ''}}); + /*await this.userModel.updateMany({community_id: community_id, user_type:'3' }, {"$set":{"community_id": ''}, {"status": '-1'}}); + return this.userModel.updateMany({community_id: community_id, user_type:'4' }, {"$set":{"community_id": ''}, {"status": '-1'}});*/ + } } diff --git a/web-ui/web-react/src/components/ComunidadViviendas.js b/web-ui/web-react/src/components/ComunidadViviendas.js index 2821bd20..68378ab7 100644 --- a/web-ui/web-react/src/components/ComunidadViviendas.js +++ b/web-ui/web-react/src/components/ComunidadViviendas.js @@ -315,10 +315,8 @@ const Communities = () => { setDeleteCommunitiesDialog(true); }; - const infoCommunity = async (community) => { await tenantsList(community._id); - setCommunity({ ...community }); setCommunityDialog(true); }; @@ -383,40 +381,38 @@ const Communities = () => { ); } - const deleteCommunity = () => { - /* fetch('http://localhost:4000/community/deleteCommunity/' + community._id, { - cache: 'no-cache', - method: 'DELETE', - 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 _community = communities.filter(val => val._id !== community._id); - setCommunities(_community); - setDeleteCommunityDialog(false); - setCommunity(emptyCommunity); - toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 }); - } - ) - .catch( - err => { - console.log('Ocurrió un error con el fetch', err) - toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Comunidad de Viviendas no se pudo eliminar', life: 3000 }); - } - ); - */ + fetch('http://localhost:4000/community/deleteCommunity/' + community._id, { + cache: 'no-cache', + method: 'DELETE', + 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 _community = communities.filter(val => val._id !== community._id); + setCommunities(_community); + setDeleteCommunityDialog(false); + setCommunity(emptyCommunity); + toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 }); + } + ) + .catch( + err => { + console.log('Ocurrió un error con el fetch', err) + toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Comunidad de Viviendas no se pudo eliminar', life: 3000 }); + } + ); let _communities = communitiesList.filter((val) => val._id !== community._id); _communities = _communities.filter( (val) => val.status != -1, From 9da33006d9664dbf97ed0467177845d012c9140d Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 23 Aug 2022 01:08:55 -0600 Subject: [PATCH 02/13] eliminar usuarios, reservaciones y areas --- .../common_areas/common_areas.controller.ts | 22 ++++++---- .../src/common_areas/common_areas.service.ts | 4 ++ .../src/communities/communities.module.ts | 20 +++++++++ .../src/communities/communities.service.ts | 25 +++++++---- .../reservations/reservations.controller.ts | 6 +++ .../src/reservations/reservations.service.ts | 4 ++ .../src/schemas/reservation.schema.ts | 3 ++ servicio-usuarios/src/users/users.service.ts | 6 +-- .../components/AdministradoresComunidad.js | 42 ++++++++++--------- .../src/components/ComunidadViviendas.js | 4 +- 10 files changed, 95 insertions(+), 41 deletions(-) diff --git a/servicio-areas-comunes/src/common_areas/common_areas.controller.ts b/servicio-areas-comunes/src/common_areas/common_areas.controller.ts index 28b5ce7e..b3bdad69 100644 --- a/servicio-areas-comunes/src/common_areas/common_areas.controller.ts +++ b/servicio-areas-comunes/src/common_areas/common_areas.controller.ts @@ -5,7 +5,7 @@ import { CommonAreasService } from './common_areas.service'; @Controller() export class CommonAreasController { - constructor(private readonly commonAreasService: CommonAreasService) {} + constructor(private readonly commonAreasService: CommonAreasService) { } @MessagePattern({ cmd: 'createCommonArea' }) create(@Payload() commonArea: CommonAreaDocument) { @@ -40,11 +40,17 @@ export class CommonAreasController { return this.commonAreasService.findByCommunity(_community_id); } - //cambiar de estado - @MessagePattern({ cmd: 'changeStatus' }) - changeStatus(@Payload() body: string) { - let pid = body['id']; - let pstatus = body['status']; - return this.commonAreasService.changeStatus(pid,pstatus); - } + //cambiar de estado + @MessagePattern({ cmd: 'changeStatus' }) + changeStatus(@Payload() body: string) { + let pid = body['id']; + let pstatus = body['status']; + return this.commonAreasService.changeStatus(pid, pstatus); + } + + @MessagePattern({ cmd: 'removeIdCommunity' }) + removeIdCommunity(@Payload() area: any) { + let community_id = area['community_id']; + return this.commonAreasService.removeIdCommunity(community_id); + } } diff --git a/servicio-areas-comunes/src/common_areas/common_areas.service.ts b/servicio-areas-comunes/src/common_areas/common_areas.service.ts index e617df0c..877bd011 100644 --- a/servicio-areas-comunes/src/common_areas/common_areas.service.ts +++ b/servicio-areas-comunes/src/common_areas/common_areas.service.ts @@ -47,4 +47,8 @@ export class CommonAreasService { }); } + + async removeIdCommunity(community_id: string){ + await this.commonAreaModel.updateMany({community_id: community_id}, {"$set":{"status": '-1'}}); + } } diff --git a/servicio-comunidad-viviendas/src/communities/communities.module.ts b/servicio-comunidad-viviendas/src/communities/communities.module.ts index 8b24e5e1..4e6a9095 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.module.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.module.ts @@ -18,6 +18,26 @@ import { Community, CommunitySchema } from '../schemas/community.schema'; }, }, ]), + ClientsModule.register([ + { + name: 'SERVICIO_AREAS_COMUNES', + transport: Transport.TCP, + options: { + host: '127.0.0.1', + port: 3003, + }, + }, + ]), + ClientsModule.register([ + { + name: 'SERVICIO_RESERVACIONES', + transport: Transport.TCP, + options: { + host: '127.0.0.1', + port: 3006, + }, + }, + ]), MongooseModule.forFeature([ { name: Community.name, schema: CommunitySchema }, ]), diff --git a/servicio-comunidad-viviendas/src/communities/communities.service.ts b/servicio-comunidad-viviendas/src/communities/communities.service.ts index 93f7cbe2..212eeda7 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.service.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.service.ts @@ -14,6 +14,8 @@ export class CommunitiesService { @InjectModel(Community.name) private readonly communityModel: Model, @Inject('SERVICIO_USUARIOS') private readonly clientUserApp: ClientProxy, + @Inject('SERVICIO_AREAS_COMUNES') private readonly clientAreaApp: ClientProxy, + @Inject('SERVICIO_RESERVACIONES') private readonly clientReservationApp: ClientProxy, ) { } async create(community: CommunityDocument): Promise { @@ -81,7 +83,6 @@ export class CommunitiesService { return finalValue['response']; } - async saveTenant(id: string, number_house: string, ptenant_id: string) { let community = await this.findOne(id); await community.houses.map(house => { @@ -98,13 +99,11 @@ export class CommunitiesService { } return house; }) - 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); @@ -115,7 +114,6 @@ export class CommunitiesService { } return house; }) - return await this.communityModel.findOneAndUpdate({ _id: id }, community, { new: true, }); @@ -123,13 +121,24 @@ export class CommunitiesService { async removeIdCommunity(community: string) { const pattern = { cmd: 'removeIdCommunity' }; - const payload = { community_id: community}; + const payload = { community_id: community }; - let callback = await this.clientUserApp + await this.clientUserApp .send(pattern, payload) .pipe(map((response: string) => ({ response }))); - const finalValue = await lastValueFrom(callback); - return finalValue['response']; + const pattern2 = { cmd: 'removeIdCommunity' }; + const payload2 = { community_id: community }; + + await this.clientAreaApp + .send(pattern2, payload2) + .pipe(map((response: string) => ({ response }))); + + const pattern3 = { cmd: 'removeIdCommunity' }; + const payload3 = { community_id: community }; + + await this.clientReservationApp + .send(pattern3, payload3) + .pipe(map((response: string) => ({ response }))); } } diff --git a/servicio-reservaciones/src/reservations/reservations.controller.ts b/servicio-reservaciones/src/reservations/reservations.controller.ts index 49621768..ea6a2553 100644 --- a/servicio-reservaciones/src/reservations/reservations.controller.ts +++ b/servicio-reservaciones/src/reservations/reservations.controller.ts @@ -38,4 +38,10 @@ export class ReservationsController { let _id = id['id']; return this.reservationsService.remove(_id); } + + @MessagePattern({ cmd: 'removeIdCommunity' }) + removeIdCommunity(@Payload() reservation: any) { + let community_id = reservation['community_id']; + return this.reservationsService.removeIdCommunity(community_id); + } } diff --git a/servicio-reservaciones/src/reservations/reservations.service.ts b/servicio-reservaciones/src/reservations/reservations.service.ts index 45382f50..c56174f1 100644 --- a/servicio-reservaciones/src/reservations/reservations.service.ts +++ b/servicio-reservaciones/src/reservations/reservations.service.ts @@ -45,4 +45,8 @@ export class ReservationsService { new: true, }); } + + async removeIdCommunity(community_id: string){ + await this.reservationModel.updateMany({community_id: community_id}, {"$set":{"status": '-1'}}); + } } diff --git a/servicio-reservaciones/src/schemas/reservation.schema.ts b/servicio-reservaciones/src/schemas/reservation.schema.ts index 542eb422..34536ff6 100644 --- a/servicio-reservaciones/src/schemas/reservation.schema.ts +++ b/servicio-reservaciones/src/schemas/reservation.schema.ts @@ -22,6 +22,9 @@ export class Reservation { @Prop() user_id: string; + + @Prop() + community_id: string; } export const ReservationSchema = SchemaFactory.createForClass(Reservation); diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index bc8ea288..6247e26c 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -297,9 +297,9 @@ export class UsersService { } async removeIdCommunity(community_id: string){ - return this.userModel.updateMany({community_id: community_id, user_type:'2' }, {"$set":{"community_id": ''}}); - /*await this.userModel.updateMany({community_id: community_id, user_type:'3' }, {"$set":{"community_id": ''}, {"status": '-1'}}); - return this.userModel.updateMany({community_id: community_id, user_type:'4' }, {"$set":{"community_id": ''}, {"status": '-1'}});*/ + await this.userModel.updateMany({community_id: community_id, user_type:'2' }, {"$set":{"community_id": ''}}); + await this.userModel.updateMany({community_id: community_id, user_type:'3' }, {"$set":{"community_id": '', "status": '-1'}}); + return this.userModel.updateMany({community_id: community_id, user_type:'4' }, {"$set":{"community_id": '', "status": '-1'}}); } } diff --git a/web-ui/web-react/src/components/AdministradoresComunidad.js b/web-ui/web-react/src/components/AdministradoresComunidad.js index 0ec73891..e58be62a 100644 --- a/web-ui/web-react/src/components/AdministradoresComunidad.js +++ b/web-ui/web-react/src/components/AdministradoresComunidad.js @@ -66,13 +66,18 @@ const AdministradoresComunidad = () => { item.status_text = 'Eliminado'; } //item.full_name returns the repositorie name - return fetch(`http://localhost:4000/community/findCommunityName/${item.community_id}`, { method: 'GET' }) - .then((response2) => response2.json()) - .then(data => data.message) - .then(data => { - item.community_name = data['name'] - return item - }) + if (item.community_id || item.community_id != '') { + return fetch(`http://localhost:4000/community/findCommunityName/${item.community_id}`, { method: 'GET' }) + .then((response2) => response2.json()) + .then(data => data.message) + .then(data => { + item.community_name = data['name'] + return item + }) + } else { + item.community_name = "Sin Comunidad Asignada"; + return item; + } })); }) .then(data => { @@ -86,9 +91,6 @@ const AdministradoresComunidad = () => { } - - - async function getCommunites() { let response = await fetch('http://localhost:4000/community/allCommunities', { method: 'GET' }) .then((response) => response.json()) @@ -151,22 +153,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); diff --git a/web-ui/web-react/src/components/ComunidadViviendas.js b/web-ui/web-react/src/components/ComunidadViviendas.js index 68378ab7..a401fd17 100644 --- a/web-ui/web-react/src/components/ComunidadViviendas.js +++ b/web-ui/web-react/src/components/ComunidadViviendas.js @@ -400,8 +400,8 @@ const Communities = () => { .then( function (response) { - let _community = communities.filter(val => val._id !== community._id); - setCommunities(_community); + let _community = communitiesList.filter(val => val._id !== community._id); + setCommunitiesList(_community); setDeleteCommunityDialog(false); setCommunity(emptyCommunity); toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 }); From f3ba61f060bb1e63675bf67a567493460485ca33 Mon Sep 17 00:00:00 2001 From: Mariela Date: Tue, 23 Aug 2022 11:48:55 -0600 Subject: [PATCH 03/13] listar reservaciones --- api-gateway/src/app.controller.ts | 8 + api-gateway/src/app.service.ts | 21 +- .../reservations/reservations.controller.ts | 6 + .../src/reservations/reservations.service.ts | 5 + web-ui/web-react/src/App.js | 3 + .../src/components/AdministradoresSistema.js | 16 - .../web-react/src/components/Reservaciones.js | 353 ++++++++++++++++++ 7 files changed, 390 insertions(+), 22 deletions(-) create mode 100644 web-ui/web-react/src/components/Reservaciones.js diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 4def7296..f94949ec 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -451,6 +451,7 @@ export class AppController { @Body('date_entry') date_entry: Date, @Body('user_id') user_id: string, @Body('common_area_id') common_area_id: string, + @Body('community_id') community_id: string, ) { return this.appService.createReservation( start_time, @@ -459,6 +460,7 @@ export class AppController { date_entry, user_id, common_area_id, + community_id ); } @@ -472,6 +474,12 @@ export class AppController { return this.appService.findReservation(paramReservation); } + @Get('reservation/findReservations/:id') + findReservations(@Param('id') community_id: string) { + return this.appService.findReservations(community_id); + } + + // #==== API Post @Post('post/createPost') diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index fbe5a423..ffecae20 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -287,12 +287,12 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } - updateAdminSystem(_id: string, dni: string, name: string, + 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, + _id: _id, dni: dni, name: name, last_name: last_name, email: email, phone: phone }; return this.clientUserApp @@ -415,7 +415,7 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } - + // ====================== COMMON AREAS =============================== //POST parameter from API createCommonArea( @@ -567,11 +567,12 @@ export class AppService { //POST parameter from API createReservation(start_time: string, finish_time: string, status: string, - date_entry: Date, user_id: string, common_area_id: string) { + date_entry: Date, user_id: string, common_area_id: string, community_id: string) { const pattern = { cmd: 'createReservation' }; const payload = { start_time: start_time, finish_time: finish_time, status: status, - date_entry: date_entry, user_id: user_id, common_area_id: common_area_id + date_entry: date_entry, user_id: user_id, common_area_id: common_area_id, + community_id: community_id }; return this.clientReservationApp .send(pattern, payload) @@ -595,6 +596,14 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + findReservations(community_id: string) { + const pattern = { cmd: 'findReservationsByCommunity' }; + const payload = { community_id: community_id }; + return this.clientReservationApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + // ====================== POSTS =============================== //POST parameter from API diff --git a/servicio-reservaciones/src/reservations/reservations.controller.ts b/servicio-reservaciones/src/reservations/reservations.controller.ts index ea6a2553..5089ba2b 100644 --- a/servicio-reservaciones/src/reservations/reservations.controller.ts +++ b/servicio-reservaciones/src/reservations/reservations.controller.ts @@ -28,6 +28,12 @@ export class ReservationsController { return this.reservationsService.findOne(_id); } + @MessagePattern({ cmd: 'findReservationsByCommunity' }) + findReservationsByCommunity(@Payload() body: string) { + let community_id = body['community_id']; + return this.reservationsService.findReservationsByCommunity(community_id); + } + @MessagePattern({ cmd: 'updateReservation' }) update(@Payload() reservation: ReservationDocument) { return this.reservationsService.update(reservation.id, reservation); diff --git a/servicio-reservaciones/src/reservations/reservations.service.ts b/servicio-reservaciones/src/reservations/reservations.service.ts index c56174f1..ce338270 100644 --- a/servicio-reservaciones/src/reservations/reservations.service.ts +++ b/servicio-reservaciones/src/reservations/reservations.service.ts @@ -49,4 +49,9 @@ export class ReservationsService { async removeIdCommunity(community_id: string){ await this.reservationModel.updateMany({community_id: community_id}, {"$set":{"status": '-1'}}); } + + + async findReservationsByCommunity(community_id: string){ + return this.reservationModel.find({ community_id: community_id }).exec(); + } } diff --git a/web-ui/web-react/src/App.js b/web-ui/web-react/src/App.js index 1551381d..164aaa17 100644 --- a/web-ui/web-react/src/App.js +++ b/web-ui/web-react/src/App.js @@ -56,6 +56,7 @@ import AreasComunes from './components/AreasComunes'; import { useCookies } from "react-cookie"; import LogInUser from './components/LogInUser'; import Page404 from './components/Page404' +import Reservaciones from './components/Reservaciones'; const App = () => { @@ -202,6 +203,7 @@ const App = () => { to: '/areasComunes', }, + { label: 'Reservaciones', icon: PrimeIcons.CALENDAR, to: '/reservaciones'}, { label: 'Comunicados', icon: PrimeIcons.COMMENTS, to: '/registroComunicado'}, ] @@ -467,6 +469,7 @@ const App = () => { + ) diff --git a/web-ui/web-react/src/components/AdministradoresSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js index 6fa70310..b7ea79f1 100644 --- a/web-ui/web-react/src/components/AdministradoresSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -108,8 +108,6 @@ const AdministradoresSistema = () => { } else { if (_admin._id) { - - fetch('http://localhost:4000/user/updateAdminSystem/', { cache: 'no-cache', method: 'POST', @@ -145,15 +143,7 @@ const AdministradoresSistema = () => { .catch( err => console.log('Ocurrió un error con el fetch', err) ); - - - - - - } else { - - fetch('http://localhost:4000/user/createAdminSystem/', { cache: 'no-cache', method: 'POST', @@ -181,12 +171,6 @@ const AdministradoresSistema = () => { ); } } - - - - - - } else { setSubmitted(true); diff --git a/web-ui/web-react/src/components/Reservaciones.js b/web-ui/web-react/src/components/Reservaciones.js new file mode 100644 index 00000000..06be073d --- /dev/null +++ b/web-ui/web-react/src/components/Reservaciones.js @@ -0,0 +1,353 @@ +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'; +import { Dialog } from 'primereact/dialog'; +import { Toolbar } from 'primereact/toolbar'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faHome, faUserAlt } from '@fortawesome/free-solid-svg-icons'; +import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons'; +import { faClockFour } from '@fortawesome/free-solid-svg-icons'; +import { useCookies } from 'react-cookie'; + +const Reservations = () => { + let emptyReservation = { + _id: null, + start_time: '', + finish_time: '', + user_id: '', + user_name: '', + common_area_id: '', + common_area_name: '', + community_id: '', + status: '1', + status_text: '', + date_entry: new Date(), + }; + + + const [reservations, setReservations] = useState([]); + const [reservation, setReservation] = useState(emptyReservation); + const [submitted, setSubmitted] = useState(false); + const [selectedReservations, setSelectedReservations] = useState(null); + const [globalFilter, setGlobalFilter] = useState(null); + const [deleteReservationDialog, setDeleteReservationDialog] = useState(false); + const [deleteReservationsDialog, setDeleteReservationsDialog] = useState(false); + const toast = useRef(null); + const dt = useRef(null); + const [cookies, setCookies] = useCookies() + const [areas, setAreas] = useState([]); + const [tenants, setTenants] = useState([]); + + async function tenantsList(id) { + await fetch(`http://localhost:4000/user/findTenants/${id}`, + { method: 'GET' }) + .then((response) => response.json()) + .then(data => data.message) + .then(data => { + data = data.filter( + (val) => val.status != -1, + ) + data = data.map(item => { + item.password = ''; + return item; + }) + setTenants(data) + }); + } + + async function areasList(id) { + await fetch(`http://localhost:4000/commonArea/findByCommunity/${id}`, + { method: 'GET' }) + .then((response) => response.json()) + .then(data => data.message) + .then(data => { + data = data.filter( + (val) => val.status != -1, + ) + setAreas(data) + }); + } + + async function reservationList(id) { + await fetch(`http://localhost:4000/reservation/findReservations/${id}`, + { method: 'GET' }) + .then((response) => response.json()) + .then(data => data.message) + .then(data => { + data = data.filter( + (val) => val.status != -1, + ) + data.map((item) => { + if (item.status == '1') { + item.status_text = 'Activo'; + } else if (item.status == '0') { + item.status_text = 'Inactivo'; + } + tenants.find((item2) => item2._id == item.user_id); + }) + + setReservations(data) + }); + } + + useEffect(() => { + tenantsList(cookies.community_id); + }, []) + + useEffect(() => { + areasList(cookies.community_id); + }, []) + + + tenants.map((item) => { + + }); + + + useEffect(() => { + reservationList(cookies.community_id); + }, []) + + + + + const actionsReservation = (rowData) => { + + + return ( +
+
+ ); + }; + + + + const confirmDeleteReservation = (reservation) => { + setReservation(reservation); + setDeleteReservationDialog(true); + }; + + const confirmDeleteSelected = () => { + setDeleteReservationsDialog(true); + }; + + const leftToolbarTemplate = () => { + return ( + +
+
+
+ ); + }; + + const rightToolbarTemplate = () => { + return ( + +