katoikia-app/servicio-usuarios/src/users/users.controller.ts

140 lines
4.0 KiB
TypeScript
Raw Normal View History

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';
import { MongoExceptionFilter } from 'src/MongoExceptionFilter';
2022-06-29 09:23:07 +00:00
@Controller()
export class UsersController {
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);
}
@MessagePattern({ cmd: 'createAdminSystem' })
@UseFilters(MongoExceptionFilter)
createUserAdmin(@Payload() user: UserDocument) {
return this.userService.create(user);
}
@MessagePattern({ cmd: 'createGuard' })
createGuard(@Payload() user: UserDocument) {
return this.userService.create(user);
}
@MessagePattern({ cmd: 'createAdminCommunity' })
createAdminCommunity(@Payload() user: UserDocument) {
return this.userService.createAdminCommunity(user);
}
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' })
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-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-08-22 11:15:29 +00:00
@MessagePattern({ cmd: 'updateGuard' })
updateGuard(@Payload() guard: UserDocument) {
return this.userService.update(guard.id, guard);
}
2022-06-29 10:12:27 +00:00
@MessagePattern({ cmd: 'removeUser' })
2022-06-29 09:23:07 +00:00
remove(@Payload() id: string) {
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' })
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
}
//buscar solo admins del sistema
@MessagePattern({ cmd: 'findAdminSistema' })
allUsersAdminSistema() {
return this.userService.allUsersAdminSistema();
}
//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);
}
//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'],
);
}
@MessagePattern({ cmd: 'deleteAdminSystem' })
deleteAdminSystem(@Payload() user: any) {
2022-07-25 04:38:48 +00:00
return this.userService.deleteAdminSystem(user['id']);
}
2022-08-19 20:15:05 +00:00
@MessagePattern({ cmd: 'deleteAdminCommunity' })
deleteAdminCommunity(@Payload() user: any) {
return this.userService.deleteAdminCommunity(user['id']);
}
2022-08-21 10:35:59 +00:00
@MessagePattern({ cmd: 'deleteTenant' })
deleteTenant(@Payload() user: any) {
return this.userService.deleteTenant(user['id']);
}
@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
}