diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 8b89f3ce..f0feefba 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') @@ -208,6 +241,40 @@ export class AppController { return this.appService.changeStatusUser(pId, pStatus); } + @Put('user/updateAdminCommunity/:id') + updateAdminCommunity( + @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('community_id') community_id: string, + ) { + return this.appService.updateAdminCommunity( + id, + dni, + name, + last_name, + email, + phone, + community_id, + ); + } + + @Post('user/updateAdminSystem') + updateAdminSystem( + //Nombre, Apellidos, Correo electrónico, Cédula, Teléfono + @Body('_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, + ) { + return this.appService.updateAdminSystem(_id, dni, name, last_name, email, phone); + } + // #==== API Communities @Post('community/createCommunity') createCommunity( @@ -261,7 +328,21 @@ export class AppController { return this.appService.changeStatusCommunity(pId, pStatus); } - + @Get('community/findHousesCommunity/:id') + findHousesCommunity( + @Param('id') community_id: string, + ) { + return this.appService.findHousesCommunity(community_id); + } + + @Post('community/saveTenant') + saveTenant( + @Body('community_id') community_id: string, + @Body('number_house') number_house: string, + @Body('tenant_id') tenant_id: string, + ) { + return this.appService.saveTenant(community_id, number_house, tenant_id); + } // #==== API Common Areas @Post('commonArea/createCommonArea') createCommonArea( @@ -438,6 +519,11 @@ export class AppController { return this.appService.findPost(paramPost); } + @Delete('post/deletePost/:id') + deletePost(@Param('id') id: string) { + return this.appService.deletePost(id); + } + // #==== API Comment @Post('post/createComment') diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 66b9d89c..2ce6a609 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, @@ -120,7 +152,29 @@ export class AppService { .send(pattern, payload) .pipe(map((message: string) => ({ message }))); } - + updateAdminCommunity( + id: string, + dni: string, + name: string, + last_name: string, + email: string, + phone: number, + community_id: string, + ) { + const pattern = { cmd: 'updateAdminCommunity' }; + const payload = { + _id: id, + dni: dni, + name: name, + last_name: last_name, + email: email, + phone: phone, + community_id: community_id, + }; + return this.clientUserApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } //POST parameter from API createAdminSystem(dni: string, name: string, last_name: string, email: string, phone: number , user_type: string, status: string, date_entry: Date) { @@ -239,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 }))); @@ -255,6 +309,19 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + updateAdminSystem(_id: string, dni: string, name: string, + last_name: string, email: string, phone: number + ) { + const pattern = { cmd: 'updateAdminSystem' }; + const payload = { + _id: _id, dni: dni, name: name, last_name: last_name, + email: email, phone: phone + }; + return this.clientUserApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + //GET parameter from API findCommunityAdmin(community_id: string) { const pattern = { cmd: 'findCommunityAdmin' }; @@ -337,6 +404,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( @@ -557,6 +649,15 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + //DELETE + deletePost(paramPostId: string) { + const pattern = { cmd: 'removePost' }; + const payload = { id: paramPostId }; + return this.clientPostApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + // ====================== COMMNENT POSTS =============================== //Comment parameter from API 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 05c13169..bfdb4481 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(); @@ -66,7 +72,7 @@ export class UsersController { @MessagePattern({ cmd: 'updateUser' }) update(@Payload() user: UserDocument) { - return this.userService.update(user.id, user); + return this.userService.update(user._id, user); } @MessagePattern({ cmd: 'updateGuard' }) @@ -74,12 +80,20 @@ export class UsersController { return this.userService.update(guard.id, guard); } + @MessagePattern({ cmd: 'updateAdminCommunity' }) + updateAdminCommunity(@Payload() user: UserDocument) { + return this.userService.update(user._id, user); + } + @MessagePattern({ cmd: 'removeUser' }) remove(@Payload() id: string) { let dni = id['dni']; return this.userService.remove(dni); } - + @MessagePattern({ cmd: 'updateAdminSystem' }) + updateAdminSystem(@Payload() user: UserDocument) { + return this.userService.updateAdminSystem(user._id, user); + } //inicio de sesion @MessagePattern({ cmd: 'loginUser' }) findLogin(@Payload() body: string) { @@ -127,7 +141,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..1393b2bd 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); @@ -78,6 +103,15 @@ export class UsersService { }); } + async updateAdminSystem(id: string, user: UserDocument) { + return this.userModel.findOneAndUpdate({ _id: id }, { + name: user['name'], last_name: user['last_name'], + dni:user['dni'], email: user['email'], phone: user['phone'] + }, { + new: true, + }); + } + /* async remove(id: string) { return this.userModel.findByIdAndRemove({ _id: id }).exec(); }*/ @@ -145,7 +179,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 +204,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 +215,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 +272,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/AdministradoresComunidad.js b/web-ui/web-react/src/components/AdministradoresComunidad.js index 0ec73891..2fdd1289 100644 --- a/web-ui/web-react/src/components/AdministradoresComunidad.js +++ b/web-ui/web-react/src/components/AdministradoresComunidad.js @@ -49,6 +49,7 @@ const AdministradoresComunidad = () => { const dt = useRef(null); const [changeStatusAdminCommunityDialog, setChangeStatusAdminCommunityDialog] = useState(false); + const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar"); async function listaAdmin() { @@ -151,22 +152,22 @@ const AdministradoresComunidad = () => { } ); - + }; const deleteSelectedAdminsCommunity = () => { let _admins = listaAdmins.filter( (val) => !selectedAdminsCommunities.includes(val), ); - selectedAdminsCommunities.map((item) => { - fetch('http://localhost:4000/user/deleteAdminCommunity/' + item._id, { - cache: 'no-cache', - method: 'DELETE', - headers: { - 'Content-Type': 'application/json' - } - }) - }) + selectedAdminsCommunities.map((item) => { + fetch('http://localhost:4000/user/deleteAdminCommunity/' + item._id, { + cache: 'no-cache', + method: 'DELETE', + headers: { + 'Content-Type': 'application/json' + } + }) + }) setListaAdmins(_admins); setDeleteAdminsCommunitiesDialog(false); setSelectedAdminsCommunities(null); @@ -224,52 +225,104 @@ const AdministradoresComunidad = () => { ); } - const saveAdminCommunity = () => { - if (adminCommunity.name && adminCommunity.dni && adminCommunity.last_name && adminCommunity.email && adminCommunity.phone) { - - let _administrators = [...listaAdmins]; - let _adminCommunity = { ...adminCommunity }; - _adminCommunity.community_id = communityId; - console.log(_adminCommunity) - console.log(communityId) - - fetch('http://localhost:4000/user/createAdminCommunity', { - cache: 'no-cache', - method: 'POST', - body: JSON.stringify(_adminCommunity), - 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(() => { - - // _adminCommunity.community_id = communitiesList.find(c => c._id === _adminCommunity.community_id).name - - _administrators.push(_adminCommunity); - toast.current.show({ severity: 'success', summary: 'Registro exitoso', detail: 'Administrador de Comunidad de vivienda Creada', life: 3000 }); - - setListaAdmins(_administrators); - - setAdminCommunity(emptyAdminCommunity); - - }) - .catch( - err => console.log('Ocurrió un error con el fetch', err) - ); - - - } else { - setSubmitted(true); - + const findIndexById = (id) => { + let index = -1; + for (let i = 0; i < listaAdmins.length; i++) { + if (listaAdmins[i]._id === id) { + index = i; + break; + } } + return index; + + } + + const findRepeated = (name, value) => { + let _administrators = [...listaAdmins]; + let value_filtered = _administrators.filter(item => item[`${name}`] === value); + return value_filtered.length + } + + const saveAdminCommunity = () => { + let _administrators = [...listaAdmins]; + let _admin = { ...adminCommunity }; + _admin.community_id = communityId; + + if (adminCommunity._id === null) { + if (adminCommunity.name && adminCommunity.dni && + adminCommunity.last_name && adminCommunity.email && + adminCommunity.phone) { + + + fetch('http://localhost:4000/user/createAdminCommunity', { + cache: 'no-cache', + method: 'POST', + body: JSON.stringify(_admin), + 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(() => { + + // _adminCommunity.community_id = communitiesList.find(c => c._id === _adminCommunity.community_id).name + + _administrators.push(_admin); + toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Administrador de Comunidad de vivienda Creada', life: 3000 }); + + setListaAdmins(_administrators); + + setAdminCommunity(emptyAdminCommunity); + + }) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + + + } else { + setSubmitted(true); + } + } else { + console.log(`Actualizando admnistrador de comunidad: ${_admin}`) + _admin.community_id = communityId; + console.log(`Actualizando admnistrador de comunidad: ${_admin}`) + + fetch(`http://localhost:4000/user/updateAdminCommunity/${_admin._id}`, { + cache: 'no-cache', + method: 'PUT', + body: JSON.stringify(_admin), + 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: 'Administrador de comunidad actualizado', + life: 3000, + }) + toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Administrador de Comunidad de vivienda Actualizada', life: 3000 }); + + listaAdmin(); + setCommunityId(''); + + setAdminCommunity(emptyAdminCommunity); + }) + } + } const hideDeleteAdminCommunityDialog = () => { @@ -298,6 +351,19 @@ const AdministradoresComunidad = () => { setChangeStatusAdminCommunityDialog(true); }; + const editAdmin = (admin) => { + setAdminCommunity(admin); + setSaveButtonTitle('Actualizar'); + setCommunityId(admin.community_id) + } + + + const cancelEdit = () => { + setAdminCommunity(emptyAdminCommunity); + setSaveButtonTitle('Registrar'); + setCommunityId(''); + } + const actionsAdminCommunity = (rowData) => { let icono = ''; let text = ''; @@ -310,15 +376,22 @@ const AdministradoresComunidad = () => { } return (
+
@@ -503,7 +576,7 @@ const AdministradoresComunidad = () => { - +
@@ -548,7 +621,7 @@ const AdministradoresComunidad = () => {
- + onInputChange(e, 'name')} required autoFocus className={classNames({ 'p-invalid': submitted && adminCommunity.name === '' })} />
@@ -560,7 +633,7 @@ const AdministradoresComunidad = () => {
- + onInputChange(e, 'last_name')} required autoFocus className={classNames({ 'p-invalid': submitted && adminCommunity.last_name === '' })} />
@@ -572,12 +645,18 @@ const AdministradoresComunidad = () => {
- + - onInputChange(e, 'email')} required autoFocus className={classNames({ 'p-invalid': submitted && adminCommunity.email === '' })} /> + onInputChange(e, 'email')} required autoFocus + className={classNames({ 'p-invalid': submitted && + (adminCommunity.email === '' || findRepeated('email', adminCommunity.email) > 0) })} />
{submitted && adminCommunity.email === '' && Correo electrónico es requirido.} + {submitted && findRepeated('email', adminCommunity.email) > 0 && + Correo electrónico se encuentra repetido. + }
@@ -585,11 +664,17 @@ const AdministradoresComunidad = () => {
- + - onInputChange(e, 'dni')} required autoFocus className={classNames({ 'p-invalid': submitted && adminCommunity.dni === '' })} /> + onInputChange(e, 'dni')} required autoFocus + className={classNames({ 'p-invalid': submitted + && (adminCommunity.dni === '' || findRepeated('dni', adminCommunity.dni) > 0)})} />
- {submitted && adminCommunity.email === '' && Identificación es requirida.} + {submitted && adminCommunity.dni === '' && Identificación es requirida.} + {submitted && findRepeated('dni', adminCommunity.dni) > 0 && + Identificación se encuentra repetida. + }
@@ -617,7 +702,23 @@ const AdministradoresComunidad = () => { {submitted && !communityId && Comunidad es requirida.}
-
+ diff --git a/web-ui/web-react/src/components/AdministradoresSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js index a301c3ed..adf8b3bf 100644 --- a/web-ui/web-react/src/components/AdministradoresSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -12,8 +12,25 @@ import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons'; import { faAt } from '@fortawesome/free-solid-svg-icons'; import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons'; import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons'; +import classNames from 'classnames'; const AdministradoresSistema = () => { + + + let emptySysAdmin = { + _id: null, + dni: '', + name: '', + last_name: '', + email: '', + phone: '', + password: '', + user_type: '1', + status: '1', + status_text: '', + }; + + const [administrators, setAdministrators] = useState([]); const [urlFetch, setUrlFetch] = useState( 'http://localhost:4000/user/findAdminSistema/', @@ -30,19 +47,12 @@ const AdministradoresSistema = () => { const [changeStatusAdminSystemDialog, setChangeStatusAdminSystemDialog] = useState(false); const [changeStatusAdminsSystemDialog, setChangeStatusAdminsSystemDialog] = useState(false); + const [adminDialog, setAdminDialog] = useState(false); + const [submitted, setSubmitted] = useState(false); + + const [editAdminDialog, setEditAdminDialog] = useState(false); + const [saveButtonTitle, setSaveButtonTitle] = useState("Registrar") - let emptySysAdmin = { - _id: null, - dni: '', - name: '', - last_name: '', - email: '', - phone: '', - password: '', - user_type: '1', - status: '1', - status_text: '', - }; async function fetchP() { let nombres = await fetch(urlFetch, { method: 'GET' }); @@ -55,7 +65,7 @@ const AdministradoresSistema = () => { item.status_text = 'Activo'; } else if (item.status == '0') { item.status_text = 'Inactivo'; - } + } }) setAdministrators(await data); } @@ -64,46 +74,105 @@ const AdministradoresSistema = () => { fetchP(); }, []) - function registrarAdmin() { - var data = { - dni: document.getElementById('identificacion').value, - name: document.getElementById('nombre').value, - last_name: document.getElementById('apellidos').value, - email: document.getElementById('correo_electronico').value, - phone: document.getElementById('telefono').value, - password: document.getElementById('correo_electronico').value, - user_type: "1", //1 es admin - status: "1" - }; - setSysAdmin(data) - - fetch('http://localhost:4000/user/createAdminSystem/', { - cache: 'no-cache', - method: 'POST', - body: JSON.stringify(data), - headers: { - 'Content-Type': 'application/json' + const findIndexById = (id) => { + let index = -1; + for (let i = 0; i < administrators.length; i++) { + if (administrators[i]._id === id) { + index = i; + break; } - }) - .then( - function (response) { - if (response.status != 201) - console.log('Ocurrió un error con el servicio: ' + response.status); - else - return response.json(); + } + return index; + + } + + const findRepeated = (name, value) => { + let _administrators = [...administrators]; + let value_filtered = _administrators.filter(item => item[`${name}`] === value); + return value_filtered.length + } + + + function guardarAdmin() { + let _administrators = [...administrators]; + let _admin = { ...sysadmin }; + + if (_admin.name && _admin.dni && _admin.last_name && _admin.email && + _admin.phone) { + + + + if (findRepeated('email', _admin.email) || findRepeated('dni', _admin.dni)) { + setSubmitted(true); + + } else { + if (_admin._id) { + fetch('http://localhost:4000/user/updateAdminSystem/', { + cache: 'no-cache', + method: 'POST', + body: JSON.stringify(_admin), + 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) { + const index = findIndexById(sysadmin._id); + + _administrators[index] = _admin; + toast.current.show({ + severity: 'success', + summary: 'Exito', + detail: 'Administrador Actualizado', + life: 3000, + }); + setAdministrators(_administrators) + setEditAdminDialog(false); + setSysAdmin(emptySysAdmin); + } + ) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } else { + fetch('http://localhost:4000/user/createAdminSystem/', { + cache: 'no-cache', + method: 'POST', + body: JSON.stringify(_admin), + 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) { + _administrators.push(_admin); + setAdministrators(_administrators) + } + ) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); } - ) - .then( - function (response) { - let _administrators = [...administrators]; - let _admin = { ...sysadmin }; - _administrators.push(_admin); - setAdministrators(_administrators) - } - ) - .catch( - err => console.log('Ocurrió un error con el fetch', err) - ); + } + } else { + setSubmitted(true); + } } const cambiarStatusUser = () => { @@ -177,6 +246,28 @@ const AdministradoresSistema = () => { setChangeStatusAdminSystemDialog(true); }; + const hideAdminDialog = () => { + setSubmitted(false); + setAdminDialog(false); + setSysAdmin(emptySysAdmin); + }; + + const infoAdmin = (sysadmin) => { + setSysAdmin({ ...sysadmin }); + setAdminDialog(true); + }; + + const cancelEdit = () => { + setSaveButtonTitle('Registrar'); + setSubmitted(false); + setSysAdmin(emptySysAdmin); + } + + const editAdmin = (sysadmin) => { + setSysAdmin({ ...sysadmin }); + setSaveButtonTitle('Actualizar'); + }; + const deleteSysAdmin = () => { fetch('http://localhost:4000/user/deleteAdminSystem/' + sysadmin._id, { cache: 'no-cache', @@ -259,6 +350,21 @@ const AdministradoresSistema = () => { return (
+
+
-
Registro de un administrador del sistema
+
Mantenimiento Administrador del Sistema
-
- - +
+ + +
+
+ + + + onInputChange(e, 'name')} + required + autoFocus + className={classNames({ + 'p-invalid': submitted && sysadmin.name === '', + })} + /> +
+ {submitted && sysadmin.name === '' && + Nombre es requirido.} +
-
- - +
+ +
+
+ + + + onInputChange(e, 'last_name')} + required + autoFocus + className={classNames({ + 'p-invalid': submitted && sysadmin.last_name === '', + })} + /> +
+ {submitted && sysadmin.last_name === '' && ( + Apellido(s) es requerido. + )} +
-
+
- +
+
+ + + + onInputChange(e, 'email')} + required + autoFocus + className={classNames({ + 'p-invalid': submitted && (sysadmin.email === '' || findRepeated('email', sysadmin.email) > 0), + })} + /> +
+ {submitted && sysadmin.email === '' && ( + Correo electrónico es requerido. + )} + {submitted && findRepeated('email', sysadmin.email) > 0 && + Correo electrónico se encuentra repetido. + } +
-
- - +
+ +
+
+ + + + onInputChange(e, 'dni')} + required + autoFocus + className={classNames({ + 'p-invalid': submitted && (sysadmin.dni === '' || findRepeated('dni', sysadmin.dni) > 0), + })} + /> +
+ {submitted && sysadmin.dni === '' && ( + Identificación es requerida. + )} + {submitted && findRepeated('dni', sysadmin.dni) > 0 && + Identificación se encuentra repetida. + } +
- - + +
+
+ + + + onInputChange(e, 'phone')} + required + autoFocus + className={classNames({ + 'p-invalid': submitted && sysadmin.phone === '', + })} + /> +
+ {submitted && sysadmin.phone === '' && ( + Teléfono es requerido. + )} +
- +
+
+
+
+
); diff --git a/web-ui/web-react/src/components/Inquilinos.js b/web-ui/web-react/src/components/Inquilinos.js index 244196da..e4f49014 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,19 +184,71 @@ 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 = () => { - let _tenants = tenants.filter((val) => !selectedTentants.includes(val)) + let _tenants = tenants.filter( + (val) => !selectedTentants.includes(val) + ); + selectedTentants.map((item) => { + let _tenant = { + community_id: item.community_id, + number_house: item.number_house + }; + fetch('http://localhost:4000/user/deleteTenant/' + item._id, { + cache: 'no-cache', + method: 'PUT', + body: JSON.stringify(_tenant), + headers: { + 'Content-Type': 'application/json', + }, + }); + }); + setTenants(_tenants) setDeleteTenantsDialog(false) setSelectedTenants(null) @@ -806,7 +874,7 @@ const Inquilinos = () => { onInputChange(e, 'dni')} required autoFocus className={classNames({ 'p-invalid': submitted && tenant.dni === '' })} />
- {submitted && tenant.email === '' && Identificación es requerida.} + {submitted && tenant.dni === '' && Identificación es requerida.}
@@ -858,7 +926,7 @@ const Inquilinos = () => { /> {saveButtonTitle === 'Actualizar' && (
diff --git a/web-ui/web-react/src/components/RegistroComunicado.js b/web-ui/web-react/src/components/RegistroComunicado.js index e2d756a9..fbe91808 100644 --- a/web-ui/web-react/src/components/RegistroComunicado.js +++ b/web-ui/web-react/src/components/RegistroComunicado.js @@ -11,155 +11,205 @@ import { Toolbar } from 'primereact/toolbar'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faHome, faUserAlt } from '@fortawesome/free-solid-svg-icons'; import { faCommentAlt } from '@fortawesome/free-solid-svg-icons'; -import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons'; -import { faAt } from '@fortawesome/free-solid-svg-icons'; -import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons'; import { faEllipsis } from '@fortawesome/free-solid-svg-icons'; -import { faHomeAlt } from '@fortawesome/free-solid-svg-icons'; -import { Dropdown } from 'primereact/dropdown'; import classNames from 'classnames'; + const RegistroComunicado = () => { - let emptyComunicado = { - _id: null, - post: '', - user_id: '', - community_id: '' + let emptyComunicado = { + _id: null, + post: '', + user_id: '', + community_id: '' + }; + + useEffect(() => { + listaComunis(); + }, []) + + const [comunicado, setComunicado] = useState(emptyComunicado); + const [comunicados, setComunicados] = useState([]); + const [comunicadoId, setComunicadoId] = useState(null); + const [showDeleteDialog, setShowDeleteDialog] = useState(false); + const [submitted, setSubmitted] = useState(false); + const toast = useRef(null); + const dt = useRef(null); + const [cookies, setCookie] = useCookies(); + const [globalFilter, setGlobalFilter] = useState(null); + + async function listaComunis() { + let comunicadosResponse = await fetch('http://localhost:4000/post/allPosts', { method: 'GET' }); + const comunicadosJson = await comunicadosResponse.json(); + const comunicadosCommunity = comunicadosJson.message.filter((comunicado) => { + return comunicado.community_id === cookies.community_id; + }) + setComunicados(comunicadosCommunity); + console.log(comunicadosCommunity); + } + + const saveComunicado = () => { + var data = { + post: document.getElementById('txt_comunicado').value, + user_id: cookies.id, + community_id: cookies.community_id }; - useEffect(()=>{ - listaComunis(); - },[]) + fetch('http://localhost:4000/post/createPost', { + cache: 'no-cache', + method: 'POST', + body: JSON.stringify(data), + headers: { + 'Content-Type': 'application/json' + } + }).then((response) => { + if (response.status != 201) + console.log('Ocurrió un error con el servicio: ' + response.status); + else + return response.json(); + }).then((_response) => { + }).catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } - const [comunicado, setComunicado] = useState(emptyComunicado); - const [comunicados,setComuicados]=useState([]); - const [comunicadoId, setComunicadoId] = useState(null); - const [submitted, setSubmitted] = useState(false); - const toast = useRef(null); - const dt = useRef(null); - const [cookies, setCookie] = useCookies(); - const [globalFilter, setGlobalFilter] = useState(null); - - async function listaComunis() { - let comunicadosA=await fetch('http://localhost:4000/post/allPosts', {method:'GET'}); - let comunicadosRes= await comunicadosA.json(); - setComuicados(comunicadosRes.message); - console.log(comunicadosRes.message); - } - - - const saveComunicado = () => { - var data = { - post: document.getElementById('txt_comunicado').value, - user_id: cookies.id, - community_id: cookies.community_id - }; - - fetch('http://localhost:4000/post/createPost', { - cache: 'no-cache', - method: 'POST', - body: JSON.stringify(data), - 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) { - - } - ) - .catch( - err => console.log('Ocurrió un error con el fetch', err) - ); - } - - const header = ( - - -
-
Comunicados de la comunidad
- - - setGlobalFilter(e.target.value)} placeholder="Buscar..." /> - -
-
+ const header = ( + +
+
Comunicados de la comunidad
+ + + setGlobalFilter(e.target.value)} placeholder="Buscar..." /> + +
+
); const headerPost = ( <> -

- {' '} - {' '} - Descripción comunicado

+

+ {' '} + {' '} + Descripción comunicado

) const leftToolbarTemplate = () => { return ( - -
-
-
- ) -} - -const rightToolbarTemplate = () => { - return ( - -