Merge branch 'dev' into US-42-EliminarInquilino

This commit is contained in:
Mariela 2022-08-22 11:45:27 -06:00
commit 04a9a2edfe
7 changed files with 821 additions and 615 deletions

View File

@ -65,6 +65,7 @@ export class AppController {
@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.createUser(
dni,
@ -77,11 +78,42 @@ export class AppController {
status,
date_entry,
community_id,
number_house,
);
}
@Put('user/updateGuard/:id')
updateGuard(
@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('password') password: string,
@Body('user_type') user_type: string,
@Body('status') status: string,
@Body('date_entry') date_entry: Date,
@Body('community_id') community_id: string,
) {
return this.appService.updateGuard(
id,
dni,
name,
last_name,
email,
phone,
password,
user_type,
status,
date_entry,
community_id,
);
}
@Put('user/updateUser')
@Put('user/updateUser/:id')
updateUser(
@Param('id') id: string,
@Body('dni') dni: string,
@Body('name') name: string,
@Body('last_name') last_name: string,
@ -92,8 +124,10 @@ export class AppController {
@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.updateUser(
id,
dni,
name,
last_name,
@ -104,6 +138,7 @@ export class AppController {
status,
date_entry,
community_id,
number_house,
);
}

View File

@ -34,6 +34,7 @@ export class AppService {
status: string,
date_entry: Date,
community_id: string,
number_house: string,
) {
const pattern = { cmd: 'createUser' };
const payload = {
@ -47,6 +48,7 @@ export class AppService {
status: status,
date_entry: date_entry,
community_id: community_id,
number_house: number_house,
};
return this.clientUserApp
.send<string>(pattern, payload)
@ -54,6 +56,41 @@ export class AppService {
}
updateUser(
_id: string,
dni: string,
name: string,
last_name: string,
email: string,
phone: number,
password: string,
user_type: string,
status: string,
date_entry: Date,
community_id: string,
number_house: string,
) {
const pattern = { cmd: 'updateUser' };
const payload = {
id: _id,
dni: dni,
name: name,
last_name: last_name,
email: email,
phone: phone,
password: password,
user_type: user_type,
status: status,
date_entry: date_entry,
community_id: community_id,
number_house: number_house,
};
return this.clientUserApp
.send<string>(pattern, payload)
.pipe(map((message: string) => ({ message })));
}
updateGuard(
_id: string,
dni: string,
name: string,
last_name: string,
@ -65,8 +102,9 @@ export class AppService {
date_entry: Date,
community_id: string,
) {
const pattern = { cmd: 'updateUser' };
const pattern = { cmd: 'updateGuard' };
const payload = {
id: _id,
dni: dni,
name: name,
last_name: last_name,

View File

@ -6,3 +6,8 @@ help = "Per project developer environments"
[[commands]]
package = "nodejs"
help = "Node.js"
[[commands]]
package = "nodePackages.expo-cli"
help = "Expo CLI"

View File

@ -69,6 +69,11 @@ export class UsersController {
return this.userService.update(user.id, user);
}
@MessagePattern({ cmd: 'updateGuard' })
updateGuard(@Payload() guard: UserDocument) {
return this.userService.update(guard.id, guard);
}
@MessagePattern({ cmd: 'removeUser' })
remove(@Payload() id: string) {
let dni = id['dni'];

View File

@ -143,19 +143,6 @@ export class UsersService {
return await this.userModel.find({ community_id: pcommunity_id, user_type: 4 })
.then(async (users) => {
if (users) {
await Promise.all(
users.map(async (u) => {
//buscar al usuario con el id de la comunidad anexado
let number_house = await this.findNumHouseTenant(pcommunity_id, u['_id']);
u['number_house'] = number_house;
return u;
}),
)
}
return users;
})
}

File diff suppressed because it is too large Load Diff

View File

@ -42,6 +42,7 @@ const Inquilinos = () => {
const [deleteTenantDialog, setDeleteTenantDialog] = useState(false)
const [deleteTenantsDialog, setDeleteTenantsDialog] = useState(false)
const [community, setCommunity] = useState([])
const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar")
const [houseNumber, setHouseNumber] = useState([])
const [housesList, setHousesList] = useState([])
const [submitted, setSubmitted] = useState(false)
@ -101,40 +102,69 @@ const Inquilinos = () => {
}, [])
const saveTenant = () => {
if (tenant.email && tenant.number_house && tenant.dni
&& tenant.name && tenant.last_name && tenant.phone) {
let _tenants = [...tenants]
let _tenant = { ...tenant }
_tenant.community_id = cookies.community_id;
_tenant.number_house = houseNumber;
_tenant.password = _tenant.email;
if (tenant._id === null) {
if (tenant.email && tenant.number_house && tenant.dni
&& tenant.name && tenant.last_name && tenant.phone) {
let _tenants = [...tenants]
let _tenant = { ...tenant }
_tenant.community_id = cookies.community_id;
_tenant.number_house = houseNumber;
_tenant.password = _tenant.email;
console.log(`Registrando nuevo inquilino: ${_tenant}`)
fetch(`http://localhost:4000/user/createUser`, {
fetch(`http://localhost:4000/user/createUser`, {
cache: 'no-cache',
method: 'POST',
body: JSON.stringify(_tenant),
headers: {
'Content-Type': 'application/json',
},
})
.then((response) => {
if (response.status !== 200)
console.log(`Hubo un error en el servicio: ${response.status}`)
else return response.json()
})
.then(() => {
_tenants.push(_tenant)
toast.current.show({
severity: 'success',
summary: 'Éxito',
detail: 'Inquilino creado',
life: 3000,
})
setTenants(_tenants)
setTenant(emptyTenant)
setHouseNumber('')
})
.catch((error) => console.log(`Ocurrió un error: ${error}`))
} else setSubmitted(true)
} else {
let _tenant = { ..._tenant, number_house: houseNumber };
console.log(`Actualizando inquilino: ${_tenant}`)
fetch(`http://localhost:4000/user/updateUser/${tenant._id}`, {
cache: 'no-cache',
method: 'POST',
method: 'PUT',
body: JSON.stringify(_tenant),
headers: {
'Content-Type': 'application/json',
},
}).then((response) => {
if (response.status !== 200)
console.log(`Hubo un error en el servicio: ${response.status}`)
else return response.json()
}).then(() => {
toast.current.show({
severity: 'success',
summary: 'Éxito',
detail: 'Inquilino editado',
life: 3000,
})
tenantsList()
setTenant(emptyTenant)
setHouseNumber('')
})
.then((response) => {
if (response.status !== 201)
console.log(`Hubo un error en el servicio: ${response.status}`)
else return response.json()
})
.then(() => {
_tenants.push(_tenant)
toast.current.show({
severity: 'success',
summary: 'Éxito',
detail: 'Inquilino creado',
life: 3000,
})
setTenants(_tenants)
setTenant(emptyTenant)
})
.catch((error) => console.log(`Ocurrió un error: ${error}`))
} else setSubmitted(true)
}
}
const deleteTenant = () => {
@ -238,6 +268,19 @@ const Inquilinos = () => {
setShowInfoDialog(true);
}
const editTenant = (tenant) => {
setTenant(tenant);
console.log(tenant);
setSaveButtonTitle('Actualizar');
setHouseNumber(tenant.number_house);
}
const cancelEdit = () => {
setTenant(emptyTenant);
setSaveButtonTitle('Registrar');
setHouseNumber('');
}
const actionsTenant = (rowData) => {
let icono = ''
let text = ''
@ -246,14 +289,21 @@ const Inquilinos = () => {
text = 'Activar Inquilino'
} else if (rowData.status === '1') {
icono = 'pi pi-eye-slash'
text = 'Inactivar Inquilino'
text = 'Desactivar Inquilino'
}
return (
<div className='actions'>
<Button
icon="pi pi-pencil"
className="p-button-rounded p-button-success mt-2 mx-2"
onClick={() => editTenant(rowData)}
title="Editar"
/>
<Button
icon="pi pi-exclamation-circle"
className="p-button-rounded p-button-info mt-2 mx-2"
onClick={() => infoTenant(rowData)}
title="Ver Información"
/>
<Button
icon={`${icono}`}
@ -265,6 +315,7 @@ const Inquilinos = () => {
icon='pi pi-trash'
className='p-button-rounded p-button-danger mt-2 mx-2'
onClick={() => confirmDeleteTenant(rowData)}
title='Eliminar Inquilino'
/>
</div>
)
@ -574,10 +625,7 @@ const Inquilinos = () => {
wordBreak: 'break-word',
}}
></Column>
<Column
style={{ flexGrow: 1, flexBasis: '80px', minWidth: '80px' }}
body={actionsTenant}
></Column>
<Column style={{ flexGrow: 1, flexBasis: '80px', minWidth: '80px' }} body={actionsTenant}></Column>
</DataTable>
<Dialog
visible={infoDialogVisible}
@ -711,7 +759,7 @@ const Inquilinos = () => {
</div>
<div className="col-12">
<div className="card">
<h5>Registro de un administrador de una comunidad de viviendas</h5>
<h5>Registro de un Inquilino</h5>
<div className="p-fluid formgrid grid">
<div className="field col-12 md:col-6">
<label htmlFor="name">Nombre</label>
@ -798,7 +846,22 @@ const Inquilinos = () => {
&& <small className="p-invalid">Casa es requerida.</small>}
</div>
</div>
<Button label="Registrar" onClick={saveTenant} />
<div style={{
display: "flex",
justifyContent: "center",
gap: "10px",
width: "100%"
}}>
<Button
label={`${saveButtonTitle}`}
onClick={saveTenant}
/>
{saveButtonTitle === 'Actualizar' && (
<Button
label="Cancel"
onClick={cancelEdit}
className="p-button-danger" />)}
</div>
</div>
</div>
</div>