email #5
@@ -1,12 +1,22 @@
|
||||
PORT=5089
|
||||
|
||||
DB_HOST=132.248.180.82
|
||||
DB_USER=user_cedetec
|
||||
DB_PASSWORD=c3t3d3c
|
||||
DB_NAME=Betelgeuse_Cedetec_Prueba
|
||||
DB_PORT=
|
||||
# DB_HOST=132.248.180.82
|
||||
# DB_USER=user_cedetec
|
||||
# DB_PASSWORD=c3t3d3c
|
||||
# DB_NAME=Betelgeuse_Cedetec_Prueba
|
||||
# DB_PORT=
|
||||
|
||||
DB_HOST=localhost
|
||||
DB_USER=root
|
||||
DB_PASSWORD=password
|
||||
DB_NAME=cedetec_proyectos
|
||||
DB_PORT=
|
||||
|
||||
DB_HOST_DSC = 132.248.180.82
|
||||
DB_USER_DSC = sites_user
|
||||
DB_PASS_DSC = F0rTest
|
||||
DB_NAME_DSC = sat
|
||||
DB_NAME_DSC = sat
|
||||
|
||||
NODEMAILER_SERVICE = gmail
|
||||
NODEMAILER_USER = cidwa1@pcpuma.acatlan.unam.mx
|
||||
NODEMAILER_PASWORD = cidwaxd1,
|
||||
+5
-1
@@ -8,4 +8,8 @@ DB_NAME=
|
||||
DB_HOST_DSC=
|
||||
DB_USER_DSC=
|
||||
DB_PASS_DSC=
|
||||
DB_NAME_DSC=
|
||||
DB_NAME_DSC=
|
||||
|
||||
NODEMAILER_SERVICE=
|
||||
NODEMAILER_USER=
|
||||
NODEMAILER_PASWORD=
|
||||
Generated
+14
@@ -22,6 +22,7 @@
|
||||
"class-validator": "^0.14.0",
|
||||
"moment": "^2.29.4",
|
||||
"mysql2": "^3.1.2",
|
||||
"nodemailer": "^6.9.1",
|
||||
"passport": "^0.6.0",
|
||||
"passport-jwt": "^4.0.1",
|
||||
"passport-local": "^1.0.0",
|
||||
@@ -6980,6 +6981,14 @@
|
||||
"integrity": "sha512-5GFldHPXVG/YZmFzJvKK2zDSzPKhEp0+ZR5SVaoSag9fsL5YgHbUHDfnG5494ISANDcK4KwPXAx2xqVEydmd7w==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/nodemailer": {
|
||||
"version": "6.9.1",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.1.tgz",
|
||||
"integrity": "sha512-qHw7dOiU5UKNnQpXktdgQ1d3OFgRAekuvbJLcdG5dnEo/GtcTHRYM7+UfJARdOFU9WUQO8OiIamgWPmiSFHYAA==",
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/nopt": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz",
|
||||
@@ -14913,6 +14922,11 @@
|
||||
"integrity": "sha512-5GFldHPXVG/YZmFzJvKK2zDSzPKhEp0+ZR5SVaoSag9fsL5YgHbUHDfnG5494ISANDcK4KwPXAx2xqVEydmd7w==",
|
||||
"dev": true
|
||||
},
|
||||
"nodemailer": {
|
||||
"version": "6.9.1",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.1.tgz",
|
||||
"integrity": "sha512-qHw7dOiU5UKNnQpXktdgQ1d3OFgRAekuvbJLcdG5dnEo/GtcTHRYM7+UfJARdOFU9WUQO8OiIamgWPmiSFHYAA=="
|
||||
},
|
||||
"nopt": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz",
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
"class-validator": "^0.14.0",
|
||||
"moment": "^2.29.4",
|
||||
"mysql2": "^3.1.2",
|
||||
"nodemailer": "^6.9.1",
|
||||
"passport": "^0.6.0",
|
||||
"passport-jwt": "^4.0.1",
|
||||
"passport-local": "^1.0.0",
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
INSERT INTO tipo_miembro(tipo_miembro) VALUES("Admin");
|
||||
INSERT INTO tipo_miembro(tipo_miembro) VALUES("Alumno");
|
||||
INSERT INTO tipo_miembro(tipo_miembro) VALUES("Miembro");
|
||||
|
||||
@@ -44,6 +44,9 @@ import { Contacto } from './contacto/entity/contacto.entity';
|
||||
import { Equipo } from './equipo/entity/equipo.entity';
|
||||
import { EquipoEvento } from './equipo-evento/entity/equipo_evento.entity';
|
||||
import { EquipoMiembro } from './equipo-miembro/entity/equipo_miembro.entity';
|
||||
import { EmailService } from './email/email.service';
|
||||
import { EmailController } from './email/email.controller';
|
||||
import { EmailModule } from './email/email.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -106,6 +109,7 @@ import { EquipoMiembro } from './equipo-miembro/entity/equipo_miembro.entity';
|
||||
ProyectoModule,
|
||||
ProyectoActividadModule,
|
||||
ActividadModule,
|
||||
EmailModule,
|
||||
],
|
||||
controllers: [
|
||||
AppController,
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { IsEmail } from "class-validator"
|
||||
|
||||
export class EmailDto {
|
||||
|
||||
subject:string
|
||||
|
||||
text:string
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { EmailController } from './email.controller';
|
||||
|
||||
describe('EmailController', () => {
|
||||
let controller: EmailController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [EmailController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<EmailController>(EmailController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Body, Controller, Param, ParseIntPipe, Post } from '@nestjs/common';
|
||||
import { EmailDto } from './dto/emailDto.dto';
|
||||
import { EmailService } from './email.service';
|
||||
|
||||
@Controller('email')
|
||||
export class EmailController {
|
||||
constructor(private readonly emailService: EmailService) {}
|
||||
|
||||
@Post('/evento/:id')
|
||||
async sendEmail(
|
||||
@Param('id', ParseIntPipe) id: number,
|
||||
@Body() emailDto: EmailDto,
|
||||
): Promise<any> {
|
||||
return this.emailService.sendEmail(id, emailDto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { EventosModule } from 'src/eventos/eventos.module';
|
||||
import { Participante } from 'src/participante/participante.entity';
|
||||
import { EmailController } from './email.controller';
|
||||
import { EmailService } from './email.service';
|
||||
|
||||
@Module({
|
||||
imports:[TypeOrmModule.forFeature([Participante])],
|
||||
controllers:[EmailController],
|
||||
providers:[EmailService]
|
||||
})
|
||||
export class EmailModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { EmailService } from './email.service';
|
||||
|
||||
describe('EmailService', () => {
|
||||
let service: EmailService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [EmailService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<EmailService>(EmailService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import * as nodemailer from 'nodemailer';
|
||||
import { EventosService } from 'src/eventos/eventos.service';
|
||||
import { Participante } from 'src/participante/participante.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { EmailDto } from './dto/emailDto.dto';
|
||||
|
||||
@Injectable()
|
||||
export class EmailService {
|
||||
private transporter;
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Participante)
|
||||
private participanteRepository: Repository<Participante>,
|
||||
private configService: ConfigService,
|
||||
) {
|
||||
this.transporter = nodemailer.createTransport({
|
||||
service: this.configService.get('NODEMAILER_SERVICE'),
|
||||
auth: {
|
||||
user: this.configService.get<string>('NODEMAILER_USER'),
|
||||
pass: this.configService.get<string>('NODEMAILER_PASWORD'),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async sendEmail(id: number, message: EmailDto) {
|
||||
const participantes = await this.getEmailDeParticipantes(id);
|
||||
participantes.map((res) => {
|
||||
const emailDestinatario = res.email;
|
||||
this.transporter.sendMail({
|
||||
to: emailDestinatario,
|
||||
subject: message.subject,
|
||||
text: message.text,
|
||||
});
|
||||
/*console.log("Email enviado a: ", res)*/
|
||||
});
|
||||
}
|
||||
|
||||
async getEmailDeParticipantes(idEvento: number) {
|
||||
const participantes = await this.participanteRepository
|
||||
.createQueryBuilder('participante')
|
||||
.innerJoin('participante.eventosParticipante', 'eventoParticipante')
|
||||
.innerJoin('eventoParticipante.evento', 'evento')
|
||||
.where('evento.id_evento = :idEvento', { idEvento })
|
||||
.select(['participante.email'])
|
||||
.getMany();
|
||||
|
||||
return participantes;
|
||||
}
|
||||
}
|
||||
@@ -37,8 +37,13 @@ export class EventosController {
|
||||
return this.eventoService.deleteEventoParticipante(id)
|
||||
}
|
||||
|
||||
@Get(':id/participantes')
|
||||
@Get(':id/cupos')
|
||||
async getCupos(@Param('id', ParseIntPipe)id: number){
|
||||
return this.eventoService.getCupos(id)
|
||||
}
|
||||
|
||||
@Get(':id/participante')
|
||||
async getParticipnates(@Param('id', ParseIntPipe)id:number){
|
||||
return this.eventoService.getParticipantes(id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { EventoParticipante } from 'src/evento-participante/evento-participante/eventoParticipante.entity';
|
||||
import { Participante } from 'src/participante/participante.entity';
|
||||
import { Evento } from './evento.entity';
|
||||
import { EventosController } from './eventos.controller';
|
||||
import { EventosService } from './eventos.service';
|
||||
|
||||
@Module({
|
||||
imports:[TypeOrmModule.forFeature([Evento, EventoParticipante])],
|
||||
imports:[TypeOrmModule.forFeature([Evento, EventoParticipante, Participante])],
|
||||
controllers:[EventosController],
|
||||
providers:[EventosService]
|
||||
})
|
||||
|
||||
@@ -13,6 +13,7 @@ export class EventosService {
|
||||
@InjectRepository(Evento) private eventoRepository: Repository<Evento>,
|
||||
@InjectRepository(EventoParticipante)
|
||||
private eventoParticipanteRepository: Repository<EventoParticipante>,
|
||||
@InjectRepository(Participante) private participanteRepository:Repository<Participante>
|
||||
) {}
|
||||
|
||||
getEventos() {
|
||||
@@ -61,16 +62,28 @@ export class EventosService {
|
||||
}
|
||||
}
|
||||
|
||||
async getCupos(id: number){
|
||||
const evento = this.getEventosPorId(id)
|
||||
if(!evento) throw new Error(`El evento con id:${id} no existe`)
|
||||
async getCupos(id: number) {
|
||||
const evento = this.getEventosPorId(id);
|
||||
if (!evento) throw new Error(`El evento con id:${id} no existe`);
|
||||
const registrados = await this.eventoParticipanteRepository
|
||||
.createQueryBuilder('ep')
|
||||
.select('COUNT(ep.id_evento)', 'count')
|
||||
.where('ep.id_evento = :eventoId', { eventoId: (await evento).id_evento })
|
||||
.getRawOne();
|
||||
.createQueryBuilder('ep')
|
||||
.select('COUNT(ep.id_evento)', 'count')
|
||||
.where('ep.id_evento = :eventoId', { eventoId: (await evento).id_evento })
|
||||
.getRawOne();
|
||||
const cupoOriginal = (await evento).cupo;
|
||||
const cupoDisponible = cupoOriginal - registrados.count;
|
||||
return { registrados: registrados.count, cupoDisponible, cupoOriginal};
|
||||
const cupoDisponible = cupoOriginal - registrados.count;
|
||||
return { registrados: registrados.count, cupoDisponible, cupoOriginal };
|
||||
}
|
||||
|
||||
async getParticipantes(idEvento: number) {
|
||||
const participantes = await this.participanteRepository
|
||||
.createQueryBuilder('participante')
|
||||
.innerJoin('participante.eventosParticipante', 'eventoParticipante')
|
||||
.innerJoin('eventoParticipante.evento', 'evento')
|
||||
.where('evento.id_evento = :idEvento', { idEvento })
|
||||
.select(['participante.nombre','participante.apellido_paterno','participante.carrera', 'participante.email'])
|
||||
.getMany();
|
||||
|
||||
return participantes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Controller, Get, UseGuards } from '@nestjs/common';
|
||||
import { Controller, Get, Param, ParseIntPipe, UseGuards } from '@nestjs/common';
|
||||
import { JwtAuthGuard } from 'src/auth/jwt-auth.guard';
|
||||
import { Miembro } from './entity/miembro.entity';
|
||||
import { MiembroService } from './miembro.service';
|
||||
@@ -13,4 +13,9 @@ export class MiembroController {
|
||||
getUsuarios(): Promise<Miembro[]>{
|
||||
return this.miembroService.getUsuarios()
|
||||
}
|
||||
|
||||
@Get(':tipo')
|
||||
getMiembros(@Param('tipo', ParseIntPipe)tipo: number): Promise<Miembro[]>{
|
||||
return this.miembroService.getMiembros(tipo)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,4 +20,12 @@ export class MiembroService {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
getMiembros(tipo: number){
|
||||
return this.miembroRepository.find({
|
||||
where:{
|
||||
id_tipo_miembro: tipo
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user