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 {
|
|
|
|
constructor(private readonly userService: UsersService) {}
|
|
|
|
|
|
|
|
@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-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-01 01:43:19 +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' })
|
|
|
|
findLogin(@Payload() body:string) {
|
|
|
|
let pemail= body['email'];
|
2022-07-11 02:46:54 +00:00
|
|
|
let ppassword= body['password'];
|
|
|
|
return this.userService.findHero(pemail,ppassword);
|
2022-07-11 02:22:34 +00:00
|
|
|
}
|
2022-06-29 09:23:07 +00:00
|
|
|
}
|