fix error inquilinos
This commit is contained in:
parent
11ac9b0232
commit
1784dd4bbb
|
@ -1,4 +1,5 @@
|
||||||
import { Controller, Get, Post, Put, Body, Param, Delete } from '@nestjs/common';
|
import { Controller, Get, Post, Put, Body, Param, Delete } from '@nestjs/common';
|
||||||
|
import { Console } from 'console';
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
@Controller()
|
@Controller()
|
||||||
export class AppController {
|
export class AppController {
|
||||||
|
@ -305,6 +306,30 @@ export class AppController {
|
||||||
return this.appService.updateAdminSystem(_id, dni, name, last_name, email, phone);
|
return this.appService.updateAdminSystem(_id, dni, name, last_name, email, phone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Put('user/updateTenant/:id')
|
||||||
|
updateTenant(
|
||||||
|
@Param('id') id: string,
|
||||||
|
@Body('dni') dni: string,
|
||||||
|
@Body('name') name: string,
|
||||||
|
@Body('last_name') last_name: string,
|
||||||
|
@Body('email') email: string,
|
||||||
|
@Body('phone') phone: number,
|
||||||
|
@Body('community_id') community_id: string,
|
||||||
|
@Body('number_house') number_house: string,
|
||||||
|
) {
|
||||||
|
|
||||||
|
return this.appService.updateTenant(
|
||||||
|
id,
|
||||||
|
dni,
|
||||||
|
name,
|
||||||
|
last_name,
|
||||||
|
email,
|
||||||
|
phone,
|
||||||
|
community_id,
|
||||||
|
number_house,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// #==== API Communities
|
// #==== API Communities
|
||||||
@Post('community/createCommunity')
|
@Post('community/createCommunity')
|
||||||
createCommunity(
|
createCommunity(
|
||||||
|
@ -369,8 +394,9 @@ export class AppController {
|
||||||
saveTenant(
|
saveTenant(
|
||||||
@Body('community_id') community_id: string,
|
@Body('community_id') community_id: string,
|
||||||
@Body('number_house') number_house: string,
|
@Body('number_house') number_house: string,
|
||||||
@Body('tenant_id') tenant_id: string,
|
@Body('_id') tenant_id: string,
|
||||||
) {
|
) {
|
||||||
|
console.log(community_id + ' ' + number_house + ' ' + tenant_id)
|
||||||
return this.appService.saveTenant(community_id, number_house, tenant_id);
|
return this.appService.saveTenant(community_id, number_house, tenant_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -175,6 +175,36 @@ export class AppService {
|
||||||
.send<string>(pattern, payload)
|
.send<string>(pattern, payload)
|
||||||
.pipe(map((message: string) => ({ message })));
|
.pipe(map((message: string) => ({ message })));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async updateTenant(
|
||||||
|
_id: string,
|
||||||
|
dni: string,
|
||||||
|
name: string,
|
||||||
|
last_name: string,
|
||||||
|
email: string,
|
||||||
|
phone: number,
|
||||||
|
community_id: string,
|
||||||
|
number_house: string,
|
||||||
|
) {
|
||||||
|
await this.saveTenant(community_id, number_house, _id);
|
||||||
|
|
||||||
|
const pattern = { cmd: 'updateTenant' };
|
||||||
|
const payload = {
|
||||||
|
id: _id,
|
||||||
|
dni: dni,
|
||||||
|
name: name,
|
||||||
|
last_name: last_name,
|
||||||
|
email: email,
|
||||||
|
phone: phone,
|
||||||
|
community_id: community_id,
|
||||||
|
number_house: number_house,
|
||||||
|
};
|
||||||
|
return this.clientUserApp
|
||||||
|
.send<string>(pattern, payload)
|
||||||
|
.pipe(map((message: string) => ({ message })));
|
||||||
|
}
|
||||||
|
|
||||||
//POST parameter from API
|
//POST parameter from API
|
||||||
createAdminSystem(dni: string, name: string, last_name: string, email: string, phone: number
|
createAdminSystem(dni: string, name: string, last_name: string, email: string, phone: number
|
||||||
, user_type: string, status: string, date_entry: Date) {
|
, user_type: string, status: string, date_entry: Date) {
|
||||||
|
@ -771,4 +801,19 @@ export class AppService {
|
||||||
|
|
||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async saveTenantNumHouse(community_id: string, number_house: string, tenant_id: string) {
|
||||||
|
|
||||||
|
const pattern = { cmd: 'saveTenantNumHouse' }
|
||||||
|
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 }))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,6 @@ 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'];
|
||||||
|
|
|
@ -88,7 +88,6 @@ export class CommunitiesService {
|
||||||
await community.houses.map(house => {
|
await community.houses.map(house => {
|
||||||
if (house.number_house == number_house) {
|
if (house.number_house == number_house) {
|
||||||
if (house.tenants) {
|
if (house.tenants) {
|
||||||
|
|
||||||
house.tenants.tenant_id = ptenant_id
|
house.tenants.tenant_id = ptenant_id
|
||||||
} else {
|
} else {
|
||||||
let tenant = new Tenant()
|
let tenant = new Tenant()
|
||||||
|
@ -109,7 +108,8 @@ export class CommunitiesService {
|
||||||
|
|
||||||
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 = "";
|
if(house.tenants)
|
||||||
|
house.tenants.tenant_id = "";
|
||||||
house.state = "desocupada"
|
house.state = "desocupada"
|
||||||
}
|
}
|
||||||
return house;
|
return house;
|
||||||
|
|
|
@ -77,14 +77,19 @@ export class UsersController {
|
||||||
|
|
||||||
@MessagePattern({ cmd: 'updateGuard' })
|
@MessagePattern({ cmd: 'updateGuard' })
|
||||||
updateGuard(@Payload() guard: UserDocument) {
|
updateGuard(@Payload() guard: UserDocument) {
|
||||||
return this.userService.update(guard.id, guard);
|
return this.userService.update(guard._id, guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
@MessagePattern({ cmd: 'updateAdminCommunity' })
|
@MessagePattern({ cmd: 'updateAdminCommunity' })
|
||||||
updateAdminCommunity(@Payload() user: UserDocument) {
|
updateAdminCommunity(@Payload() user: UserDocument) {
|
||||||
return this.userService.update(user._id, user);
|
return this.userService.update(user._id, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MessagePattern({ cmd: 'updateTenant' })
|
||||||
|
updateTenant(@Payload() tenant: UserDocument) {
|
||||||
|
return this.userService.updateTenant(tenant.id, tenant);
|
||||||
|
}
|
||||||
|
|
||||||
@MessagePattern({ cmd: 'removeUser' })
|
@MessagePattern({ cmd: 'removeUser' })
|
||||||
remove(@Payload() id: string) {
|
remove(@Payload() id: string) {
|
||||||
let dni = id['dni'];
|
let dni = id['dni'];
|
||||||
|
|
|
@ -29,7 +29,7 @@ export class UsersService {
|
||||||
let passwordEncriptada = Md5.init(user.password);
|
let passwordEncriptada = Md5.init(user.password);
|
||||||
user.password = passwordEncriptada;
|
user.password = passwordEncriptada;
|
||||||
let userCreated = await this.userModel.create(user);
|
let userCreated = await this.userModel.create(user);
|
||||||
await this.saveTenantNumHouse(user.community_id, user.number_house, userCreated['_id']);
|
await this.saveTenant(user.community_id, user.number_house, userCreated['_id']);
|
||||||
|
|
||||||
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'];
|
||||||
|
@ -117,6 +117,9 @@ export class UsersService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, user: UserDocument) {
|
async update(id: string, user: UserDocument) {
|
||||||
|
console.log(id)
|
||||||
|
console.log(user)
|
||||||
|
|
||||||
return this.userModel.findOneAndUpdate({ _id: id }, user, {
|
return this.userModel.findOneAndUpdate({ _id: id }, user, {
|
||||||
new: true,
|
new: true,
|
||||||
});
|
});
|
||||||
|
@ -131,6 +134,18 @@ export class UsersService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateTenant(id: string, user: UserDocument) {
|
||||||
|
await this.saveTenant(user.community_id, user.number_house, user.id);
|
||||||
|
|
||||||
|
return await this.userModel.findOneAndUpdate({ _id: id }, {
|
||||||
|
name: user['name'], last_name: user['last_name'],
|
||||||
|
dni: user['dni'], email: user['email'], phone: user['phone'],
|
||||||
|
number_house: user['number_house']
|
||||||
|
}, {
|
||||||
|
new: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/* async remove(id: string) {
|
/* async remove(id: string) {
|
||||||
return this.userModel.findByIdAndRemove({ _id: id }).exec();
|
return this.userModel.findByIdAndRemove({ _id: id }).exec();
|
||||||
}*/
|
}*/
|
||||||
|
@ -293,7 +308,7 @@ export class UsersService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async saveTenantNumHouse(community_id: string, number_house: string, tenant_id: string) {
|
async saveTenant(community_id: string, number_house: string, tenant_id: string) {
|
||||||
const pattern = { cmd: 'saveTenant' }
|
const pattern = { cmd: 'saveTenant' }
|
||||||
const payload = { _id: community_id, number_house: number_house, tenant_id: tenant_id }
|
const payload = { _id: community_id, number_house: number_house, tenant_id: tenant_id }
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,9 @@ const Inquilinos = () => {
|
||||||
item.number_house = 'Sin vivienda asignada'
|
item.number_house = 'Sin vivienda asignada'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
data = data.filter(
|
||||||
|
(val) => val.status != -1,
|
||||||
|
);
|
||||||
setTenants(data)
|
setTenants(data)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -156,9 +159,9 @@ const Inquilinos = () => {
|
||||||
.catch((error) => console.log(`Ocurrió un error: ${error}`))
|
.catch((error) => console.log(`Ocurrió un error: ${error}`))
|
||||||
} else setSubmitted(true)
|
} else setSubmitted(true)
|
||||||
} else {
|
} else {
|
||||||
let _tenant = { ..._tenant, number_house: houseNumber };
|
let _tenant = { ...tenant, number_house: houseNumber };
|
||||||
console.log(`Actualizando inquilino: ${_tenant}`)
|
console.log(`Actualizando inquilino: ${_tenant}`)
|
||||||
fetch(`http://localhost:4000/user/updateUser/${tenant._id}`, {
|
fetch(`http://localhost:4000/user/updateTenant/${tenant._id}`, {
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: JSON.stringify(_tenant),
|
body: JSON.stringify(_tenant),
|
||||||
|
@ -170,6 +173,17 @@ const Inquilinos = () => {
|
||||||
console.log(`Hubo un error en el servicio: ${response.status}`)
|
console.log(`Hubo un error en el servicio: ${response.status}`)
|
||||||
else return response.json()
|
else return response.json()
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
|
||||||
|
fetch('http://localhost:4000/community/saveTenant',
|
||||||
|
{
|
||||||
|
cache: 'no-cache',
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(_tenant),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
toast.current.show({
|
toast.current.show({
|
||||||
severity: 'success',
|
severity: 'success',
|
||||||
summary: 'Éxito',
|
summary: 'Éxito',
|
||||||
|
|
|
@ -132,7 +132,7 @@ const PerfilAdminComunidad = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
tenantsList(community._id);
|
tenantsList(cookies.community_id);
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue