Skip to content
Snippets Groups Projects
Commit 997e0873 authored by FORESTIER Fabien's avatar FORESTIER Fabien
Browse files

Building email object from contactForm

parent 53c7a62c
Branches
Tags
No related merge requests found
Pipeline #
import { Controller, Post, Body } from '@nestjs/common';
import { Email } from './email';
import { ContactForm } from './email';
import { EmailService } from './email.service';
import { ApiBadRequestResponse, ApiOkResponse } from '@nestjs/swagger';
......@@ -10,11 +10,11 @@ export class EmailController {
private emailService: EmailService,
) {}
@Post('send')
@Post('contact')
@ApiOkResponse({ description: 'OK'})
@ApiBadRequestResponse({ description: 'Missing fields'})
create(@Body() email: Email) {
return this.emailService.send(email);
create(@Body() contactForm: ContactForm) {
return this.emailService.send(contactForm);
}
}
import { Injectable, Logger } from '@nestjs/common';
import * as amqp from 'amqplib/callback_api';
import { Email } from './email';
import { ContactForm, Email } from './email';
@Injectable()
export class EmailService {
send(email: Email) {
send(contactForm: ContactForm) {
const rabbitmqUrl = 'amqp://user:password123@rabbitmq:5672';
const mailerQueue = 'portail-data-send-email';
const email = new Email();
email.from = `${contactForm.firstname} ${contactForm.lastname} ${contactForm.from}`;
email.to = [process.env.EMAIL_CONTACT];
email.subject = contactForm.subject;
email.text = contactForm.text;
Logger.log(email);
// Connect to rabbitmq
amqp.connect(rabbitmqUrl, (err, conn) => {
if (err != null) { Logger.log(err); }
......
import { IsDefined } from 'class-validator';
import { ApiModelProperty, ApiModelPropertyOptional } from '@nestjs/swagger';
export class ContactForm {
@ApiModelProperty()
@IsDefined()
from: string;
@ApiModelProperty()
@IsDefined()
subject: string;
@ApiModelProperty()
@IsDefined()
firstname: string;
@ApiModelProperty()
@IsDefined()
lastname: string;
@ApiModelProperty()
@IsDefined()
text: string;
}
export class Email {
@ApiModelProperty()
......@@ -24,4 +47,5 @@ export class Email {
@ApiModelProperty()
@IsDefined()
text: string;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment