From d95ffb385304e26afdbba50ba4f2f1966b8fe9d9 Mon Sep 17 00:00:00 2001 From: Traym17 <51390112+Traym17@users.noreply.github.com> Date: Tue, 30 Aug 2022 22:50:34 -0600 Subject: [PATCH] Pantallas guarda de seguridad Lista de invitados y comunicados por la comunidad a la que el guarda corresponde --- api-gateway/src/app.controller.ts | 11 ++++- api-gateway/src/app.service.ts | 16 +++++++ mobile-ui/components/CommentCard/index.js | 12 +++--- mobile-ui/components/Home.js | 39 +++++++++++------ mobile-ui/components/Invitados.js | 42 ++++++++++++------- .../post-comments/post-comments.controller.ts | 6 +++ .../post-comments/post-comments.service.ts | 5 +++ .../src/posts/posts.controller.ts | 5 +++ .../src/posts/posts.service.ts | 5 +++ .../src/guests/guests.controller.ts | 5 +++ .../src/guests/guests.service.ts | 6 ++- 11 files changed, 115 insertions(+), 37 deletions(-) diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index eaf4e71f..f865c1fd 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -433,6 +433,12 @@ export class AppController { findGuestUser(@Param('id') paramGuestId: string) { return this.appService.findGuestUser(paramGuestId); } + + @Get('guest/findGuestCommunity/:id') + findGuestCommunityr(@Param('id') paramGuestId: string) { + return this.appService.findGuestCommunityr(paramGuestId); + } + @Post('guest/updateGuest') updateGuest( @Body('_id') _id: string){ @@ -523,7 +529,10 @@ export class AppController { allPosts() { return this.appService.allPosts(); } - + @Get('post/findPostCommunity/:id') + findPostCommunity(@Param('id') paramPost: string) { + return this.appService.findPostCommunity(paramPost); + } @Get('post/find/:id') findPost(@Param('id') paramPost: string) { return this.appService.findPost(paramPost); diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 73077be2..605c4688 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -549,6 +549,14 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + findGuestCommunityr(paramGuestId: string) { + const pattern = { cmd: 'findGuestCommunity' }; + const payload = { id: paramGuestId }; + return this.clientGuestApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + updateGuest(_id: string ) { const pattern = { cmd: 'removeGuest' }; @@ -655,6 +663,14 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + findPostCommunity(paramGuestId: string) { + const pattern = { cmd: 'findPostCommunity' }; + const payload = { id: paramGuestId }; + return this.clientPostApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + //GET parameter from API findPost(paramPostId: string) { const pattern = { cmd: 'findOnePost' }; diff --git a/mobile-ui/components/CommentCard/index.js b/mobile-ui/components/CommentCard/index.js index 15b9143d..32e2f0a2 100644 --- a/mobile-ui/components/CommentCard/index.js +++ b/mobile-ui/components/CommentCard/index.js @@ -8,8 +8,8 @@ import PropTypes from 'prop-types'; import React from 'react'; -export const CommentCard = ({ date, comment }) => { - const dateFormated = format(new Date(date), "dd LL yyyy") +export const CommentCard = ({ post }) => { + //const dateFormated = format(new Date(date), "dd LL yyyy") return ( { - {dateFormated} + Administrador de Comunidad - {comment} + {post} @@ -46,6 +46,6 @@ export const CommentCard = ({ date, comment }) => { } CommentCard.propTypes = { - date: PropTypes.string.isRequired, - comment: PropTypes.string.isRequired, + // date: PropTypes.string.isRequired, + post: PropTypes.string.isRequired, } diff --git a/mobile-ui/components/Home.js b/mobile-ui/components/Home.js index 52df0632..b4577071 100644 --- a/mobile-ui/components/Home.js +++ b/mobile-ui/components/Home.js @@ -8,7 +8,10 @@ export default function Home() { const { user } = useContext(UserContext) const [isRequesting, setIsRequesting] = useState(false); const [comments, setComments] = useState([]); - + const user_type=user.user_type; + //const user_type="4"; + const community_id=user.community_id; + //const community_id="1"; useEffect(() => { console.log(user); @@ -17,17 +20,27 @@ export default function Home() { setIsRequesting(true); try { - const jsonResponse = await fetch(`${API.BASE_URL}/post/allComments`, { - method: "GET", - headers: { - 'Content-Type': 'application/json' - } - }) + if(user_type=="4"){ + const jsonResponse = await fetch(`${API.BASE_URL}/post/findPostCommunity/`+`${community_id}`, { + method: "GET", + headers: { + 'Content-Type': 'application/json' + } + }) + const response = await jsonResponse.json(); + setComments(response.message); - const response = await jsonResponse.json(); - // console.log(response); - - setComments(response.message); + }else{ + const jsonResponse = await fetch(`${API.BASE_URL}/post/allPosts`, { + method: "GET", + headers: { + 'Content-Type': 'application/json' + } + }) + + const response = await jsonResponse.json(); + setComments(response.message); + } } catch (error) { @@ -55,8 +68,8 @@ export default function Home() { comments.map(item => ( )) } diff --git a/mobile-ui/components/Invitados.js b/mobile-ui/components/Invitados.js index 2fdfaf75..b43a1afc 100644 --- a/mobile-ui/components/Invitados.js +++ b/mobile-ui/components/Invitados.js @@ -15,6 +15,10 @@ export default function Invitados({navigation}) { const { user } = useContext(UserContext); const id = user._id; //const id = "6301df20dac7dcf76dcecade"; + const user_type=user.user_type; + //const user_type="4"; + //const community_id="1"; + const community_id=user.community_id; const [invitado, setInvitado] = useState([]); useEffect(() => { @@ -23,17 +27,27 @@ export default function Invitados({navigation}) { setIsRequesting(true); try { - const jsonResponse = await fetch(`${API.BASE_URL}/guest/findGuestUser/`+`${id}`, { - method: "GET", - headers: { - 'Content-Type': 'application/json' - } - }) - - const response = await jsonResponse.json(); - //console.log(response); - setInvitados(response.message); - + if(user_type=="4"){ + const jsonResponse = await fetch(`${API.BASE_URL}/guest/findGuestCommunity/`+`${community_id}`, { + method: "GET", + headers: { + 'Content-Type': 'application/json' + } + }) + + const response = await jsonResponse.json(); + setInvitados(response.message); + }else{ + const jsonResponse = await fetch(`${API.BASE_URL}/guest/findGuestUser/`+`${id}`, { + method: "GET", + headers: { + 'Content-Type': 'application/json' + } + }) + + const response = await jsonResponse.json(); + setInvitados(response.message); + } } catch (error) { } @@ -118,13 +132,9 @@ export default function Invitados({navigation}) { - {deleteInvitado(item._id)}} /> + {user_type == 3 && {deleteInvitado(item._id)}} />} } keyExtractor={item => item.id} /> - - - - diff --git a/servicio-foro-comunicaciones/src/post-comments/post-comments.controller.ts b/servicio-foro-comunicaciones/src/post-comments/post-comments.controller.ts index 14113432..3df3c1c4 100644 --- a/servicio-foro-comunicaciones/src/post-comments/post-comments.controller.ts +++ b/servicio-foro-comunicaciones/src/post-comments/post-comments.controller.ts @@ -33,4 +33,10 @@ export class PostCommentsController { let _id = id['id']; return this.postCommentsService.remove(_id); } + + @MessagePattern({ cmd: 'findCommentCommunity' }) + findPostCommunity(@Payload() id: string) { + let _id = id['id']; + return this.postCommentsService.findPostCommunity(_id); + } } diff --git a/servicio-foro-comunicaciones/src/post-comments/post-comments.service.ts b/servicio-foro-comunicaciones/src/post-comments/post-comments.service.ts index f82b71fa..9351aa7f 100644 --- a/servicio-foro-comunicaciones/src/post-comments/post-comments.service.ts +++ b/servicio-foro-comunicaciones/src/post-comments/post-comments.service.ts @@ -37,4 +37,9 @@ export class PostCommentsService { new: true, }); } + + async findPostCommunity(id: string): Promise { + console.log(id); + return this.commentModel.find({community_id:id}).setOptions({ sanitizeFilter: true }).exec(); + } } diff --git a/servicio-foro-comunicaciones/src/posts/posts.controller.ts b/servicio-foro-comunicaciones/src/posts/posts.controller.ts index 9872892c..90706065 100644 --- a/servicio-foro-comunicaciones/src/posts/posts.controller.ts +++ b/servicio-foro-comunicaciones/src/posts/posts.controller.ts @@ -33,4 +33,9 @@ export class PostsController { let _id = id['id']; return this.postsService.remove(_id); } + @MessagePattern({ cmd: 'findPostCommunity' }) + findPostCommunity(@Payload() id: string) { + let _id = id['id']; + return this.postsService.findPostCommunity(_id); + } } diff --git a/servicio-foro-comunicaciones/src/posts/posts.service.ts b/servicio-foro-comunicaciones/src/posts/posts.service.ts index 7423aec2..30fe438e 100644 --- a/servicio-foro-comunicaciones/src/posts/posts.service.ts +++ b/servicio-foro-comunicaciones/src/posts/posts.service.ts @@ -30,4 +30,9 @@ export class PostsService { async remove(id: string) { return this.postModel.findByIdAndRemove({ _id: id }).exec(); } + + async findPostCommunity(id: string): Promise { + console.log(id); + return this.postModel.find({community_id:id}).setOptions({ sanitizeFilter: true }).exec(); + } } diff --git a/servicio-invitados/src/guests/guests.controller.ts b/servicio-invitados/src/guests/guests.controller.ts index 3e306f6e..2b750ba9 100644 --- a/servicio-invitados/src/guests/guests.controller.ts +++ b/servicio-invitados/src/guests/guests.controller.ts @@ -20,6 +20,11 @@ export class GuestsController { findGuestUser(@Payload() id: string) { return this.guestsService.findGuestUser(id); } + @MessagePattern({ cmd: 'findGuestCommunity' }) + findGuestCommunity(@Payload() id: string) { + let _id = id['id']; + return this.guestsService.findGuestCommunity(_id); + } @MessagePattern({ cmd: 'findOneGuest' }) findOneById(@Payload() id: string) { let _id = id['_id']; diff --git a/servicio-invitados/src/guests/guests.service.ts b/servicio-invitados/src/guests/guests.service.ts index 87da8833..f2343b7e 100644 --- a/servicio-invitados/src/guests/guests.service.ts +++ b/servicio-invitados/src/guests/guests.service.ts @@ -18,10 +18,14 @@ export class GuestsService { } async findGuestUser(id: string): Promise { - console.log(id); return this.guestModel.find({_tenant_id:id, status:"1"}).setOptions({ sanitizeFilter: true }).exec(); } + async findGuestCommunity(id: string): Promise { + console.log(id); + return this.guestModel.find({community_id:id}).setOptions({ sanitizeFilter: true }).exec(); + } + findOneId(id: string): Promise { return this.guestModel.findOne({ _id: id }).exec(); }