envio de correos desde servicio usuarios

This commit is contained in:
Mariela 2022-07-15 19:02:17 -06:00
parent 1b6f2b2f63
commit 02ebc62a56
6 changed files with 107 additions and 34 deletions

View File

@ -313,4 +313,21 @@ export class AppController {
return this.appService.html(email, name);
}
// #==== API Users
@Post('user/testSendMail')
testSendMail(
@Body('dni') dni: string,
@Body('name') name: string,
@Body('last_name') last_name: string,
@Body('email') email: string,
@Body('phone') phone: number,
@Body('password') password: string,
@Body('user_type') user_type: string,
@Body('status') status: string,
@Body('date_entry') date_entry: Date,
) {
return this.appService.testSendMail(dni, name, last_name, email, phone, password,
user_type, status, date_entry);
}
}

View File

@ -50,6 +50,20 @@ export class AppService {
);
}
testSendMail(dni: string, name: string, last_name: string, email: string, phone: number
, password: string, user_type: string, status: string, date_entry: Date) {
const pattern = { cmd: 'testSendMail' };
const payload = {
dni: dni, name: name, last_name: last_name, email: email, phone: phone,
password: password, user_type: user_type, status: status, date_entry: date_entry
};
return this.clientUserApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message })),
);
}
allUsers() {
const pattern = { cmd: 'findAllUsers' };
const payload = {};

View File

@ -7,7 +7,7 @@ import { UsersModule } from './users/users.module';
imports: [
ClientsModule.register([
{
name: "SERVICIO_NOTIFICACIONES",
name: "SERVICIO_USUARIOS",
transport: Transport.TCP,
options: {
host: "127.0.0.1",

View File

@ -5,7 +5,7 @@ import { UsersService } from './users.service';
@Controller()
export class UsersController {
constructor(private readonly userService: UsersService) {}
constructor(private readonly userService: UsersService) { }
@MessagePattern({ cmd: 'createUser' })
create(@Payload() user: UserDocument) {
@ -17,6 +17,8 @@ export class UsersController {
return this.userService.create(user);
}
@MessagePattern({ cmd: 'findAllUsers' })
findAll() {
return this.userService.findAll();
@ -41,10 +43,10 @@ export class UsersController {
//inicio de sesion
@MessagePattern({ cmd: 'loginUser' })
findLogin(@Payload() body:string) {
let pemail= body['email'];
let ppassword= body['password'];
return this.userService.findLogin(pemail,ppassword);
findLogin(@Payload() body: string) {
let pemail = body['email'];
let ppassword = body['password'];
return this.userService.findLogin(pemail, ppassword);
}
//buscar solo admins del sistema
@ -53,9 +55,15 @@ export class UsersController {
return this.userService.allUsersAdminSistema();
}
//buscar solo admins de comunidad
@MessagePattern({ cmd: 'findAdminComunidad' })
allUsersAdminComunidad() {
return this.userService.allUsersAdminComunidad();
}
//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);
}
}

View File

@ -4,9 +4,20 @@ import { MongooseModule } from '@nestjs/mongoose';
import { UsersController } from './users.controller';
import { User, UserSchema } from '../schemas/user.schema';
import { ClientsModule, Transport } from "@nestjs/microservices";
@Module({
imports: [
ClientsModule.register([
{
name: "SERVICIO_NOTIFICACIONES",
transport: Transport.TCP,
options: {
host: "127.0.0.1",
port: 3009
}
}
]),
MongooseModule.forFeature([{ name: User.name, schema: UserSchema }]),
],
controllers: [UsersController],

View File

@ -1,18 +1,25 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Inject } from '@nestjs/common';
import { Model } from 'mongoose';
import { User, UserDocument } from '../schemas/user.schema';
import { InjectModel } from '@nestjs/mongoose';
import {Md5} from "md5-typescript";
import { Md5 } from "md5-typescript";
import { map } from 'rxjs/operators';
import { RpcException, ClientProxy } from '@nestjs/microservices';
@Injectable()
export class UsersService {
constructor(
@InjectModel(User.name) private readonly userModel: Model<UserDocument>,
) {}
@Inject('SERVICIO_NOTIFICACIONES') private readonly clientNotificationtApp: ClientProxy,
) { }
private publicKey: string;
async create(user: UserDocument): Promise<User> {
let passwordEncriptada=Md5.init(user.password);
user.password=passwordEncriptada;
let passwordEncriptada = Md5.init(user.password);
user.password = passwordEncriptada;
return this.userModel.create(user);
}
@ -41,18 +48,18 @@ export class UsersService {
}
//inicio de sesion
async findLogin(email: string, password: string) : Promise<User> {
let repo1=this.userModel;
async findLogin(email: string, password: string): Promise<User> {
let repo1 = this.userModel;
let userReturn = new Promise<User>((resolve, reject) => {
let repo =repo1;
let repo = repo1;
repo.find({ email : email }).exec((err, res) => {
repo.find({ email: email }).exec((err, res) => {
if (err) {
reject(err);
}
else {
let passwordEncriptada=Md5.init(password);
if (res[0].password==passwordEncriptada) {
let passwordEncriptada = Md5.init(password);
if (res[0].password == passwordEncriptada) {
resolve(res[0]);
}
else {
@ -70,10 +77,26 @@ export class UsersService {
return this.userModel.find({ user_type: 1 }).exec();
}
//find admin de comunidad
async allUsersAdminComunidad(): Promise<User[]> {
return this.userModel.find({ user_type: 2 }).exec();
}
//find admin de comunidad
async allUsersAdminComunidad(): Promise<User[]> {
return this.userModel.find({ user_type: 2 }).exec();
}
async testSendMail(user: UserDocument) {
let passwordEncriptada = Md5.init(user.password);
user.password = passwordEncriptada;
this.userModel.create(user)
/*.then(() => {
} );*/
const pattern = { cmd: 'html' };
const payload = { email: user['email'], name: user['name'] };
return this.clientNotificationtApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message })),
);
}
}