2022-06-29 09:23:07 +00:00
|
|
|
import { Controller } from '@nestjs/common';
|
|
|
|
import { MessagePattern, Payload } from '@nestjs/microservices';
|
|
|
|
import { User, UserDocument } from '../schemas/user.schema';
|
|
|
|
import { UsersService } from './users.service';
|
|
|
|
|
|
|
|
@Controller()
|
|
|
|
export class UsersController {
|
2022-07-16 01:02:17 +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' })
|
|
|
|
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-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
|
|
|
|
|
|
|
@MessagePattern({ cmd: 'findGuardsCommunity' })
|
|
|
|
findGuardsCommunity(@Payload() community_id: string) {
|
|
|
|
let pcommunity_id = community_id['community_id'];
|
|
|
|
return this.userService.findGuardsCommunity(pcommunity_id);
|
|
|
|
}
|
2022-07-01 01:43:19 +00:00
|
|
|
|
2022-07-22 05:10:36 +00:00
|
|
|
|
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) {
|
|
|
|
return this.userService.findCommunityUser(user["community_id"], user["user_type"]);
|
|
|
|
}
|
|
|
|
|
2022-07-22 07:22:13 +00:00
|
|
|
@MessagePattern({ cmd: 'deleteAdminSystem' })
|
|
|
|
deleteAdminSystem(@Payload() user: any) {
|
|
|
|
console.log("entró")
|
|
|
|
|
|
|
|
return this.userService.deleteAdminSystem(user["id"]);
|
|
|
|
}
|
2022-07-19 19:56:48 +00:00
|
|
|
|
2022-06-29 09:23:07 +00:00
|
|
|
}
|
2022-07-19 19:56:48 +00:00
|
|
|
|