corregir agregar inquilino a comunidad
This commit is contained in:
parent
85e44d8c92
commit
c8da611700
|
@ -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'];
|
||||
|
|
|
@ -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.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,
|
||||
});
|
||||
|
|
|
@ -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' })
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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({
|
||||
|
|
Loading…
Reference in New Issue