diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 647eca29..1b53de45 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -2,7 +2,7 @@ import { Controller, Get, Post, Put, Body, Param, Delete } from '@nestjs/common' import { AppService } from './app.service'; @Controller() export class AppController { - constructor(private readonly appService: AppService) {} + constructor(private readonly appService: AppService) { } // #==== API Users @Post('user/createAdminSystem') createAdminSystem( @@ -15,8 +15,8 @@ export class AppController { @Body('status') status: string, @Body('date_entry') date_entry: Date, ) { - return this.appService.createAdminSystem(dni, name, last_name, email, phone, - user_type, status, date_entry); + return this.appService.createAdminSystem(dni, name, last_name, email, phone, + user_type, status, date_entry); } @Post('user/createGuard') @@ -33,7 +33,7 @@ export class AppController { @Body('community_id') community_id: string, ) { return this.appService.createGuard(dni, name, last_name, email, phone, - user_type, status, date_entry,community_id); + user_type, status, date_entry, community_id); } @Post('user/createAdminCommunity') @@ -47,10 +47,10 @@ export class AppController { @Body('user_type') user_type: string, @Body('status') status: string, @Body('date_entry') date_entry: Date, - @Body('community_id') community_id:string + @Body('community_id') community_id: string ) { return this.appService.createAdminCommunity(dni, name, last_name, email, phone, - user_type, status, date_entry,community_id); + user_type, status, date_entry, community_id); } @Post('user/createUser') @@ -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') updateGuard( @Param('id') id: string, @@ -174,7 +203,7 @@ export class AppController { allUsersTenants(@Param('community_id') paramCommunity_id: string) { return this.appService.findTenantsCommunity(paramCommunity_id); } - + @Get('user/find/:dni') findUser(@Param('dni') paramUserDNI: string) { return this.appService.findUser(paramUserDNI); @@ -195,9 +224,13 @@ export class AppController { return this.appService.deleteAdminCommunity(id); } - @Delete('user/deleteTenant/:id') - deleteTenant(@Param('id') id: string) { - return this.appService.deleteTenant(id); + @Put('user/deleteTenant/:id') + deleteTenant( + @Param('id') id: string, + @Body('community_id') community_id: string, + @Body('number_house') number_house: string + ) { + return this.appService.deleteTenant(id, community_id, number_house); } @Post('user/changeStatus') @@ -296,8 +329,6 @@ export class AppController { ) { return this.appService.saveTenant(community_id, number_house, tenant_id); } - - // #==== API Common Areas @Post('commonArea/createCommonArea') createCommonArea( diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 29a84208..9f39ccaf 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -1,6 +1,7 @@ import { Injectable, Inject } from '@nestjs/common'; import { ClientProxy } from '@nestjs/microservices'; import { map } from 'rxjs/operators'; +import { lastValueFrom } from 'rxjs'; @Injectable() export class AppService { @@ -55,6 +56,37 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + createTenant( + dni: string, + name: string, + last_name: string, + email: string, + phone: number, + user_type: string, + status: string, + date_entry: Date, + community_id: string, + number_house: string, + ) { + const pattern = { cmd: 'createTenant' }; + const payload = { + dni: dni, + name: name, + last_name: last_name, + email: email, + phone: phone, + password: this.generatePassword(), + user_type: user_type, + status: status, + date_entry: date_entry, + community_id: community_id, + number_house: number_house, + }; + return this.clientUserApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + updateUser( _id: string, dni: string, @@ -261,9 +293,9 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } - deleteTenant(id: string) { + deleteTenant(id: string, community_id: string, number_house: string) { const pattern = { cmd: 'deleteTenant' }; - const payload = { id: id }; + const payload = { _id: id, community_id: community_id, number_house: number_house }; return this.clientUserApp .send(pattern, payload) .pipe(map((message: string) => ({ message }))); @@ -359,6 +391,31 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + + async findHousesCommunity(community_id: string) { + const pattern = { cmd: 'findOneCommunity' } + const payload = { _id: community_id } + + let callback = await this.clientCommunityApp + .send(pattern, payload) + .pipe( + map((response: string) => ({ response })) + ) + const finalValue = await lastValueFrom(callback); + const response = finalValue['response']; + const houses = response['houses']; + + return houses; + } + + saveTenant(id: string, number_house: string, tenant_id: string) { + const pattern = { cmd: 'saveTenant' }; + const payload = { _id: id, number_house: number_house, tenant_id: tenant_id }; + return this.clientCommunityApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + // ====================== COMMON AREAS =============================== //POST parameter from API createCommonArea( diff --git a/servicio-comunidad-viviendas/src/communities/communities.controller.ts b/servicio-comunidad-viviendas/src/communities/communities.controller.ts index 83335420..a0fa2672 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.controller.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.controller.ts @@ -53,4 +53,22 @@ export class CommunitiesController { let pstatus = body['status']; return this.communitiesService.changeStatus(pid,pstatus); } + + + @MessagePattern({ cmd: 'saveTenant' }) + saveTenant(@Payload() body: string) { + + let id = body['_id']; + let tenant_id = body['tenant_id']; + let number_house = body['number_house']; + return this.communitiesService.saveTenant(id, number_house, tenant_id); + } + + @MessagePattern({ cmd: 'deleteTenant' }) + deleteTenant(@Payload() body: string) { + let id = body['_id']; + let tenant_id = body['tenant_id']; + let number_house = body['number_house']; + return this.communitiesService.deleteTenant(id, number_house, tenant_id); + } } diff --git a/servicio-comunidad-viviendas/src/communities/communities.service.ts b/servicio-comunidad-viviendas/src/communities/communities.service.ts index 8b5ce685..dc3773e7 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.service.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.service.ts @@ -6,6 +6,7 @@ import { RpcException, ClientProxy } from '@nestjs/microservices'; import { from, lastValueFrom, map, scan, mergeMap } from 'rxjs'; import { Admin } from 'src/schemas/admin.entity'; import { appendFileSync } from 'fs'; +import { Tenant, TenantSchema } from 'src/schemas/tenant.schema'; @Injectable() export class CommunitiesService { @@ -13,7 +14,7 @@ export class CommunitiesService { @InjectModel(Community.name) private readonly communityModel: Model, @Inject('SERVICIO_USUARIOS') private readonly clientUserApp: ClientProxy, - ) {} + ) { } async create(community: CommunityDocument): Promise { return this.communityModel.create(community); @@ -56,15 +57,15 @@ export class CommunitiesService { } async remove(id: string) { - return this.communityModel.findOneAndUpdate({ _id: id }, {status: '-1'}, { + return this.communityModel.findOneAndUpdate({ _id: id }, { status: '-1' }, { new: true, - }); + }); } async changeStatus(id: string, status: string) { - return this.communityModel.findOneAndUpdate({ _id: id }, {status: status}, { + return this.communityModel.findOneAndUpdate({ _id: id }, { status: status }, { new: true, - }); + }); } async findCommunityAdmin(community: string, user_type: string) { @@ -78,4 +79,44 @@ export class CommunitiesService { const finalValue = await lastValueFrom(callback); return finalValue['response']; } + + + async saveTenant(id: string, number_house: string, ptenant_id: string) { + let community = await this.findOne(id); + await community.houses.map(house => { + if (house.number_house == number_house) { + if (house.tenants) { + + house.tenants.tenant_id = ptenant_id + } else { + let tenant = new Tenant() + tenant.tenant_id = ptenant_id; + house.tenants = tenant; + } + house.state = "ocupada" + } + return house; + }) + + 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 = ""; + house.state = "desocupada" + } + return house; + }) + + return await this.communityModel.findOneAndUpdate({ _id: id }, community, { + new: true, + }); + } } diff --git a/servicio-notificaciones/.env b/servicio-notificaciones/.env index 80c3aee2..7b8f623a 100644 --- a/servicio-notificaciones/.env +++ b/servicio-notificaciones/.env @@ -1,7 +1,7 @@ # mail MAIL_HOST=smtp.gmail.com -MAIL_USER=mbonilla.guti@gmail.com -MAIL_PASSWORD=laofghlofgffmyry +MAIL_USER=katoikiap4@gmail.com +MAIL_PASSWORD=snxwbncohehilkkz MAIL_FROM=noreply@example.com # optional diff --git a/servicio-notificaciones/src/email.controller.ts b/servicio-notificaciones/src/email.controller.ts index d1363138..0259684e 100644 --- a/servicio-notificaciones/src/email.controller.ts +++ b/servicio-notificaciones/src/email.controller.ts @@ -12,7 +12,7 @@ export class EmailController { sendMail(@Payload() toEmail: string) { var response = this.mailService.sendMail({ to: toEmail['email'], - from: 'mbonilla.guti@gmail.com', + from: 'katoikiap4@gmail.com', subject: 'Plain Text Email ✔', text: 'Welcome NestJS Email Sending Tutorial', }); @@ -25,7 +25,7 @@ export class EmailController { const image = "images/email.png"; var response = await this.mailService.sendMail({ to: user["email"], - from: "mbonilla.guti@gmail.com", + from: "katoikiap4@gmail.com", subject: 'HTML Dynamic Template', template: 'templateEmail', context: { @@ -51,7 +51,7 @@ export class EmailController { const logo = "images/Logo Katoikia.png"; var response = await this.mailService.sendMail({ to: user["email"], - from: "mbonilla.guti@gmail.com", + from: "katoikiap4@gmail.com", subject: 'Usuario registrado', template: 'emailCreateUserAdminCommunity', context: { @@ -77,4 +77,39 @@ export class EmailController { }); return response; } + + + @MessagePattern({ cmd: 'emailCreateUserTenant' }) + async emailCreateUserTenant(@Payload() user: any) { + const url = "http://localhost:3000/"; + const image = "images/email.png"; + const logo = "images/Logo Katoikia.png"; + var response = await this.mailService.sendMail({ + to: user["email"], + from: "katoikiap4@gmail.com", + subject: 'Usuario registrado', + template: 'emailCreateUserTenant', + context: { + name: user["name"], + password: user["password"], + date_entry: user["date_entry"], + email: user["email"], + community_name: user['community_name'], + number_house: user['number_house'] + }, + attachments: [ + { + filename: 'email.png', + path: __dirname + '/mails/images/email.png', + cid: 'image_email' //my mistake was putting "cid:logo@cid" here! + }, + { + filename: 'Logo_Katoikia.png', + path: __dirname + '/mails/images/Logo_Katoikia.png', + cid: 'logoKatoikia' //my mistake was putting "cid:logo@cid" here! + } + ] + }); + return response; + } } diff --git a/servicio-notificaciones/src/mails/emailCreateUserAdmin.hbs b/servicio-notificaciones/src/mails/emailCreateUserAdmin.hbs index 334dfd5b..4962f6cc 100644 --- a/servicio-notificaciones/src/mails/emailCreateUserAdmin.hbs +++ b/servicio-notificaciones/src/mails/emailCreateUserAdmin.hbs @@ -432,7 +432,7 @@

Información de contacto

    -
  • katoikiaapp@gmail.com
  • +
  • katoikiap4@gmail.com
diff --git a/servicio-notificaciones/src/mails/emailCreateUserAdminCommunity.hbs b/servicio-notificaciones/src/mails/emailCreateUserAdminCommunity.hbs index 9dc7ea9c..657f3c17 100644 --- a/servicio-notificaciones/src/mails/emailCreateUserAdminCommunity.hbs +++ b/servicio-notificaciones/src/mails/emailCreateUserAdminCommunity.hbs @@ -438,8 +438,8 @@

Información de contacto

    -
  • katoikiaapp@gmail.com
  • +
  • katoikiap4@gmail.com
diff --git a/servicio-notificaciones/src/mails/emailCreateUserTenant.hbs b/servicio-notificaciones/src/mails/emailCreateUserTenant.hbs new file mode 100644 index 00000000..a4a7586c --- /dev/null +++ b/servicio-notificaciones/src/mails/emailCreateUserTenant.hbs @@ -0,0 +1,459 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌  +
+ +
+ + + \ No newline at end of file diff --git a/servicio-notificaciones/src/notifications/dto/create-notification.dto.ts b/servicio-notificaciones/src/notifications/dto/create-notification.dto.ts deleted file mode 100644 index 98ca4791..00000000 --- a/servicio-notificaciones/src/notifications/dto/create-notification.dto.ts +++ /dev/null @@ -1 +0,0 @@ -export class CreateNotificationDto {} diff --git a/servicio-notificaciones/src/notifications/dto/update-notification.dto.ts b/servicio-notificaciones/src/notifications/dto/update-notification.dto.ts deleted file mode 100644 index f639cde4..00000000 --- a/servicio-notificaciones/src/notifications/dto/update-notification.dto.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { PartialType } from '@nestjs/mapped-types'; -import { CreateNotificationDto } from './create-notification.dto'; - -export class UpdateNotificationDto extends PartialType(CreateNotificationDto) { - id: number; -} diff --git a/servicio-notificaciones/src/notifications/notifications.controller.ts b/servicio-notificaciones/src/notifications/notifications.controller.ts deleted file mode 100644 index 4d8484f7..00000000 --- a/servicio-notificaciones/src/notifications/notifications.controller.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { Controller } from '@nestjs/common'; -import { MessagePattern, Payload } from '@nestjs/microservices'; -import { NotificationsService } from './notifications.service'; -import { CreateNotificationDto } from './dto/create-notification.dto'; -import { UpdateNotificationDto } from './dto/update-notification.dto'; - -@Controller() -export class NotificationsController { - constructor(private readonly notificationsService: NotificationsService) {} - - @MessagePattern({ cmd: 'createNotification' }) - create(@Payload() createNotificationDto: CreateNotificationDto) { - return this.notificationsService.create(createNotificationDto); - } - - @MessagePattern({ cmd: 'findAllNotifications' }) - findAll() { - return this.notificationsService.findAll(); - } - - @MessagePattern({ cmd: 'findOneNotification' }) - findOne(@Payload() id: number) { - return this.notificationsService.findOne(id); - } - - @MessagePattern({ cmd: 'updateNotification' }) - update(@Payload() updateNotificationDto: UpdateNotificationDto) { - return this.notificationsService.update( - updateNotificationDto.id, - updateNotificationDto, - ); - } - - @MessagePattern({ cmd: 'removeNotification' }) - remove(@Payload() id: number) { - return this.notificationsService.remove(id); - } -} diff --git a/servicio-notificaciones/src/notifications/notifications.module.ts b/servicio-notificaciones/src/notifications/notifications.module.ts deleted file mode 100644 index a3b7b79c..00000000 --- a/servicio-notificaciones/src/notifications/notifications.module.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Module } from '@nestjs/common'; -import { NotificationsService } from './notifications.service'; -import { NotificationsController } from './notifications.controller'; - -@Module({ - controllers: [NotificationsController], - providers: [NotificationsService], -}) -export class NotificationsModule {} diff --git a/servicio-notificaciones/src/notifications/notifications.service.ts b/servicio-notificaciones/src/notifications/notifications.service.ts deleted file mode 100644 index 41219fe1..00000000 --- a/servicio-notificaciones/src/notifications/notifications.service.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { CreateNotificationDto } from './dto/create-notification.dto'; -import { UpdateNotificationDto } from './dto/update-notification.dto'; - -@Injectable() -export class NotificationsService { - create(createNotificationDto: CreateNotificationDto) { - return 'This action adds a new notification'; - } - - findAll() { - return `This action returns all notifications`; - } - - findOne(id: number) { - return `This action returns a #${id} notification`; - } - - update(id: number, updateNotificationDto: UpdateNotificationDto) { - return `This action updates a #${id} notification`; - } - - remove(id: number) { - return `This action removes a #${id} notification`; - } -} diff --git a/servicio-notificaciones/src/notifications/schemas/notification.schemas.ts b/servicio-notificaciones/src/notifications/schemas/notification.schemas.ts deleted file mode 100644 index b79d7d57..00000000 --- a/servicio-notificaciones/src/notifications/schemas/notification.schemas.ts +++ /dev/null @@ -1 +0,0 @@ -export class Notification {} diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index 775ca4f0..d01aafbb 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -29,6 +29,12 @@ export class UsersController { return this.userService.createAdminCommunity(user); } + @MessagePattern({ cmd: 'createTenant' }) + createTenant(@Payload() user: UserDocument) { + return this.userService.createTenant(user); + } + + @MessagePattern({ cmd: 'findAllUsers' }) findAll() { return this.userService.findAll(); @@ -132,7 +138,10 @@ export class UsersController { @MessagePattern({ cmd: 'deleteTenant' }) deleteTenant(@Payload() user: any) { - return this.userService.deleteTenant(user['id']); + let tenant_id = user['_id']; + return this.userService.deleteTenant(tenant_id, + user['community_id'], + user['number_house']); } @MessagePattern({ cmd: 'changeStatus' }) diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index d117beeb..e5a17fef 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -24,6 +24,31 @@ export class UsersService { } + async createTenant(user: UserDocument) { + let password = user.password; + let passwordEncriptada = Md5.init(user.password); + user.password = passwordEncriptada; + let userCreated = await this.userModel.create(user); + await this.saveTenantNumHouse(user.community_id, user.number_house, userCreated['_id']); + + let community = await this.findCommunity(user.community_id); + user.community_id = community['name']; + + const pattern = { cmd: 'emailCreateUserTenant' }; + const payload = { + email: user['email'], password: password, name: user['name'], + date_entry: user['date_entry'], community_name: community['name'], + number_house: user['number_house'] + }; + + return this.clientNotificationtApp + .send(pattern, payload) + .pipe( + map((message: string) => ({ message })), + ); + } + + async createAdminCommunity(user: UserDocument) { let password = user.password; let passwordEncriptada = Md5.init(user.password); @@ -145,7 +170,6 @@ export class UsersService { return await this.userModel.find({ community_id: pcommunity_id, user_type: 4 }) } - async testSendMail(user: UserDocument) { let passwordEncriptada = Md5.init(user.password); user.password = passwordEncriptada; @@ -171,7 +195,7 @@ export class UsersService { } async deleteAdminSystem(id: string) { - return this.userModel.findOneAndUpdate({ _id: id }, { status: '-1' }, { + return this.userModel.findOneAndUpdate({ _id: id }, { status: '-1'}, { new: true, }); } @@ -182,10 +206,18 @@ export class UsersService { }); } - async deleteTenant(id: string) { - return this.userModel.findOneAndUpdate({ _id: id }, { status: '-1' }, { - new: true, - }); + async deleteTenant(tenant_id: string, community_id: string, number_house: string) { + + try{ + await this.userModel.findOneAndUpdate({ _id: tenant_id }, { status: '-1', number_house:''}, { + new: true, + }); + + return await this.deleteTenantNumHouse(community_id, number_house, tenant_id); + } catch(error){ + console.log(error) + return error; + } } async validateEmail(email: string) { @@ -231,5 +263,28 @@ export class UsersService { new: true, }); } + + + async saveTenantNumHouse(community_id: string, number_house: string, tenant_id: string) { + const pattern = { cmd: 'saveTenant' } + const payload = { _id: community_id, number_house: number_house, tenant_id: tenant_id } + + return await this.clientCommunityApp + .send(pattern, payload) + .pipe( + 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(pattern, payload) + .pipe( + map((response: string) => ({ response })) + ) + } } diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 244196da..459cee47 100644 --- a/web-ui/web-react/src/components/Inquilinos.js +++ b/web-ui/web-react/src/components/Inquilinos.js @@ -93,6 +93,16 @@ const Inquilinos = () => { ) } + + async function getHouses() { + let response = await fetch( + `http://localhost:4000/community/findHousesCommunity/${cookies.community_id}`, + { method: 'GET' }, + ) + let resList = await response.json() + setHousesList(await resList) + } + useEffect(() => { tenantsList() }, []) @@ -110,9 +120,9 @@ 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/createUser`, { + fetch(`http://localhost:4000/user/createTenant`, { cache: 'no-cache', method: 'POST', body: JSON.stringify(_tenant), @@ -125,7 +135,12 @@ 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') { + _tenant.status_text = 'Inactivo' + } _tenants.push(_tenant) toast.current.show({ severity: 'success', @@ -133,6 +148,7 @@ const Inquilinos = () => { detail: 'Inquilino creado', life: 3000, }) + setTenants(_tenants) setTenant(emptyTenant) setHouseNumber('') @@ -168,15 +184,50 @@ const Inquilinos = () => { } const deleteTenant = () => { - 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 _tenant = { + community_id: tenant.community_id, + number_house: tenant.number_house + }; + + fetch('http://localhost:4000/user/deleteTenant/' + tenant._id, { + cache: 'no-cache', + method: 'PUT', + body: JSON.stringify(_tenant), + headers: { + '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(); + } + ) + .then( + 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, + }) + } + ) + .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 }); + } + ); + + } const deleteSelectedTenants = () => {