Merge branch 'dev' into issue-error-user-service

This commit is contained in:
Mariela 2022-07-29 00:24:49 -06:00
commit c498db7937
12 changed files with 1524 additions and 3729 deletions

View File

@ -22,7 +22,7 @@ export class EmailController {
@MessagePattern({ cmd: 'html' }) @MessagePattern({ cmd: 'html' })
async postHTMLEmail(@Payload() user: any) { async postHTMLEmail(@Payload() user: any) {
const url = "http://localhost:3000/"; const url = "http://localhost:3000/";
const image = "images/email.ong"; const image = "images/email.png";
var response = await this.mailService.sendMail({ var response = await this.mailService.sendMail({
to: user["email"], to: user["email"],
from: "mbonilla.guti@gmail.com", from: "mbonilla.guti@gmail.com",
@ -48,7 +48,7 @@ export class EmailController {
async emailCreateUserAdmin(@Payload() user: any) { async emailCreateUserAdmin(@Payload() user: any) {
const url = "http://localhost:3000/"; const url = "http://localhost:3000/";
const image = "images/email.png"; const image = "images/email.png";
const logo = "images/Logo Katoikia.svg"; const logo = "images/Logo Katoikia.png";
var response = await this.mailService.sendMail({ var response = await this.mailService.sendMail({
to: user["email"], to: user["email"],
from: "mbonilla.guti@gmail.com", from: "mbonilla.guti@gmail.com",
@ -69,8 +69,8 @@ export class EmailController {
cid: 'image_email' //my mistake was putting "cid:logo@cid" here! cid: 'image_email' //my mistake was putting "cid:logo@cid" here!
}, },
{ {
filename: 'Logo Katoikia.svg', filename: 'Logo_Katoikia.png',
path: __dirname + '/mails/images/Logo Katoikia.svg', path: __dirname + '/mails/images/Logo_Katoikia.png',
cid: 'logoKatoikia' //my mistake was putting "cid:logo@cid" here! cid: 'logoKatoikia' //my mistake was putting "cid:logo@cid" here!
} }
] ]

View File

@ -10,6 +10,10 @@
<title></title> <!-- The title tag shows in email notifications, like Android 4.4. --> <title></title> <!-- The title tag shows in email notifications, like Android 4.4. -->
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Lato:300,400,700" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.2/css/all.min.css"
integrity="sha512-1sCRPdkRXhBV2PBLUdRb4tMg1w2YPf37qatUFeS7zlBy7jJI8Lf4VHwWfZZfpXtYSLy85pkm9GaYVYMfw5BC1A=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<!-- CSS Reset : BEGIN --> <!-- CSS Reset : BEGIN -->
<style> <style>
@ -119,7 +123,7 @@
<!-- Progressive Enhancements : BEGIN --> <!-- Progressive Enhancements : BEGIN -->
<style> <style>
.primary { .primary {
background: #30e3ca; background: #D7A86E;
} }
.bg_white { .bg_white {
@ -150,7 +154,7 @@
.btn.btn-primary { .btn.btn-primary {
border-radius: 5px; border-radius: 5px;
background: #30e3ca; background: #D7A86E;
color: #ffffff; color: #ffffff;
} }
@ -185,6 +189,7 @@
color: #000000; color: #000000;
margin-top: 0; margin-top: 0;
font-weight: 400; font-weight: 400;
margin-bottom: 12px;
} }
body { body {
@ -192,11 +197,11 @@
font-weight: 400; font-weight: 400;
font-size: 15px; font-size: 15px;
line-height: 1.8; line-height: 1.8;
color: rgba(0, 0, 0, .4); color: rgba(0, 0, 0, 0.808);
} }
a { a {
color: #30e3ca; color: #D7A86E;
} }
table {} table {}
@ -208,7 +213,7 @@
} }
.logo h1 a { .logo h1 a {
color: #30e3ca; color: #D7A86E;
font-size: 24px; font-size: 24px;
font-weight: 700; font-weight: 700;
font-family: 'Lato', sans-serif; font-family: 'Lato', sans-serif;
@ -221,7 +226,7 @@
} }
.hero .text { .hero .text {
color: rgba(0, 0, 0, .3); color: rgba(0, 0, 0, 0.884);
} }
.hero .text h2 { .hero .text h2 {
@ -239,7 +244,7 @@
.hero .text h2 span { .hero .text h2 span {
font-weight: 600; font-weight: 600;
color: #30e3ca; color: #D7A86E;
} }
@ -272,7 +277,7 @@
content: ''; content: '';
width: 100%; width: 100%;
height: 2px; height: 2px;
background: #30e3ca; background: #D7A86E;
margin: 0 auto; margin: 0 auto;
} }
@ -281,8 +286,7 @@
} }
.heading-section-white h2 { .heading-section-white h2 {
font-family: line-height: 1;
line-height: 1;
padding-bottom: 0; padding-bottom: 0;
} }
@ -356,17 +360,23 @@
<td valign="top" class="bg_white" style="padding: 1em 2.5em 0 2.5em;"> <td valign="top" class="bg_white" style="padding: 1em 2.5em 0 2.5em;">
<table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%"> <table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr> <tr>
<td class="logo" style="text-align: center;">
<td class="logo" style="text-align: right;">
<img src="cid:logoLatoikia" alt="Logo Katoikia"
style="width: 60px; max-width: 60px; height: auto; margin: auto; display: block; float: right;">
</td>
<td class="logo" style="text-align: left;">
<h1><a href="#">Katoikia</a></h1> <h1><a href="#">Katoikia</a></h1>
</td> </td>
</tr> </tr>
</table> </table>
</td> </td>
</tr><!-- end tr --> </tr><!-- end tr -->
<tr> <tr>
<td valign="middle" class="hero bg_white" style="padding: 3em 0 2em 0;"> <td valign="middle" class="hero bg_white" style="padding: 3em 0 2em 0;">
<img src="cid:logoLatoikia" alt="" <img src="cid:image_email" alt="Logo Katoikia"
style="width: 300px; max-width: 600px; height: auto; margin: auto; display: block;"> style="width: 150px; max-width: 300px; height: auto; margin: auto; display: block;">
</td> </td>
</tr><!-- end tr --> </tr><!-- end tr -->
<tr> <tr>
@ -375,16 +385,22 @@
<tr> <tr>
<td> <td>
<div class="text" style="padding: 0 2.5em; text-align: center;"> <div class="text" style="padding: 0 2.5em; text-align: center;">
<h2>Hola, {{ name }}</h2> <h2> Hola , {{ name }} <i class="fa-regular fa-face-smile-wink"
<h2>Ha sido registrado como un Administrador General del sitio web Katoikia</h2> style="color:#D7A86E; font-size: 0.8em; margin-left: 20px;"></i></h2>
<h3>Fecha de registro {{date_entry}}</h3> <h3>Ha sido registrado como un Administrador General del sitio web Katoikia</h3>
<h4><i class="fa-solid fa-calendar-day"
style="color:#D7A86E; margin-right: 10px;"></i> Fecha de registro
{{date_entry}}</h4>
</div>
<div class="text" style="padding: 0 4em; text-align: left;">
<h3>Estas son sus credenciales:</h3> <h3>Estas son sus credenciales:</h3>
<ul> <p><i class="fa-regular fa-envelope" style="color:#D7A86E; margin-right: 10px;"></i> Correo electronico: {{email}}</p>
<li>Correo electronico: {{email}}</li> <p><i class="fa-solid fa-key" style="color:#D7A86E; margin-right: 10px;"></i> Password: {{password}}</p>
<li>Password: {{password}}</li>
</ul> </div>
<h3>Inicie sesión en el sitio web para poder acceder y disfrutar todos sus benefucuin</h3> <div class="text" style="padding: 0 2.5em; text-align: center;">
<h3>Inicie sesión en el sitio web para poder acceder y disfrutar todos sus
beneficios</h3>
<p><a href="{{ url }}" class="btn btn-primary">Iniciar sesión</a></p> <p><a href="{{ url }}" class="btn btn-primary">Iniciar sesión</a></p>
</div> </div>
</td> </td>
@ -392,46 +408,45 @@
</table> </table>
</td> </td>
</tr><!-- end tr --> </tr><!-- end tr -->
<!-- 1 Column Text + Button : END --> <!-- 1 Column Text + Button : END -->
</table> </table>
<table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%" <table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%"
style="margin: auto;"> style="margin: auto;">
<tr> <td valign="middle" class="bg_light footer email-section">
<td valign="middle" class="bg_light footer email-section"> <table>
<table> <tr>
<td valign="top" width="33.333%" style="padding-top: 20px">
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
<tr> <tr>
<td valign="top" width="33.333%" style="padding-top: 20px;"> <td style="text-align: left; padding-right: 10px">
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%"> <h3 class="heading">Acerca de</h3>
<tr> <p>Katoikia es su compañero más cercano para poder estar en contacto con sus vecinos y conocer sobre los mejores anuncios sobre su comunidad.</p>
<td style="text-align: left; padding-right: 10px;"> </td>
<!-- <h3 class="heading">About</h3>
<p>A small river named Duden flows by their place and supplies it with
the necessary regelialia.</p>
-->
</td>
</tr>
</table>
</td>
<td valign="top" width="33.333%" style="padding-top: 20px;">
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td style="text-align: left; padding-left: 5px; padding-right: 5px;">
<!-- <h3 class="heading">Informacion de contacto</h3>
<ul>
<li><span class="text">203 Fake St. Mountain View, San Francisco,
California, USA</span></li>
<li><span class="text">+2 392 3929 210</span></a></li>
</ul>
-->
</td>
</tr>
</table>
</td>
</tr> </tr>
</table> </table>
</td> </td>
</tr><!-- end: tr --> <td valign="top" width="33.333%" style="padding-top: 20px">
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td style="text-align: left; padding-left: 5px; padding-right: 5px">
<h3 class="heading">Información de contacto</h3>
<ul>
<li><span href="mailto:katoikiaapp@gmail.com" class="text">katoikiaapp@gmail.com</span></li>
</ul>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<!-- end: tr -->
<tr>
<td class="bg_light" style="text-align: center">
<p><a href="http://localhost:3000" style="color: rgba(0, 0, 0, 0.8)">katoikiaapp.org</a></p>
</td>
</table> </table>

View File

@ -10,6 +10,10 @@
<title></title> <!-- The title tag shows in email notifications, like Android 4.4. --> <title></title> <!-- The title tag shows in email notifications, like Android 4.4. -->
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Lato:300,400,700" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.2/css/all.min.css"
integrity="sha512-1sCRPdkRXhBV2PBLUdRb4tMg1w2YPf37qatUFeS7zlBy7jJI8Lf4VHwWfZZfpXtYSLy85pkm9GaYVYMfw5BC1A=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<!-- CSS Reset : BEGIN --> <!-- CSS Reset : BEGIN -->
<style> <style>
@ -119,7 +123,7 @@
<!-- Progressive Enhancements : BEGIN --> <!-- Progressive Enhancements : BEGIN -->
<style> <style>
.primary { .primary {
background: #30e3ca; background: #D7A86E;
} }
.bg_white { .bg_white {
@ -150,7 +154,7 @@
.btn.btn-primary { .btn.btn-primary {
border-radius: 5px; border-radius: 5px;
background: #30e3ca; background: #D7A86E;
color: #ffffff; color: #ffffff;
} }
@ -185,6 +189,7 @@
color: #000000; color: #000000;
margin-top: 0; margin-top: 0;
font-weight: 400; font-weight: 400;
margin-bottom: 12px;
} }
body { body {
@ -192,11 +197,11 @@
font-weight: 400; font-weight: 400;
font-size: 15px; font-size: 15px;
line-height: 1.8; line-height: 1.8;
color: rgba(0, 0, 0, .4); color: rgba(0, 0, 0, 0.808);
} }
a { a {
color: #30e3ca; color: #D7A86E;
} }
table {} table {}
@ -208,7 +213,7 @@
} }
.logo h1 a { .logo h1 a {
color: #30e3ca; color: #D7A86E;
font-size: 24px; font-size: 24px;
font-weight: 700; font-weight: 700;
font-family: 'Lato', sans-serif; font-family: 'Lato', sans-serif;
@ -221,7 +226,7 @@
} }
.hero .text { .hero .text {
color: rgba(0, 0, 0, .3); color: rgba(0, 0, 0, 0.884);
} }
.hero .text h2 { .hero .text h2 {
@ -239,7 +244,7 @@
.hero .text h2 span { .hero .text h2 span {
font-weight: 600; font-weight: 600;
color: #30e3ca; color: #D7A86E;
} }
@ -272,7 +277,7 @@
content: ''; content: '';
width: 100%; width: 100%;
height: 2px; height: 2px;
background: #30e3ca; background: #D7A86E;
margin: 0 auto; margin: 0 auto;
} }
@ -281,8 +286,7 @@
} }
.heading-section-white h2 { .heading-section-white h2 {
font-family: line-height: 1;
line-height: 1;
padding-bottom: 0; padding-bottom: 0;
} }
@ -356,17 +360,23 @@
<td valign="top" class="bg_white" style="padding: 1em 2.5em 0 2.5em;"> <td valign="top" class="bg_white" style="padding: 1em 2.5em 0 2.5em;">
<table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%"> <table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr> <tr>
<td class="logo" style="text-align: center;">
<td class="logo" style="text-align: right;">
<img src="cid:logoKatoikia" alt="Logo Katoikia"
style="width: 60px; max-width: 60px; height: auto; margin: auto; display: block; float: right;">
</td>
<td class="logo" style="text-align: left;">
<h1><a href="#">Katoikia</a></h1> <h1><a href="#">Katoikia</a></h1>
</td> </td>
</tr> </tr>
</table> </table>
</td> </td>
</tr><!-- end tr --> </tr><!-- end tr -->
<tr> <tr>
<td valign="middle" class="hero bg_white" style="padding: 3em 0 2em 0;"> <td valign="middle" class="hero bg_white" style="padding: 3em 0 2em 0;">
<img src="cid:logoKatoikia" alt="" <img src="cid:image_email" alt="Logo Katoikia"
style="width: 300px; max-width: 600px; height: auto; margin: auto; display: block;"> style="width: 150px; max-width: 300px; height: auto; margin: auto; display: block;">
</td> </td>
</tr><!-- end tr --> </tr><!-- end tr -->
<tr> <tr>
@ -375,16 +385,27 @@
<tr> <tr>
<td> <td>
<div class="text" style="padding: 0 2.5em; text-align: center;"> <div class="text" style="padding: 0 2.5em; text-align: center;">
<h2>Hola, {{ name }}</h2> <h2> Hola , {{ name }} <i class="fa-regular fa-face-smile-wink"
<p>Ha sido registrado como un Administrador de la Comunidad `{{community_name}}`</p> style="color:#D7A86E; font-size: 0.8em; margin-left: 20px;"></i></h2>
<p>Fecha de registro: {{date_entry}}</p> <h3>Ha sido registrado como un Administrador de la Comunidad `{{community_name}}`
</h3>
<h4><i class="fa-solid fa-calendar-day"
style="color:#D7A86E; margin-right: 10px;"></i> Fecha de registro
{{date_entry}}</h4>
</div>
<div class="text" style="padding: 0 4em; text-align: left;">
<h3>Estas son sus credenciales:</h3> <h3>Estas son sus credenciales:</h3>
<ul> <p><i class="fa fa-regular fa-envelope"
<li></p>Correo electronico: {{email}}</p></li> style="color:#D7A86E; margin-right: 10px;"></i> Correo electronico:
<li><p>>Password: {{password}}</p></li> {{email}}</p>
</ul> <p><i class="fa-solid fa-key" style="color:#D7A86E; margin-right: 10px;"></i>
<p>Inicie sesión en el sitio web para poder acceder y disfrutar todos sus benefucuin</p> Password: {{password}}</p>
</div>
<div class="text" style="padding: 0 2.5em; text-align: center;">
<h3>Inicie sesión en el sitio web para poder acceder y disfrutar todos sus
beneficios</h3>
<p><a href="{{ url }}" class="btn btn-primary">Iniciar sesión</a></p> <p><a href="{{ url }}" class="btn btn-primary">Iniciar sesión</a></p>
</div> </div>
</td> </td>
@ -392,46 +413,47 @@
</table> </table>
</td> </td>
</tr><!-- end tr --> </tr><!-- end tr -->
<!-- 1 Column Text + Button : END --> <!-- 1 Column Text + Button : END -->
</table> </table>
<table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%" <table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%"
style="margin: auto;"> style="margin: auto;">
<td valign="middle" class="bg_light footer email-section">
<table>
<tr>
<td valign="top" width="33.333%" style="padding-top: 20px">
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td style="text-align: left; padding-right: 10px">
<h3 class="heading">Acerca de</h3>
<p>Katoikia es su compañero más cercano para poder estar en contacto con sus
vecinos y conocer sobre los mejores anuncios sobre su comunidad.</p>
</td>
</tr>
</table>
</td>
<td valign="top" width="33.333%" style="padding-top: 20px">
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td style="text-align: left; padding-left: 5px; padding-right: 5px">
<h3 class="heading">Información de contacto</h3>
<ul>
<li><span href="mailto:katoikiaapp@gmail.com"
class="text">katoikiaapp@gmail.com</span></li>
</ul>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<!-- end: tr -->
<tr> <tr>
<td valign="middle" class="bg_light footer email-section"> <td class="bg_light" style="text-align: center">
<table> <p><a href="http://localhost:3000" style="color: rgba(0, 0, 0, 0.8)">katoikiaapp.org</a></p>
<tr>
<td valign="top" width="33.333%" style="padding-top: 20px;">
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td style="text-align: left; padding-right: 10px;">
<!-- <h3 class="heading">About</h3>
<p>A small river named Duden flows by their place and supplies it with
the necessary regelialia.</p>
-->
</td>
</tr>
</table>
</td>
<td valign="top" width="33.333%" style="padding-top: 20px;">
<table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td style="text-align: left; padding-left: 5px; padding-right: 5px;">
<!-- <h3 class="heading">Informacion de contacto</h3>
<ul>
<li><span class="text">203 Fake St. Mountain View, San Francisco,
California, USA</span></li>
<li><span class="text">+2 392 3929 210</span></a></li>
</ul>
-->
</td>
</tr>
</table>
</td>
</tr>
</table>
</td> </td>
</tr><!-- end: tr -->
</table> </table>

View File

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

File diff suppressed because it is too large Load Diff

View File

@ -29,10 +29,12 @@
"@nestjs/platform-express": "^8.0.0", "@nestjs/platform-express": "^8.0.0",
"@nestjs/swagger": "^5.2.1", "@nestjs/swagger": "^5.2.1",
"buffer": "^5.7.1", "buffer": "^5.7.1",
"class-validator": "^0.13.2",
"cors": "^2.8.5", "cors": "^2.8.5",
"crypto-browserify": "^3.12.0", "crypto-browserify": "^3.12.0",
"md5-typescript": "^1.0.5", "md5-typescript": "^1.0.5",
"mongoose": "^6.4.1", "mongoose": "^6.4.1",
"mongoose-unique-validator": "^3.1.0",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"rxjs": "^7.2.0", "rxjs": "^7.2.0",

View File

@ -0,0 +1,14 @@
import { ArgumentsHost, Catch, ConflictException, ExceptionFilter } from '@nestjs/common';
import { MongoError } from 'mongodb';
@Catch(MongoError)
export class MongoExceptionFilter implements ExceptionFilter {
catch(exception: MongoError, host: ArgumentsHost) {
switch (exception.code) {
case 11000:
console.log('llave duplicada')
// duplicate exception
// do whatever you want here, for instance send error to client
}
}
}

View File

@ -16,11 +16,12 @@ import { UsersModule } from './users/users.module';
}, },
]), ]),
MongooseModule.forRoot( MongooseModule.forRoot(
`mongodb+srv://proyecto_4:proyecto_4@proyecto4.yv4fb.mongodb.net/servicio_usuarios?retryWrites=true&w=majority`, `mongodb+srv://proyecto_4:proyecto_4@proyecto4.yv4fb.mongodb.net/servicio_usuarios?retryWrites=true&w=majority`
), ),
UsersModule, UsersModule,
], ],
controllers: [], controllers: [],
providers: [], providers: [],
}) })
export class AppModule {} export class AppModule { }

