agregar funciones de edici[on de agregar inquilino
This commit is contained in:
parent
2cea9bc217
commit
c89e501005
|
@ -82,6 +82,35 @@ export class AppController {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
@Post('user/createTenant')
|
||||
createTenant(
|
||||
@Body('dni') dni: string,
|
||||
@Body('name') name: string,
|
||||
@Body('last_name') last_name: string,
|
||||
@Body('email') email: string,
|
||||
@Body('phone') phone: number,
|
||||
@Body('user_type') user_type: string,
|
||||
@Body('status') status: string,
|
||||
@Body('date_entry') date_entry: Date,
|
||||
@Body('community_id') community_id: string,
|
||||
@Body('number_house') number_house: string,
|
||||
) {
|
||||
return this.appService.createTenant(
|
||||
dni,
|
||||
name,
|
||||
last_name,
|
||||
email,
|
||||
phone,
|
||||
user_type,
|
||||
status,
|
||||
date_entry,
|
||||
community_id,
|
||||
number_house,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Put('user/updateGuard/:id')
|
||||
updateGuard(
|
||||
@Param('id') id: string,
|
||||
|
|
|
@ -87,6 +87,29 @@ export class CommunitiesService {
|
|||
await community.houses.map(house => {
|
||||
if(house.number_house == number_house){
|
||||
house.tenants.tenant_id = tenant_id
|
||||
house.state = "ocupada"
|
||||
}
|
||||
return house;
|
||||
})
|
||||
|
||||
console.log(community.houses)
|
||||
|
||||
return await this.communityModel.findOneAndUpdate({ _id: id }, community, {
|
||||
new: true,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async deleteTenant(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){
|
||||
house.tenants = null;
|
||||
house.state = "desocupada"
|
||||
|
||||
}
|
||||
return house;
|
||||
})
|
||||
|
|
|
@ -268,5 +268,17 @@ export class UsersService {
|
|||
map((response: string) => ({ response }))
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
async deleteTenantNumHouse(community_id: string, number_house:string, tenant_id: string) {
|
||||
const pattern = { cmd: 'deleteTenant' }
|
||||
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 }))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ const Inquilinos = () => {
|
|||
_tenant.password = _tenant.email;
|
||||
console.log(`Registrando nuevo inquilino: ${_tenant}`)
|
||||
|
||||
fetch(`http://localhost:4000/user/createUser`, {
|
||||
fetch(`http://localhost:4000/user/createTenant`, {
|
||||
cache: 'no-cache',
|
||||
method: 'POST',
|
||||
body: JSON.stringify(_tenant),
|
||||
|
@ -136,6 +136,13 @@ const Inquilinos = () => {
|
|||
else return response.json()
|
||||
})
|
||||
.then(() => {
|
||||
if (_tenant.status === '1') {
|
||||
_tenant.status = '0'
|
||||
_tenant.status_text = 'Inactivo'
|
||||
} else if (_tenant.status === '0') {
|
||||
_tenant.status = '1'
|
||||
_tenant.status_text = 'Activo'
|
||||
}
|
||||
_tenants.push(_tenant)
|
||||
toast.current.show({
|
||||
severity: 'success',
|
||||
|
@ -143,6 +150,7 @@ const Inquilinos = () => {
|
|||
detail: 'Inquilino creado',
|
||||
life: 3000,
|
||||
})
|
||||
|
||||
setTenants(_tenants)
|
||||
setTenant(emptyTenant)
|
||||
setHouseNumber('')
|
||||
|
|
Loading…
Reference in New Issue