arreglar ultimos detalles para el eliminar

This commit is contained in:
Mariela 2022-08-22 16:43:52 -06:00
parent a9c02244a8
commit 2dcfdf495f
2 changed files with 31 additions and 30 deletions

View File

@ -195,7 +195,7 @@ export class UsersService {
} }
async deleteAdminSystem(id: string) { async deleteAdminSystem(id: string) {
return this.userModel.findOneAndUpdate({ _id: id }, { status: '-1', number_house:'' }, { return this.userModel.findOneAndUpdate({ _id: id }, { status: '-1'}, {
new: true, new: true,
}); });
} }
@ -209,7 +209,7 @@ export class UsersService {
async deleteTenant(tenant_id: string, community_id: string, number_house: string) { async deleteTenant(tenant_id: string, community_id: string, number_house: string) {
try{ try{
this.userModel.findOneAndUpdate({ _id: tenant_id }, { status: '-1' }, { await this.userModel.findOneAndUpdate({ _id: tenant_id }, { status: '-1', number_house:''}, {
new: true, new: true,
}); });

View File

@ -60,7 +60,7 @@ const Inquilinos = () => {
.then((response) => response.json()) .then((response) => response.json())
.then((data) => data.message) .then((data) => data.message)
.then((data) => { .then((data) => {
data = data.filter((val) => val.status !== -1) data = data.filter((val) => val.status != -1)
data.map((item) => { data.map((item) => {
if (item.status === '1') { if (item.status === '1') {
item.status_text = 'Activo' item.status_text = 'Activo'
@ -120,7 +120,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}`) console.log(`Registrando nuevo inquilino: ${_tenant}`)
fetch(`http://localhost:4000/user/createTenant`, { fetch(`http://localhost:4000/user/createTenant`, {
cache: 'no-cache', cache: 'no-cache',
@ -135,7 +135,7 @@ const Inquilinos = () => {
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()
}) })
.then(() => { .then((data) => {
if (_tenant.status === '1') { if (_tenant.status === '1') {
_tenant.status_text = 'Activo' _tenant.status_text = 'Activo'
} else if (_tenant.status === '0') { } else if (_tenant.status === '0') {
@ -184,7 +184,7 @@ const Inquilinos = () => {
} }
const deleteTenant = () => { const deleteTenant = () => {
let _tenant = { let _tenant = {
community_id: tenant.community_id, community_id: tenant.community_id,
number_house: tenant.number_house number_house: tenant.number_house
@ -195,38 +195,39 @@ const Inquilinos = () => {
method: 'PUT', method: 'PUT',
body: JSON.stringify(_tenant), body: JSON.stringify(_tenant),
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
}) })
.then( .then(
function (response) { function (response) {
if (response.status != 201) if (response.status != 201)
console.log('Ocurrió un error con el servicio: ' + response.status); console.log('Ocurrió un error con el servicio: ' + response.status);
else else
return response.json(); return response.json();
} }
) )
.then( .then(
function (response) { function (response) {
let _tenants = tenants.filter((val) => val._id !== tenant._id) let _tenants = tenants.filter((val) => val._id !== tenant._id)
setTenants(_tenants) setTenants(_tenants)
setDeleteTenantDialog(false) setDeleteTenantDialog(false)
setTenant(emptyTenant) setTenant(emptyTenant)
toast.current.show({ toast.current.show({
severity: 'success', severity: 'success',
summary: 'Inquilino Eliminado', summary: 'Inquilino Eliminado',
life: 3000, life: 3000,
}) } })
}
) )
.catch( .catch(
err => { err => {
console.log('Ocurrió un error con el fetch', 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 }); toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Inquilino no se pudo eliminar', life: 3000 });
} }
); );
} }
const deleteSelectedTenants = () => { const deleteSelectedTenants = () => {