Merge pull request #183 from DeimosPr4/52-us-39-modificar-inquilino
52 us 39 modificar inquilino
This commit is contained in:
		
						commit
						2746d29fa4
					
				| 
						 | 
					@ -65,6 +65,7 @@ export class AppController {
 | 
				
			||||||
    @Body('status') status: string,
 | 
					    @Body('status') status: string,
 | 
				
			||||||
    @Body('date_entry') date_entry: Date,
 | 
					    @Body('date_entry') date_entry: Date,
 | 
				
			||||||
    @Body('community_id') community_id: string,
 | 
					    @Body('community_id') community_id: string,
 | 
				
			||||||
 | 
					    @Body('number_house') number_house: string,
 | 
				
			||||||
  ) {
 | 
					  ) {
 | 
				
			||||||
    return this.appService.createUser(
 | 
					    return this.appService.createUser(
 | 
				
			||||||
      dni,
 | 
					      dni,
 | 
				
			||||||
| 
						 | 
					@ -77,11 +78,13 @@ export class AppController {
 | 
				
			||||||
      status,
 | 
					      status,
 | 
				
			||||||
      date_entry,
 | 
					      date_entry,
 | 
				
			||||||
      community_id,
 | 
					      community_id,
 | 
				
			||||||
 | 
					      number_house,
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Put('user/updateUser')
 | 
					  @Put('user/updateUser/:id')
 | 
				
			||||||
  updateUser(
 | 
					  updateUser(
 | 
				
			||||||
 | 
					    @Param('id') id: string,
 | 
				
			||||||
    @Body('dni') dni: string,
 | 
					    @Body('dni') dni: string,
 | 
				
			||||||
    @Body('name') name: string,
 | 
					    @Body('name') name: string,
 | 
				
			||||||
    @Body('last_name') last_name: string,
 | 
					    @Body('last_name') last_name: string,
 | 
				
			||||||
| 
						 | 
					@ -92,8 +95,10 @@ export class AppController {
 | 
				
			||||||
    @Body('status') status: string,
 | 
					    @Body('status') status: string,
 | 
				
			||||||
    @Body('date_entry') date_entry: Date,
 | 
					    @Body('date_entry') date_entry: Date,
 | 
				
			||||||
    @Body('community_id') community_id: string,
 | 
					    @Body('community_id') community_id: string,
 | 
				
			||||||
 | 
					    @Body('number_house') number_house: string,
 | 
				
			||||||
  ) {
 | 
					  ) {
 | 
				
			||||||
    return this.appService.updateUser(
 | 
					    return this.appService.updateUser(
 | 
				
			||||||
 | 
					      id,
 | 
				
			||||||
      dni,
 | 
					      dni,
 | 
				
			||||||
      name,
 | 
					      name,
 | 
				
			||||||
      last_name,
 | 
					      last_name,
 | 
				
			||||||
| 
						 | 
					@ -104,6 +109,7 @@ export class AppController {
 | 
				
			||||||
      status,
 | 
					      status,
 | 
				
			||||||
      date_entry,
 | 
					      date_entry,
 | 
				
			||||||
      community_id,
 | 
					      community_id,
 | 
				
			||||||
 | 
					      number_house,
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,6 +34,7 @@ export class AppService {
 | 
				
			||||||
    status: string,
 | 
					    status: string,
 | 
				
			||||||
    date_entry: Date,
 | 
					    date_entry: Date,
 | 
				
			||||||
    community_id: string,
 | 
					    community_id: string,
 | 
				
			||||||
 | 
					    number_house: string,
 | 
				
			||||||
  ) {
 | 
					  ) {
 | 
				
			||||||
    const pattern = { cmd: 'createUser' };
 | 
					    const pattern = { cmd: 'createUser' };
 | 
				
			||||||
    const payload = {
 | 
					    const payload = {
 | 
				
			||||||
| 
						 | 
					@ -47,6 +48,7 @@ export class AppService {
 | 
				
			||||||
      status: status,
 | 
					      status: status,
 | 
				
			||||||
      date_entry: date_entry,
 | 
					      date_entry: date_entry,
 | 
				
			||||||
      community_id: community_id,
 | 
					      community_id: community_id,
 | 
				
			||||||
 | 
					      number_house: number_house,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    return this.clientUserApp
 | 
					    return this.clientUserApp
 | 
				
			||||||
      .send<string>(pattern, payload)
 | 
					      .send<string>(pattern, payload)
 | 
				
			||||||
| 
						 | 
					@ -54,6 +56,7 @@ export class AppService {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  updateUser(
 | 
					  updateUser(
 | 
				
			||||||
 | 
					    _id: string,
 | 
				
			||||||
    dni: string,
 | 
					    dni: string,
 | 
				
			||||||
    name: string,
 | 
					    name: string,
 | 
				
			||||||
    last_name: string,
 | 
					    last_name: string,
 | 
				
			||||||
| 
						 | 
					@ -64,9 +67,11 @@ export class AppService {
 | 
				
			||||||
    status: string,
 | 
					    status: string,
 | 
				
			||||||
    date_entry: Date,
 | 
					    date_entry: Date,
 | 
				
			||||||
    community_id: string,
 | 
					    community_id: string,
 | 
				
			||||||
 | 
					    number_house: string,
 | 
				
			||||||
  ) {
 | 
					  ) {
 | 
				
			||||||
    const pattern = { cmd: 'updateUser' };
 | 
					    const pattern = { cmd: 'updateUser' };
 | 
				
			||||||
    const payload = {
 | 
					    const payload = {
 | 
				
			||||||
 | 
					      id: _id,
 | 
				
			||||||
      dni: dni,
 | 
					      dni: dni,
 | 
				
			||||||
      name: name,
 | 
					      name: name,
 | 
				
			||||||
      last_name: last_name,
 | 
					      last_name: last_name,
 | 
				
			||||||
| 
						 | 
					@ -77,6 +82,7 @@ export class AppService {
 | 
				
			||||||
      status: status,
 | 
					      status: status,
 | 
				
			||||||
      date_entry: date_entry,
 | 
					      date_entry: date_entry,
 | 
				
			||||||
      community_id: community_id,
 | 
					      community_id: community_id,
 | 
				
			||||||
 | 
					      number_house: number_house,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    return this.clientUserApp
 | 
					    return this.clientUserApp
 | 
				
			||||||
      .send<string>(pattern, payload)
 | 
					      .send<string>(pattern, payload)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -143,19 +143,6 @@ export class UsersService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return await this.userModel.find({ community_id: pcommunity_id, user_type: 4 })
 | 
					    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;
 | 
					 | 
				
			||||||
      })
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -42,10 +42,12 @@ const Inquilinos = () => {
 | 
				
			||||||
  const [deleteTenantDialog, setDeleteTenantDialog] = useState(false)
 | 
					  const [deleteTenantDialog, setDeleteTenantDialog] = useState(false)
 | 
				
			||||||
  const [deleteTenantsDialog, setDeleteTenantsDialog] = useState(false)
 | 
					  const [deleteTenantsDialog, setDeleteTenantsDialog] = useState(false)
 | 
				
			||||||
  const [community, setCommunity] = useState([])
 | 
					  const [community, setCommunity] = useState([])
 | 
				
			||||||
 | 
					  const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar")
 | 
				
			||||||
  const [houseNumber, setHouseNumber] = useState([])
 | 
					  const [houseNumber, setHouseNumber] = useState([])
 | 
				
			||||||
  const [housesList, setHousesList] = useState([])
 | 
					  const [housesList, setHousesList] = useState([])
 | 
				
			||||||
  const [submitted, setSubmitted] = useState(false)
 | 
					  const [submitted, setSubmitted] = useState(false)
 | 
				
			||||||
  const [infoDialogVisible, setShowInfoDialog] = useState(false)
 | 
					  const [infoDialogVisible, setShowInfoDialog] = useState(false)
 | 
				
			||||||
 | 
					  const [cancelSaveButtonVisible, setCancelSaveButtonVisible] = useState(false)
 | 
				
			||||||
  const toast = useRef(null)
 | 
					  const toast = useRef(null)
 | 
				
			||||||
  const dt = useRef(null)
 | 
					  const dt = useRef(null)
 | 
				
			||||||
  const [cookies] = useCookies()
 | 
					  const [cookies] = useCookies()
 | 
				
			||||||
| 
						 | 
					@ -101,6 +103,7 @@ const Inquilinos = () => {
 | 
				
			||||||
  }, [])
 | 
					  }, [])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const saveTenant = () => {
 | 
					  const saveTenant = () => {
 | 
				
			||||||
 | 
					    if (tenant._id === null) {
 | 
				
			||||||
      if (tenant.email && tenant.number_house && tenant.dni
 | 
					      if (tenant.email && tenant.number_house && tenant.dni
 | 
				
			||||||
        && tenant.name && tenant.last_name && tenant.phone) {
 | 
					        && tenant.name && tenant.last_name && tenant.phone) {
 | 
				
			||||||
        let _tenants = [...tenants]
 | 
					        let _tenants = [...tenants]
 | 
				
			||||||
| 
						 | 
					@ -108,6 +111,7 @@ const Inquilinos = () => {
 | 
				
			||||||
        _tenant.community_id = cookies.community_id;
 | 
					        _tenant.community_id = cookies.community_id;
 | 
				
			||||||
        _tenant.number_house = houseNumber;
 | 
					        _tenant.number_house = houseNumber;
 | 
				
			||||||
        _tenant.password = _tenant.email;
 | 
					        _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',
 | 
					          cache: 'no-cache',
 | 
				
			||||||
| 
						 | 
					@ -118,7 +122,7 @@ const Inquilinos = () => {
 | 
				
			||||||
          },
 | 
					          },
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
          .then((response) => {
 | 
					          .then((response) => {
 | 
				
			||||||
          if (response.status !== 201)
 | 
					            if (response.status !== 200)
 | 
				
			||||||
              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()
 | 
				
			||||||
          })
 | 
					          })
 | 
				
			||||||
| 
						 | 
					@ -132,9 +136,36 @@ const Inquilinos = () => {
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
            setTenants(_tenants)
 | 
					            setTenants(_tenants)
 | 
				
			||||||
            setTenant(emptyTenant)
 | 
					            setTenant(emptyTenant)
 | 
				
			||||||
 | 
					            setHouseNumber('')
 | 
				
			||||||
          })
 | 
					          })
 | 
				
			||||||
          .catch((error) => console.log(`Ocurrió un error: ${error}`))
 | 
					          .catch((error) => console.log(`Ocurrió un error: ${error}`))
 | 
				
			||||||
      } else setSubmitted(true)
 | 
					      } 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: '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('')
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const deleteTenant = () => {
 | 
					  const deleteTenant = () => {
 | 
				
			||||||
| 
						 | 
					@ -238,6 +269,20 @@ const Inquilinos = () => {
 | 
				
			||||||
    setShowInfoDialog(true);
 | 
					    setShowInfoDialog(true);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const editTenant = (tenant) => {
 | 
				
			||||||
 | 
					    setTenant(tenant);
 | 
				
			||||||
 | 
					    console.log(tenant);
 | 
				
			||||||
 | 
					    setSaveButtonTitle('Actualizar');
 | 
				
			||||||
 | 
					    setHouseNumber(tenant.number_house);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const cancelEdit = () => {
 | 
				
			||||||
 | 
					    setTenant(emptyTenant);
 | 
				
			||||||
 | 
					    setSaveButtonTitle('Registrar');
 | 
				
			||||||
 | 
					    setCancelSaveButtonVisible(false);
 | 
				
			||||||
 | 
					    setHouseNumber('');
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const actionsTenant = (rowData) => {
 | 
					  const actionsTenant = (rowData) => {
 | 
				
			||||||
    let icono = ''
 | 
					    let icono = ''
 | 
				
			||||||
    let text = ''
 | 
					    let text = ''
 | 
				
			||||||
| 
						 | 
					@ -246,14 +291,21 @@ const Inquilinos = () => {
 | 
				
			||||||
      text = 'Activar Inquilino'
 | 
					      text = 'Activar Inquilino'
 | 
				
			||||||
    } else if (rowData.status === '1') {
 | 
					    } else if (rowData.status === '1') {
 | 
				
			||||||
      icono = 'pi pi-eye-slash'
 | 
					      icono = 'pi pi-eye-slash'
 | 
				
			||||||
      text = 'Inactivar Inquilino'
 | 
					      text = 'Desactivar Inquilino'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
      <div className='actions'>
 | 
					      <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
 | 
					        <Button
 | 
				
			||||||
          icon="pi pi-exclamation-circle"
 | 
					          icon="pi pi-exclamation-circle"
 | 
				
			||||||
          className="p-button-rounded p-button-info mt-2 mx-2"
 | 
					          className="p-button-rounded p-button-info mt-2 mx-2"
 | 
				
			||||||
          onClick={() => infoTenant(rowData)}
 | 
					          onClick={() => infoTenant(rowData)}
 | 
				
			||||||
 | 
					          title="Ver Información"
 | 
				
			||||||
        />
 | 
					        />
 | 
				
			||||||
        <Button
 | 
					        <Button
 | 
				
			||||||
          icon={`${icono}`}
 | 
					          icon={`${icono}`}
 | 
				
			||||||
| 
						 | 
					@ -265,6 +317,7 @@ const Inquilinos = () => {
 | 
				
			||||||
          icon='pi pi-trash'
 | 
					          icon='pi pi-trash'
 | 
				
			||||||
          className='p-button-rounded p-button-danger mt-2 mx-2'
 | 
					          className='p-button-rounded p-button-danger mt-2 mx-2'
 | 
				
			||||||
          onClick={() => confirmDeleteTenant(rowData)}
 | 
					          onClick={() => confirmDeleteTenant(rowData)}
 | 
				
			||||||
 | 
					          title='Eliminar Inquilino'
 | 
				
			||||||
        />
 | 
					        />
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
| 
						 | 
					@ -574,10 +627,7 @@ const Inquilinos = () => {
 | 
				
			||||||
                wordBreak: 'break-word',
 | 
					                wordBreak: 'break-word',
 | 
				
			||||||
              }}
 | 
					              }}
 | 
				
			||||||
            ></Column>
 | 
					            ></Column>
 | 
				
			||||||
            <Column
 | 
					            <Column style={{ flexGrow: 1, flexBasis: '80px', minWidth: '80px' }} body={actionsTenant}></Column>
 | 
				
			||||||
              style={{ flexGrow: 1, flexBasis: '80px', minWidth: '80px' }}
 | 
					 | 
				
			||||||
              body={actionsTenant}
 | 
					 | 
				
			||||||
            ></Column>
 | 
					 | 
				
			||||||
          </DataTable>
 | 
					          </DataTable>
 | 
				
			||||||
          <Dialog
 | 
					          <Dialog
 | 
				
			||||||
            visible={infoDialogVisible}
 | 
					            visible={infoDialogVisible}
 | 
				
			||||||
| 
						 | 
					@ -798,7 +848,22 @@ const Inquilinos = () => {
 | 
				
			||||||
                  && <small className="p-invalid">Casa es requerida.</small>}
 | 
					                  && <small className="p-invalid">Casa es requerida.</small>}
 | 
				
			||||||
              </div>
 | 
					              </div>
 | 
				
			||||||
            </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>
 | 
					        </div>
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue