agregar numero de vivienda a inquilino

This commit is contained in:
Mariela 2022-08-16 16:36:06 -06:00
parent 6d6fafd177
commit ff5c6e55ff
4 changed files with 73 additions and 5 deletions

View File

@ -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(

View File

@ -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<string>(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(

View File

@ -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<string>(pattern, payload)
.pipe(
map((response: string) => ({ response }))
)
const finalValue = await lastValueFrom(callback);
const response = finalValue['response'];
const houses = response['houses'];
return houses;
}
}

View File

@ -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 = () => {
<Dropdown
required
id='numero_vivienda'
value={communityId}
options={cList}
onChange={(e) => setCommunityId(e.value)}
value={houseId}
options={hList}
onChange={(e) => setHouseId(e.value)}
/>
</div>
<Button label='Registrar' onClick={registrarInquilino} />