corregir agregar inquilino a comunidad
This commit is contained in:
parent
85e44d8c92
commit
c8da611700
|
@ -57,6 +57,7 @@ export class CommunitiesController {
|
||||||
|
|
||||||
@MessagePattern({ cmd: 'saveTenant' })
|
@MessagePattern({ cmd: 'saveTenant' })
|
||||||
saveTenant(@Payload() body: string) {
|
saveTenant(@Payload() body: string) {
|
||||||
|
|
||||||
let id = body['_id'];
|
let id = body['_id'];
|
||||||
let tenant_id = body['tenant_id'];
|
let tenant_id = body['tenant_id'];
|
||||||
let number_house = body['number_house'];
|
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 { from, lastValueFrom, map, scan, mergeMap } from 'rxjs';
|
||||||
import { Admin } from 'src/schemas/admin.entity';
|
import { Admin } from 'src/schemas/admin.entity';
|
||||||
import { appendFileSync } from 'fs';
|
import { appendFileSync } from 'fs';
|
||||||
|
import { Tenant, TenantSchema } from 'src/schemas/tenant.schema';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CommunitiesService {
|
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);
|
let community = await this.findOne(id);
|
||||||
|
|
||||||
|
console.log(ptenant_id)
|
||||||
|
|
||||||
await community.houses.map(house => {
|
await community.houses.map(house => {
|
||||||
if(house.number_house == number_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"
|
house.state = "ocupada"
|
||||||
}
|
}
|
||||||
return house;
|
return house;
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(community.houses)
|
|
||||||
|
|
||||||
return await this.communityModel.findOneAndUpdate({ _id: id }, community, {
|
return await this.communityModel.findOneAndUpdate({ _id: id }, community, {
|
||||||
new: true,
|
new: true,
|
||||||
});
|
});
|
||||||
|
@ -105,8 +122,8 @@ export class CommunitiesService {
|
||||||
let community = await this.findOne(id);
|
let community = await this.findOne(id);
|
||||||
|
|
||||||
await community.houses.map(house => {
|
await community.houses.map(house => {
|
||||||
if(house.number_house == number_house &&
|
if (house.number_house == number_house &&
|
||||||
house.tenants.tenant_id == tenant_id){
|
house.tenants.tenant_id == tenant_id) {
|
||||||
house.tenants = null;
|
house.tenants = null;
|
||||||
house.state = "desocupada"
|
house.state = "desocupada"
|
||||||
|
|
||||||
|
|
|
@ -393,7 +393,7 @@
|
||||||
{{date_entry}}</h4>
|
{{date_entry}}</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="text" style="padding: 0 4em; text-align: left;">
|
<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>
|
||||||
<div class="text" style="padding: 0 4em; text-align: left;">
|
<div class="text" style="padding: 0 4em; text-align: left;">
|
||||||
|
|
|
@ -133,7 +133,7 @@ export class UsersController {
|
||||||
|
|
||||||
@MessagePattern({ cmd: 'deleteTenant' })
|
@MessagePattern({ cmd: 'deleteTenant' })
|
||||||
deleteTenant(@Payload() user: any) {
|
deleteTenant(@Payload() user: any) {
|
||||||
return this.userService.deleteTenant(user['id']);
|
return this.userService.deleteTenant(user['_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@MessagePattern({ cmd: 'changeStatus' })
|
@MessagePattern({ cmd: 'changeStatus' })
|
||||||
|
|
|
@ -28,9 +28,12 @@ export class UsersService {
|
||||||
let password = user.password;
|
let password = user.password;
|
||||||
let passwordEncriptada = Md5.init(user.password);
|
let passwordEncriptada = Md5.init(user.password);
|
||||||
user.password = passwordEncriptada;
|
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);
|
let community = await this.findCommunity(user.community_id);
|
||||||
user.community_id = community['name'];
|
user.community_id = community['name'];
|
||||||
|
@ -39,7 +42,7 @@ export class UsersService {
|
||||||
const payload = {
|
const payload = {
|
||||||
email: user['email'], password: password, name: user['name'],
|
email: user['email'], password: password, name: user['name'],
|
||||||
date_entry: user['date_entry'], community_name: community['name'],
|
date_entry: user['date_entry'], community_name: community['name'],
|
||||||
number_house:['number_house']
|
number_house: user['number_house']
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.clientNotificationtApp
|
return this.clientNotificationtApp
|
||||||
|
|
|
@ -137,11 +137,9 @@ const Inquilinos = () => {
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (_tenant.status === '1') {
|
if (_tenant.status === '1') {
|
||||||
_tenant.status = '0'
|
|
||||||
_tenant.status_text = 'Inactivo'
|
|
||||||
} else if (_tenant.status === '0') {
|
|
||||||
_tenant.status = '1'
|
|
||||||
_tenant.status_text = 'Activo'
|
_tenant.status_text = 'Activo'
|
||||||
|
} else if (_tenant.status === '0') {
|
||||||
|
_tenant.status_text = 'Inactivo'
|
||||||
}
|
}
|
||||||
_tenants.push(_tenant)
|
_tenants.push(_tenant)
|
||||||
toast.current.show({
|
toast.current.show({
|
||||||
|
|
Loading…
Reference in New Issue