View File

@ -0,0 +1,30 @@
import { Injectable } from "@nestjs/common";
import { Model } from 'mongoose';
import { User, UserDocument } from '../schemas/user.schema';
import { InjectModel } from '@nestjs/mongoose';
import { ValidationArguments, ValidatorConstraint, ValidatorConstraintInterface } from "class-validator";
@ValidatorConstraint({ name: 'UserExists', async: true })
@Injectable()
export class UserExistsRule implements ValidatorConstraintInterface {
constructor(
@InjectModel(User.name) private readonly userModel: Model<UserDocument>,
) {}
async validate(value: string) {
try {
await this.userModel.find({email: value});
} catch (e) {
return false;
}
return true;
}
defaultMessage(args: ValidationArguments) {
return `User doesn't exist`;
}
}

View File

@ -1,23 +1,27 @@
import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose'; import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose'; import { Document } from 'mongoose';
var uniqueValidator = require('mongoose-unique-validator');
import { IsEmail, IsNotEmpty, IsString, Validate } from 'class-validator';
import { UserExistsRule } from 'src/exceptions/UserExistsRule';
export type UserDocument = User & Document; export type UserDocument = User & Document;
@Schema({ collection: 'users' }) @Schema({ collection: 'users'})
export class User { export class User {
@Prop() @Prop({index: true})
dni: string; dni!: string;
@Prop() @Prop({required: true})
name: string; name: string;
@Prop() @Prop({required: true})
last_name: string; last_name: string;
@Prop() @Prop({required: true, unique: true})
@Validate(UserExistsRule)
email: string; email: string;
@Prop() @Prop({required: true, unique: true})
phone: number; phone: number;
@Prop() @Prop()
@ -37,3 +41,4 @@ export class User {
} }
export const UserSchema = SchemaFactory.createForClass(User); export const UserSchema = SchemaFactory.createForClass(User);
UserSchema.plugin(uniqueValidator);

View File

@ -1,7 +1,8 @@
import { Controller } from '@nestjs/common'; import { Controller, UseFilters } from '@nestjs/common';
import { MessagePattern, Payload } from '@nestjs/microservices'; import { MessagePattern, Payload } from '@nestjs/microservices';
import { User, UserDocument } from '../schemas/user.schema'; import { User, UserDocument } from '../schemas/user.schema';
import { UsersService } from './users.service'; import { UsersService } from './users.service';
import { MongoExceptionFilter } from 'src/MongoExceptionFilter';
@Controller() @Controller()
export class UsersController { export class UsersController {
@ -13,6 +14,7 @@ export class UsersController {
} }
@MessagePattern({ cmd: 'createAdminSystem' }) @MessagePattern({ cmd: 'createAdminSystem' })
@UseFilters(MongoExceptionFilter)
createUserAdmin(@Payload() user: UserDocument) { createUserAdmin(@Payload() user: UserDocument) {
return this.userService.create(user); return this.userService.create(user);
} }

View File

@ -25,20 +25,24 @@ export class UsersService {
async createAdminCommunity(user: UserDocument) { async createAdminCommunity(user: UserDocument) {
let password = user.password; let password = user.password;
let passwordEncriptada = Md5.init(user.password); let passwordEncriptada = Md5.init(user.password);
user.password = passwordEncriptada; user.password = passwordEncriptada;
this.userModel.create(user);
let community = await this.findCommunity(user.community_id);
user.community_id = community['name'];
const pattern = { cmd: 'emailCreateUserAdminCommunity' }; this.userModel.create(user)
const payload = { email: user['email'], password: password, name: user['name'], date_entry: user['date_entry'] };
return this.clientNotificationtApp
.send<string>(pattern, payload) let community = await this.findCommunity(user.community_id);
.pipe( user.community_id = community['name'];
map((message: string) => ({ message })),
); const pattern = { cmd: 'emailCreateUserAdminCommunity' };
const payload = { email: user['email'], password: password, name: user['name'],
date_entry: user['date_entry'], community_name: community['name'] };
return this.clientNotificationtApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message })),
);
} }
async findCommunity(community_id: string) { async findCommunity(community_id: string) {
@ -141,8 +145,22 @@ export class UsersService {
return this.userModel.deleteOne({ _id: id }).exec(); return this.userModel.deleteOne({ _id: id }).exec();
} }
async validateEmail(email: string) {
let repo1 = this.userModel;
return new Promise<User>((resolve, reject) => {
let repo = repo1;
repo.find({ email: email }).exec((err, res) => {
if (err) {
reject(err);
} else {
if (res.length > 0) {
return res;
}
}
});
});
}
} }