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",
|
||||||
|
|
|
@ -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();
|
||||||
|
@ -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,13 +1,20 @@
|
||||||
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> {
|
||||||
|
@ -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