envio de correos desde servicio usuarios
This commit is contained in:
		
							parent
							
								
									1b6f2b2f63
								
							
						
					
					
						commit
						02ebc62a56
					
				|  | @ -313,4 +313,21 @@ export class AppController { | ||||||
| 
 | 
 | ||||||
|     return this.appService.html(email, name); |     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); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | @ -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() { |   allUsers() { | ||||||
|     const pattern = { cmd: 'findAllUsers' }; |     const pattern = { cmd: 'findAllUsers' }; | ||||||
|     const payload = {}; |     const payload = {}; | ||||||
|  |  | ||||||
|  | @ -7,7 +7,7 @@ import { UsersModule } from './users/users.module'; | ||||||
|   imports: [ |   imports: [ | ||||||
|     ClientsModule.register([ |     ClientsModule.register([ | ||||||
|       { |       { | ||||||
|         name: "SERVICIO_NOTIFICACIONES", |         name: "SERVICIO_USUARIOS", | ||||||
|         transport: Transport.TCP, |         transport: Transport.TCP, | ||||||
|         options: { |         options: { | ||||||
|           host: "127.0.0.1", |           host: "127.0.0.1", | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ import { UsersService } from './users.service'; | ||||||
| 
 | 
 | ||||||
| @Controller() | @Controller() | ||||||
| export class UsersController { | export class UsersController { | ||||||
|   constructor(private readonly userService: UsersService) {} |   constructor(private readonly userService: UsersService) { } | ||||||
| 
 | 
 | ||||||
|   @MessagePattern({ cmd: 'createUser' }) |   @MessagePattern({ cmd: 'createUser' }) | ||||||
|   create(@Payload() user: UserDocument) { |   create(@Payload() user: UserDocument) { | ||||||
|  | @ -17,6 +17,8 @@ export class UsersController { | ||||||
|     return this.userService.create(user); |     return this.userService.create(user); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|   @MessagePattern({ cmd: 'findAllUsers' }) |   @MessagePattern({ cmd: 'findAllUsers' }) | ||||||
|   findAll() { |   findAll() { | ||||||
|     return this.userService.findAll(); |     return this.userService.findAll(); | ||||||
|  | @ -41,10 +43,10 @@ export class UsersController { | ||||||
| 
 | 
 | ||||||
|   //inicio de sesion
 |   //inicio de sesion
 | ||||||
|   @MessagePattern({ cmd: 'loginUser' }) |   @MessagePattern({ cmd: 'loginUser' }) | ||||||
|   findLogin(@Payload() body:string) { |   findLogin(@Payload() body: string) { | ||||||
|     let pemail= body['email']; |     let pemail = body['email']; | ||||||
|     let ppassword= body['password']; |     let ppassword = body['password']; | ||||||
|     return this.userService.findLogin(pemail,ppassword); |     return this.userService.findLogin(pemail, ppassword); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   //buscar solo admins del sistema
 |   //buscar solo admins del sistema
 | ||||||
|  | @ -58,4 +60,10 @@ export class UsersController { | ||||||
|   allUsersAdminComunidad() { |   allUsersAdminComunidad() { | ||||||
|     return this.userService.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); | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -4,9 +4,20 @@ import { MongooseModule } from '@nestjs/mongoose'; | ||||||
| 
 | 
 | ||||||
| import { UsersController } from './users.controller'; | import { UsersController } from './users.controller'; | ||||||
| import { User, UserSchema } from '../schemas/user.schema'; | import { User, UserSchema } from '../schemas/user.schema'; | ||||||
|  | import { ClientsModule, Transport } from "@nestjs/microservices"; | ||||||
| 
 | 
 | ||||||
| @Module({ | @Module({ | ||||||
|   imports: [ |   imports: [ | ||||||
|  |     ClientsModule.register([ | ||||||
|  |       { | ||||||
|  |         name: "SERVICIO_NOTIFICACIONES", | ||||||
|  |         transport: Transport.TCP, | ||||||
|  |         options: { | ||||||
|  |           host: "127.0.0.1", | ||||||
|  |           port: 3009 | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     ]), | ||||||
|     MongooseModule.forFeature([{ name: User.name, schema: UserSchema }]),  |     MongooseModule.forFeature([{ name: User.name, schema: UserSchema }]),  | ||||||
|   ], |   ], | ||||||
|   controllers: [UsersController], |   controllers: [UsersController], | ||||||
|  |  | ||||||
|  | @ -1,18 +1,25 @@ | ||||||
| import { Injectable } from '@nestjs/common'; | import { Injectable, Inject } from '@nestjs/common'; | ||||||
| import { Model } from 'mongoose'; | import { Model } from 'mongoose'; | ||||||
| import { User, UserDocument } from '../schemas/user.schema'; | import { User, UserDocument } from '../schemas/user.schema'; | ||||||
| import { InjectModel } from '@nestjs/mongoose'; | 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() | @Injectable() | ||||||
| export class UsersService { | export class UsersService { | ||||||
|   constructor( |   constructor( | ||||||
|     @InjectModel(User.name) private readonly userModel: Model<UserDocument>, |     @InjectModel(User.name) private readonly userModel: Model<UserDocument>, | ||||||
|   ) {} |     @Inject('SERVICIO_NOTIFICACIONES') private readonly clientNotificationtApp: ClientProxy, | ||||||
|  | 
 | ||||||
|  |   ) { } | ||||||
|   private publicKey: string; |   private publicKey: string; | ||||||
|   async create(user: UserDocument): Promise<User> { |   async create(user: UserDocument): Promise<User> { | ||||||
|     let passwordEncriptada=Md5.init(user.password); |     let passwordEncriptada = Md5.init(user.password); | ||||||
|     user.password=passwordEncriptada; |     user.password = passwordEncriptada; | ||||||
|     return this.userModel.create(user); |     return this.userModel.create(user); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | @ -41,18 +48,18 @@ export class UsersService { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   //inicio de sesion
 |   //inicio de sesion
 | ||||||
|   async findLogin(email: string, password: string) : Promise<User> { |   async findLogin(email: string, password: string): Promise<User> { | ||||||
|     let repo1=this.userModel; |     let repo1 = this.userModel; | ||||||
|     let userReturn = new Promise<User>((resolve, reject) => { |     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) { |         if (err) { | ||||||
|           reject(err); |           reject(err); | ||||||
|         } |         } | ||||||
|         else { |         else { | ||||||
|           let passwordEncriptada=Md5.init(password); |           let passwordEncriptada = Md5.init(password); | ||||||
|           if (res[0].password==passwordEncriptada) { |           if (res[0].password == passwordEncriptada) { | ||||||
|             resolve(res[0]); |             resolve(res[0]); | ||||||
|           } |           } | ||||||
|           else { |           else { | ||||||
|  | @ -75,5 +82,21 @@ export class UsersService { | ||||||
|     return this.userModel.find({ user_type: 2 }).exec(); |     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 })), | ||||||
|  |       ); | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue