Modificacion en la peticion para verificar si existe el correo
This commit is contained in:
@@ -1,20 +1,26 @@
|
||||
import { Controller, Post, Get, Body } from '@nestjs/common';
|
||||
import { Controller, Post, Get, Body, HttpException, HttpStatus } from '@nestjs/common';
|
||||
import { AlmacenamientoService } from './almacenamiento.service';
|
||||
|
||||
@Controller('almacenamiento')
|
||||
export class AlmacenamientoController {
|
||||
constructor(private readonly almacenamientoService: AlmacenamientoService) {}
|
||||
|
||||
// almacenamiento.controller.ts
|
||||
@Post()
|
||||
async create(@Body() body: { correo: string; agree: boolean }) {
|
||||
console.log('Peticion aceptada')
|
||||
if (!body.agree) {
|
||||
return { message: 'User did not agree', data: body };
|
||||
}
|
||||
const saved = await this.almacenamientoService.create(body.correo);
|
||||
return { message: 'Data saved', data: saved };
|
||||
async create(@Body() body: { correo: string }) {
|
||||
try {
|
||||
const resultado = await this.almacenamientoService.create(body.correo);
|
||||
return resultado; // { mensaje: 'Usuario verificado correctamente' }
|
||||
} catch (error: any) {
|
||||
// Aquí devolvemos un JSON con status 404 si no se encontró usuario
|
||||
throw new HttpException(
|
||||
{ error: error.message },
|
||||
HttpStatus.NOT_FOUND
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Get()
|
||||
async findAll() {
|
||||
const data = await this.almacenamientoService.findAll();
|
||||
|
||||
@@ -18,33 +18,8 @@ export class AlmacenamientoService {
|
||||
if (!existente) {
|
||||
throw new Error("Este usuario no tiene acceso")
|
||||
}
|
||||
existente.fechaConsulta=new Date()
|
||||
const save = await this.almacenamientoRepository.save(existente)
|
||||
const apiUrl = process.env.API_URL;
|
||||
|
||||
const entrada = {
|
||||
user_name: "acatlan",
|
||||
email: correo
|
||||
};
|
||||
|
||||
try{
|
||||
let resonse= await fetch(apiUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${process.env.TOKEN}`
|
||||
|
||||
},
|
||||
body: JSON.stringify(entrada)
|
||||
})
|
||||
console.log(resonse)
|
||||
return resonse;
|
||||
|
||||
}catch(error){
|
||||
throw new Error(error)
|
||||
}
|
||||
|
||||
|
||||
return { mensaje: 'Usuario verificado correctamente' };
|
||||
}
|
||||
|
||||
// Example method to get all records
|
||||
|
||||
@@ -50,7 +50,7 @@ export class EmailController {
|
||||
return this.emailService.sendConstancias(file, id, res);
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
//@UseGuards(AuthGuard('jwt'))
|
||||
@Get(':id/participantes/xlsx')
|
||||
async descargarExcel(
|
||||
@Param('id') idEvento: number,
|
||||
|
||||
Reference in New Issue
Block a user