2022-07-27 21:54:31 +00:00
|
|
|
import { Controller, UseFilters } from '@nestjs/common';
|
2022-06-29 09:23:07 +00:00
|
|
|
import { MessagePattern, Payload } from '@nestjs/microservices';
|
|
|
|
import { User, UserDocument } from '../schemas/user.schema';
|
|
|
|
import { UsersService } from './users.service';
|
2022-07-27 21:54:31 +00:00
|
|
|
import { MongoExceptionFilter } from 'src/MongoExceptionFilter';
|
2022-06-29 09:23:07 +00:00
|
|
|
|
|
|
|
@Controller()
|
|
|
|
export class UsersController {
|
2022-08-03 03:50:01 +00:00
|
|
|
constructor(private readonly userService: UsersService) { }
|
2022-06-29 09:23:07 +00:00
|
|
|
|
|
|
|
@MessagePattern({ cmd: 'createUser' })
|
|
|
|
create(@Payload() user: UserDocument) {
|
|
|
|
return this.userService.create(user);
|
|
|
|
}
|
|
|
|
|
2022-07-01 01:43:19 +00:00
|
|
|
@MessagePattern({ cmd: 'createAdminSystem' })
|
2022-07-27 21:54:31 +00:00
|
|
|
@UseFilters(MongoExceptionFilter)
|
2022-07-01 01:43:19 +00:00
|
|
|
createUserAdmin(@Payload() user: UserDocument) {
|
|
|
|
return this.userService.create(user);
|
|
|
|
}
|
|
|
|
|
2022-07-19 02:55:01 +00:00
|
|
|
@MessagePattern({ cmd: 'createGuard' })
|
|
|
|
createGuard(@Payload() user: UserDocument) {
|
|
|
|
return this.userService.create(user);
|
|
|
|
}
|
|
|
|
|
2022-07-26 22:59:29 +00:00
|
|
|
@MessagePattern({ cmd: 'createAdminCommunity' })
|
|
|
|
createAdminCommunity(@Payload() user: UserDocument) {
|
|
|
|
return this.userService.createAdminCommunity(user);
|
|
|
|
}
|
2022-07-16 01:02:17 +00:00
|
|
|
|
2022-06-29 09:23:07 +00:00
|
|
|
@MessagePattern({ cmd: 'findAllUsers' })
|
|
|
|
findAll() {
|
|
|
|
return this.userService.findAll();
|
|
|
|
}
|
|
|
|
|
2022-06-29 10:12:27 +00:00
|
|
|
@MessagePattern({ cmd: 'findUserDNI' })
|
2022-07-01 09:09:48 +00:00
|
|
|
findOne(@Payload() id: string) {
|
|
|
|
let dni = id['dni'];
|
2022-06-29 10:12:27 +00:00
|
|
|
return this.userService.findOneByDNI(dni);
|
2022-06-29 09:23:07 +00:00
|
|
|
}
|
2022-07-19 04:28:56 +00:00
|
|
|
|
2022-08-01 05:29:48 +00:00
|
|
|
@MessagePattern({ cmd: 'findById' })
|
|
|
|
findById(@Payload() id: string) {
|
|
|
|
let _id = id['id'];
|
|
|
|
return this.userService.findOne(_id);
|
|
|
|
}
|
|
|
|
|
2022-07-19 04:28:56 +00:00
|
|
|
@MessagePattern({ cmd: 'findGuardsCommunity' })
|
|
|
|
findGuardsCommunity(@Payload() community_id: string) {
|
|
|
|
let pcommunity_id = community_id['community_id'];
|
|
|
|
return this.userService.findGuardsCommunity(pcommunity_id);
|
|
|
|
}
|
2022-07-22 05:10:36 +00:00
|
|
|
|
2022-07-24 05:54:05 +00:00
|
|
|
@MessagePattern({ cmd: 'findTenantsCommunity' })
|
|
|
|
findTenantsCommunity(@Payload() community_id: string) {
|
|
|
|
let pcommunity_id = community_id['community_id'];
|
|
|
|
return this.userService.findTenantsCommunity(pcommunity_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
@MessagePattern({ cmd: 'findTenants' })
|
|
|
|
findTenants() {
|
|
|
|
return this.userService.findTenants();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-29 10:12:27 +00:00
|
|
|
@MessagePattern({ cmd: 'updateUser' })
|
2022-06-29 09:23:07 +00:00
|
|
|
update(@Payload() user: UserDocument) {
|
|
|
|
return this.userService.update(user.id, user);
|
|
|
|
}
|
|
|
|
|
2022-06-29 10:12:27 +00:00
|
|
|
@MessagePattern({ cmd: 'removeUser' })
|
2022-06-29 09:23:07 +00:00
|
|
|
remove(@Payload() id: string) {
|
2022-07-01 09:09:48 +00:00
|
|
|
let dni = id['dni'];
|
|
|
|
return this.userService.remove(dni);
|
2022-06-29 09:23:07 +00:00
|
|
|
}
|
2022-07-11 02:22:34 +00:00
|
|
|
|
|
|
|
//inicio de sesion
|
|
|
|
@MessagePattern({ cmd: 'loginUser' })
|
2022-07-16 01:02:17 +00:00
|
|
|
findLogin(@Payload() body: string) {
|
|
|
|
let pemail = body['email'];
|
|
|
|
let ppassword = body['password'];
|
|
|
|
return this.userService.findLogin(pemail, ppassword);
|
2022-07-11 02:22:34 +00:00
|
|
|
}
|
2022-07-15 01:01:02 +00:00
|
|
|
|
|
|
|
//buscar solo admins del sistema
|
|
|
|
@MessagePattern({ cmd: 'findAdminSistema' })
|
|
|
|
allUsersAdminSistema() {
|
|
|
|
return this.userService.allUsersAdminSistema();
|
|
|
|
}
|
2022-07-15 03:16:02 +00:00
|
|
|
|
2022-07-16 01:02:17 +00:00
|
|
|
//buscar solo admins de comunidad
|
|
|
|
@MessagePattern({ cmd: 'findAdminComunidad' })
|
|
|
|
allUsersAdminComunidad() {
|
|
|
|
return this.userService.allUsersAdminComunidad();
|
|
|
|
}
|
|
|
|
|
|
|
|
//Prueba de envio de correo despues de registro, llamando a microservicio notificaciones
|
|
|
|
@MessagePattern({ cmd: 'testSendMail' })
|
|
|
|
testSendMail(@Payload() user: UserDocument) {
|
|
|
|
return this.userService.testSendMail(user);
|
|
|
|
}
|
2022-07-19 19:56:48 +00:00
|
|
|
|
|
|
|
//buscar usuario de una comunidad
|
|
|
|
@MessagePattern({ cmd: 'findOneCommunityUser' })
|
|
|
|
findCommunityUser(@Payload() user: any) {
|
2022-07-25 04:38:48 +00:00
|
|
|
return this.userService.findCommunityUser(
|
|
|
|
user['community_id'],
|
|
|
|
user['user_type'],
|
|
|
|
);
|
2022-07-19 19:56:48 +00:00
|
|
|
}
|
|
|
|
|
2022-07-22 07:22:13 +00:00
|
|
|
@MessagePattern({ cmd: 'deleteAdminSystem' })
|
|
|
|
deleteAdminSystem(@Payload() user: any) {
|
2022-07-25 04:38:48 +00:00
|
|
|
return this.userService.deleteAdminSystem(user['id']);
|
2022-07-22 07:22:13 +00:00
|
|
|
}
|
2022-07-19 19:56:48 +00:00
|
|
|
|
2022-08-19 20:15:05 +00:00
|
|
|
|
|
|
|
@MessagePattern({ cmd: 'deleteAdminCommunity' })
|
|
|
|
deleteAdminCommunity(@Payload() user: any) {
|
|
|
|
return this.userService.deleteAdminCommunity(user['id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-26 22:59:29 +00:00
|
|
|
|
2022-08-03 03:50:01 +00:00
|
|
|
@MessagePattern({ cmd: 'changeStatus' })
|
|
|
|
changeStatus(@Payload() body: string) {
|
|
|
|
let pid = body['id'];
|
|
|
|
let pstatus = body['status'];
|
|
|
|
return this.userService.changeStatus(pid, pstatus);
|
|
|
|
}
|
2022-06-29 09:23:07 +00:00
|
|
|
}
|