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)} />