42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
HttpException,
|
|
HttpStatus,
|
|
Param,
|
|
ParseIntPipe,
|
|
Post,
|
|
Res,
|
|
UploadedFile,
|
|
UseInterceptors,
|
|
} from '@nestjs/common';
|
|
import { FileInterceptor } from '@nestjs/platform-express';
|
|
import { EmailDto } from './dto/emailDto.dto';
|
|
import { EmailService } from './email.service';
|
|
import { Response } from 'express';
|
|
import * as xlsx from 'xlsx';
|
|
|
|
|
|
@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);
|
|
}
|
|
|
|
@Post('constancias')
|
|
@UseInterceptors(FileInterceptor('file'))
|
|
async sendConstancias(@UploadedFile() file, @Body('nombreEvento') nombreEvento: string,) {
|
|
if(!file) {
|
|
throw new HttpException("No se ha cargado ningun archivo", HttpStatus.BAD_REQUEST)
|
|
}
|
|
/* console.log(file) */
|
|
return this.emailService.sendConstancias(file, nombreEvento);
|
|
}
|
|
}
|