Newer
Older
import { Controller, Post, Body, Res } from '@nestjs/common';
import { ContactForm } from './email';
import { EmailService } from './email.service';
import { ApiBadRequestResponse, ApiOkResponse } from '@nestjs/swagger';
@Controller('email')
export class EmailController {
constructor(
private emailService: EmailService,
) {}
@ApiOkResponse({ description: 'OK'})
@ApiBadRequestResponse({ description: 'Missing fields'})
create(@Body() contactForm: ContactForm, @Res() res) {
const created = this.emailService.send(contactForm);
if (created === true) {
res.status(200).send();
} else {
res.status(400).send({error: 'Couldn\'t send the email'});
}