Merge branch 'agregaNumeroViviendaRegistroInquilino' into US-42-EliminarInquilino

This commit is contained in:
Mariela 2022-08-22 12:22:15 -06:00
commit b6b21a19c7
6 changed files with 96 additions and 7 deletions

View File

@ -261,7 +261,21 @@ export class AppController {
return this.appService.changeStatusCommunity(pId, pStatus); 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 // #==== API Common Areas
@Post('commonArea/createCommonArea') @Post('commonArea/createCommonArea')
createCommonArea( createCommonArea(

View File

@ -1,6 +1,7 @@
import { Injectable, Inject } from '@nestjs/common'; import { Injectable, Inject } from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices'; import { ClientProxy } from '@nestjs/microservices';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { lastValueFrom } from 'rxjs';
@Injectable() @Injectable()
export class AppService { export class AppService {
@ -337,6 +338,31 @@ export class AppService {
.pipe(map((message: string) => ({ message }))); .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;
}
saveTenant(id: string, number_house: string, tenant_id: string) {
const pattern = { cmd: 'saveTenant' };
const payload = { _id: id, number_house: number_house, tenant_id: tenant_id };
return this.clientCommunityApp
.send<string>(pattern, payload)
.pipe(map((message: string) => ({ message })));
}
// ====================== COMMON AREAS =============================== // ====================== COMMON AREAS ===============================
//POST parameter from API //POST parameter from API
createCommonArea( createCommonArea(

View File

@ -53,4 +53,13 @@ export class CommunitiesController {
let pstatus = body['status']; let pstatus = body['status'];
return this.communitiesService.changeStatus(pid,pstatus); return this.communitiesService.changeStatus(pid,pstatus);
} }
@MessagePattern({ cmd: 'saveTenant' })
saveTenant(@Payload() body: string) {
let id = body['_id'];
let tenant_id = body['tenant_id'];
let number_house = body['number_house'];
return this.communitiesService.saveTenant(id, number_house, tenant_id);
}
} }

View File

@ -13,7 +13,7 @@ export class CommunitiesService {
@InjectModel(Community.name) @InjectModel(Community.name)
private readonly communityModel: Model<CommunityDocument>, private readonly communityModel: Model<CommunityDocument>,
@Inject('SERVICIO_USUARIOS') private readonly clientUserApp: ClientProxy, @Inject('SERVICIO_USUARIOS') private readonly clientUserApp: ClientProxy,
) {} ) { }
async create(community: CommunityDocument): Promise<Community> { async create(community: CommunityDocument): Promise<Community> {
return this.communityModel.create(community); return this.communityModel.create(community);
@ -56,15 +56,15 @@ export class CommunitiesService {
} }
async remove(id: string) { async remove(id: string) {
return this.communityModel.findOneAndUpdate({ _id: id }, {status: '-1'}, { return this.communityModel.findOneAndUpdate({ _id: id }, { status: '-1' }, {
new: true, new: true,
}); });
} }
async changeStatus(id: string, status: string) { async changeStatus(id: string, status: string) {
return this.communityModel.findOneAndUpdate({ _id: id }, {status: status}, { return this.communityModel.findOneAndUpdate({ _id: id }, { status: status }, {
new: true, new: true,
}); });
} }
async findCommunityAdmin(community: string, user_type: string) { async findCommunityAdmin(community: string, user_type: string) {
@ -78,4 +78,23 @@ export class CommunitiesService {
const finalValue = await lastValueFrom(callback); const finalValue = await lastValueFrom(callback);
return finalValue['response']; return finalValue['response'];
} }
async saveTenant(id: string, number_house: string, tenant_id: string) {
let community = await this.findOne(id);
await community.houses.map(house => {
if(house.number_house == number_house){
house.tenants.tenant_id = tenant_id
}
return house;
})
console.log(community.houses)
return await this.communityModel.findOneAndUpdate({ _id: id }, community, {
new: true,
});
}
} }

View File

@ -145,7 +145,6 @@ export class UsersService {
return await this.userModel.find({ community_id: pcommunity_id, user_type: 4 }) return await this.userModel.find({ community_id: pcommunity_id, user_type: 4 })
} }
async testSendMail(user: UserDocument) { async testSendMail(user: UserDocument) {
let passwordEncriptada = Md5.init(user.password); let passwordEncriptada = Md5.init(user.password);
user.password = passwordEncriptada; user.password = passwordEncriptada;
@ -231,5 +230,17 @@ export class UsersService {
new: true, new: true,
}); });
} }
async saveTenantNumHouse(community_id: string, number_house:string, tenant_id: string) {
const pattern = { cmd: 'saveTenant' }
const payload = { _id: community_id, number_house: number_house, tenant_id: tenant_id }
return await this.clientCommunityApp
.send<string>(pattern, payload)
.pipe(
map((response: string) => ({ response }))
)
}
} }

View File

@ -93,6 +93,16 @@ const Inquilinos = () => {
) )
} }
async function getHouses() {
let response = await fetch(
`http://localhost:4000/community/findHousesCommunity/${cookies.community_id}`,
{ method: 'GET' },
)
let resList = await response.json()
setHousesList(await resList)
}
useEffect(() => { useEffect(() => {
tenantsList() tenantsList()
}, []) }, [])