From 2dcfdf495f13278b036cd6bc83f6351413698b71 Mon Sep 17 00:00:00 2001 From: Mariela Date: Mon, 22 Aug 2022 16:43:52 -0600 Subject: [PATCH] arreglar ultimos detalles para el eliminar --- servicio-usuarios/src/users/users.service.ts | 4 +- web-ui/web-react/src/components/Inquilinos.js | 57 ++++++++++--------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index d42cffb9..e5a17fef 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -195,7 +195,7 @@ export class UsersService { } async deleteAdminSystem(id: string) { - return this.userModel.findOneAndUpdate({ _id: id }, { status: '-1', number_house:'' }, { + return this.userModel.findOneAndUpdate({ _id: id }, { status: '-1'}, { new: true, }); } @@ -209,7 +209,7 @@ export class UsersService { async deleteTenant(tenant_id: string, community_id: string, number_house: string) { try{ - this.userModel.findOneAndUpdate({ _id: tenant_id }, { status: '-1' }, { + await this.userModel.findOneAndUpdate({ _id: tenant_id }, { status: '-1', number_house:''}, { new: true, }); diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 0f8fa2a3..0e0350e9 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -60,7 +60,7 @@ const Inquilinos = () => { .then((response) => response.json()) .then((data) => data.message) .then((data) => { - data = data.filter((val) => val.status !== -1) + data = data.filter((val) => val.status != -1) data.map((item) => { if (item.status === '1') { item.status_text = 'Activo' @@ -120,7 +120,7 @@ const Inquilinos = () => { _tenant.community_id = cookies.community_id; _tenant.number_house = houseNumber; _tenant.password = _tenant.email; - console.log(`Registrando nuevo inquilino: ${_tenant}`) + console.log(`Registrando nuevo inquilino: ${_tenant}`) fetch(`http://localhost:4000/user/createTenant`, { cache: 'no-cache', @@ -135,7 +135,7 @@ const Inquilinos = () => { console.log(`Hubo un error en el servicio: ${response.status}`) else return response.json() }) - .then(() => { + .then((data) => { if (_tenant.status === '1') { _tenant.status_text = 'Activo' } else if (_tenant.status === '0') { @@ -184,7 +184,7 @@ const Inquilinos = () => { } const deleteTenant = () => { - + let _tenant = { community_id: tenant.community_id, number_house: tenant.number_house @@ -195,38 +195,39 @@ const Inquilinos = () => { method: 'PUT', body: JSON.stringify(_tenant), headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json' } - }) + }) .then( - function (response) { - if (response.status != 201) - console.log('Ocurrió un error con el servicio: ' + response.status); - else - return response.json(); - } + function (response) { + if (response.status != 201) + console.log('Ocurrió un error con el servicio: ' + response.status); + else + return response.json(); + } ) .then( - function (response) { + function (response) { - let _tenants = tenants.filter((val) => val._id !== tenant._id) - setTenants(_tenants) - setDeleteTenantDialog(false) - setTenant(emptyTenant) - toast.current.show({ - severity: 'success', - summary: 'Inquilino Eliminado', - life: 3000, - }) } + let _tenants = tenants.filter((val) => val._id !== tenant._id) + setTenants(_tenants) + setDeleteTenantDialog(false) + setTenant(emptyTenant) + toast.current.show({ + severity: 'success', + summary: 'Inquilino Eliminado', + life: 3000, + }) + } ) .catch( - err => { - console.log('Ocurrió un error con el fetch', err) - toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Inquilino no se pudo eliminar', life: 3000 }); - } + err => { + console.log('Ocurrió un error con el fetch', err) + toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Inquilino no se pudo eliminar', life: 3000 }); + } ); - - + + } const deleteSelectedTenants = () => {