corregir agregar inquilino a comunidad

This commit is contained in:
Mariela 2022-08-22 14:58:43 -06:00
parent 85e44d8c92
commit c8da611700
6 changed files with 40 additions and 21 deletions

View File

@ -57,6 +57,7 @@ export class CommunitiesController {
@MessagePattern({ cmd: 'saveTenant' })
saveTenant(@Payload() body: string) {
let id = body['_id'];
let tenant_id = body['tenant_id'];
let number_house = body['number_house'];

View File

@ -6,6 +6,7 @@ import { RpcException, ClientProxy } from '@nestjs/microservices';
import { from, lastValueFrom, map, scan, mergeMap } from 'rxjs';
import { Admin } from 'src/schemas/admin.entity';
import { appendFileSync } from 'fs';
import { Tenant, TenantSchema } from 'src/schemas/tenant.schema';
@Injectable()
export class CommunitiesService {
@ -80,20 +81,36 @@ export class CommunitiesService {
}
async saveTenant(id: string, number_house: string, tenant_id: string) {
async saveTenant(id: string, number_house: string, ptenant_id: string) {
let community = await this.findOne(id);
console.log(ptenant_id)
await community.houses.map(house => {
if(house.number_house == number_house){
house.tenants.tenant_id = tenant_id
if (house.number_house == number_house) {
if (house.tenants) {
console.log(house.tenants.tenant_id + '1')
house.tenants.tenant_id = ptenant_id
console.log(house.tenants.tenant_id + '1')
console.log(house.tenants + '1')
} else {
let tenant = new Tenant()
tenant.tenant_id = ptenant_id;
console.log(tenant)
house.tenants = tenant;
console.log(house.tenants + '2')
}
console.log(house.tenants + '3')
house.state = "ocupada"
}
return house;
})
console.log(community.houses)
return await this.communityModel.findOneAndUpdate({ _id: id }, community, {
new: true,
});
@ -105,8 +122,8 @@ export class CommunitiesService {
let community = await this.findOne(id);
await community.houses.map(house => {
if(house.number_house == number_house &&
house.tenants.tenant_id == tenant_id){
if (house.number_house == number_house &&
house.tenants.tenant_id == tenant_id) {
house.tenants = null;
house.state = "desocupada"

View File

@ -393,7 +393,7 @@
{{date_entry}}</h4>
</div>
<div class="text" style="padding: 0 4em; text-align: left;">
<p>Fue asignado en la comunidad {{community_name}} en la vivienda #{{number_house}}</p>
<p>Fue asignado en la comunidad {{community_name}} en la vivienda # {{number_house}}</p>
</div>
<div class="text" style="padding: 0 4em; text-align: left;">

View File

@ -133,7 +133,7 @@ export class UsersController {
@MessagePattern({ cmd: 'deleteTenant' })
deleteTenant(@Payload() user: any) {
return this.userService.deleteTenant(user['id']);
return this.userService.deleteTenant(user['_id']);
}
@MessagePattern({ cmd: 'changeStatus' })

View File

@ -28,9 +28,12 @@ export class UsersService {
let password = user.password;
let passwordEncriptada = Md5.init(user.password);
user.password = passwordEncriptada;
this.userModel.create(user)
let userCreated = await this.userModel.create(user);
console.log(await userCreated);
let callback = await this.saveTenantNumHouse(user.community_id, user.number_house, userCreated['_id']);
await this.saveTenantNumHouse(user.community_id, user.number_house, user._id);
const finalValue = await lastValueFrom(callback);
const response = await finalValue['response'];
let community = await this.findCommunity(user.community_id);
user.community_id = community['name'];
@ -39,7 +42,7 @@ export class UsersService {
const payload = {
email: user['email'], password: password, name: user['name'],
date_entry: user['date_entry'], community_name: community['name'],
number_house:['number_house']
number_house: user['number_house']
};
return this.clientNotificationtApp

View File

@ -137,11 +137,9 @@ const Inquilinos = () => {
})
.then(() => {
if (_tenant.status === '1') {
_tenant.status = '0'
_tenant.status_text = 'Inactivo'
} else if (_tenant.status === '0') {
_tenant.status = '1'
_tenant.status_text = 'Activo'
} else if (_tenant.status === '0') {
_tenant.status_text = 'Inactivo'
}
_tenants.push(_tenant)
toast.current.show({