agregar funciones de edici[on de agregar inquilino

This commit is contained in:
Mariela 2022-08-22 12:57:33 -06:00
parent 2cea9bc217
commit c89e501005
4 changed files with 73 additions and 1 deletions

View File

@ -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') @Put('user/updateGuard/:id')
updateGuard( updateGuard(
@Param('id') id: string, @Param('id') id: string,

View File

@ -87,6 +87,29 @@ 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 = tenant_id 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; return house;
}) })

View File

@ -268,5 +268,17 @@ export class UsersService {
map((response: string) => ({ response })) 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 }))
)
}
} }

View File

@ -122,7 +122,7 @@ const Inquilinos = () => {
_tenant.password = _tenant.email; _tenant.password = _tenant.email;
console.log(`Registrando nuevo inquilino: ${_tenant}`) console.log(`Registrando nuevo inquilino: ${_tenant}`)
fetch(`http://localhost:4000/user/createUser`, { fetch(`http://localhost:4000/user/createTenant`, {
cache: 'no-cache', cache: 'no-cache',
method: 'POST', method: 'POST',
body: JSON.stringify(_tenant), body: JSON.stringify(_tenant),
@ -136,6 +136,13 @@ const Inquilinos = () => {
else return response.json() else return response.json()
}) })
.then(() => { .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) _tenants.push(_tenant)
toast.current.show({ toast.current.show({
severity: 'success', severity: 'success',
@ -143,6 +150,7 @@ const Inquilinos = () => {
detail: 'Inquilino creado', detail: 'Inquilino creado',
life: 3000, life: 3000,
}) })
setTenants(_tenants) setTenants(_tenants)
setTenant(emptyTenant) setTenant(emptyTenant)
setHouseNumber('') setHouseNumber('')