feat: Adding contact-email endpoint
This commit is contained in:
22
README.md
22
README.md
@@ -33,6 +33,7 @@ Read registered resources:
|
|||||||
- `GET /public-load-attachments/download/:id`: Downloads the attachment of the load identified by Id.
|
- `GET /public-load-attachments/download/:id`: Downloads the attachment of the load identified by Id.
|
||||||
- `GET /public-vehicles`: List registered vehicles.
|
- `GET /public-vehicles`: List registered vehicles.
|
||||||
- `GET /states`: List registered states.
|
- `GET /states`: List registered states.
|
||||||
|
- `POST /contact-email`: Send an email from the Landing Page.
|
||||||
|
|
||||||
All these endpoints support the following parameters (except for those with `public-` as prefix, for example `public-vehicles`):
|
All these endpoints support the following parameters (except for those with `public-` as prefix, for example `public-vehicles`):
|
||||||
|
|
||||||
@@ -181,6 +182,27 @@ Returns:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### POST /contact-email
|
||||||
|
|
||||||
|
Send an email from the Landing Page:
|
||||||
|
|
||||||
|
Body content:
|
||||||
|
|
||||||
|
```{.json}
|
||||||
|
{
|
||||||
|
"email":"josepablo134@gmail.com",
|
||||||
|
"name":"Josepablo C.",
|
||||||
|
"message":"This is a test"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
```{.json}
|
||||||
|
{
|
||||||
|
"msg": "Email sent!"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### GET /public-companies
|
### GET /public-companies
|
||||||
|
|
||||||
Get public fields from registered companies.
|
Get public fields from registered companies.
|
||||||
|
|||||||
7
src/apps/public/contact-email/routes.js
Normal file
7
src/apps/public/contact-email/routes.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
'use strict';
|
||||||
|
const router = require('express').Router();
|
||||||
|
const services= require('./services.js');
|
||||||
|
|
||||||
|
router.post('/', services.postSendConactEMail);
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
38
src/apps/public/contact-email/services.js
Normal file
38
src/apps/public/contact-email/services.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
"use strict";
|
||||||
|
const { ROOT_PATH, HANDLERS_PATH } = process.env;
|
||||||
|
const { emailEvent , EMAIL_EVENTS } = require( `${ROOT_PATH}/${HANDLERS_PATH}/MailClient` );
|
||||||
|
|
||||||
|
const { Validator } = require( "jsonschema" );
|
||||||
|
const validator = new Validator();
|
||||||
|
|
||||||
|
const conact_email = {
|
||||||
|
type : 'object',
|
||||||
|
properties : {
|
||||||
|
name : { type : 'string' , maxLength : 256 },
|
||||||
|
email : { type : 'string' , maxLength : 256 },
|
||||||
|
message : { type : 'string', maxLength : 1024 }
|
||||||
|
},
|
||||||
|
required : [ 'name', 'email', 'message' ]
|
||||||
|
};
|
||||||
|
|
||||||
|
const postSendConactEMail = async(req, res) => {
|
||||||
|
try{
|
||||||
|
if( validator.validate( req.body , conact_email ).valid ){
|
||||||
|
const receiver = req.body.email;
|
||||||
|
const content = {
|
||||||
|
name : req.body.name,
|
||||||
|
email : req.body.email,
|
||||||
|
message : req.body.message
|
||||||
|
}
|
||||||
|
await emailEvent( EMAIL_EVENTS.CONTACT_EMAIL , receiver , content );
|
||||||
|
}else{
|
||||||
|
res.status(400).send( { error : "Invalid request" } );
|
||||||
|
}
|
||||||
|
return res.status(200).send({ msg : "Email sent!"});
|
||||||
|
} catch ( err ){
|
||||||
|
console.error( err );
|
||||||
|
return res.status(500).send({ error : "Contact-Email: Internal error" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = { postSendConactEMail };
|
||||||
@@ -6,6 +6,7 @@ const router = require('express').Router();
|
|||||||
|
|
||||||
const account = require('./account/routes.js');
|
const account = require('./account/routes.js');
|
||||||
const cities = require('./cities/routes.js');
|
const cities = require('./cities/routes.js');
|
||||||
|
const contactEmail = require('./contact-email/routes.js');
|
||||||
const countries = require('./countries/routes.js');
|
const countries = require('./countries/routes.js');
|
||||||
const metaData = require('./meta-data/routes.js');
|
const metaData = require('./meta-data/routes.js');
|
||||||
const metaGroups = require('./meta-groups/routes.js');
|
const metaGroups = require('./meta-groups/routes.js');
|
||||||
@@ -21,6 +22,7 @@ const test = require('./test/routes.js');
|
|||||||
|
|
||||||
router.use('/account', account);
|
router.use('/account', account);
|
||||||
router.use('/cities', cities);
|
router.use('/cities', cities);
|
||||||
|
router.use('/contact-email', contactEmail);
|
||||||
router.use('/countries', countries);
|
router.use('/countries', countries);
|
||||||
router.use('/meta-data', metaData);
|
router.use('/meta-data', metaData);
|
||||||
router.use('/meta-groups', metaGroups);
|
router.use('/meta-groups', metaGroups);
|
||||||
|
|||||||
@@ -35,5 +35,14 @@
|
|||||||
"API_KEY": "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",
|
"API_KEY": "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",
|
||||||
"FROM": "noreply@etaviaporte.com"
|
"FROM": "noreply@etaviaporte.com"
|
||||||
},
|
},
|
||||||
|
"email_standalone" : {
|
||||||
|
"host": "smtp.hostinger.com",
|
||||||
|
"port": "465",
|
||||||
|
"secure": true,
|
||||||
|
"auth": {
|
||||||
|
"user": "noreply@etaviaporte.com",
|
||||||
|
"pass": "-)WJt[oP~P$`76Q4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"mongodb": "mongodb+srv://enruta_admin:NeptFx4RUZG8OsfA@enruta.vwofshy.mongodb.net/enrutaviaporte?retryWrites=true&w=majority"
|
"mongodb": "mongodb+srv://enruta_admin:NeptFx4RUZG8OsfA@enruta.vwofshy.mongodb.net/enrutaviaporte?retryWrites=true&w=majority"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,5 +35,14 @@
|
|||||||
"API_KEY": "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",
|
"API_KEY": "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",
|
||||||
"FROM": "noreply@etaviaporte.com"
|
"FROM": "noreply@etaviaporte.com"
|
||||||
},
|
},
|
||||||
|
"email_standalone" : {
|
||||||
|
"host": "smtp.hostinger.com",
|
||||||
|
"port": "465",
|
||||||
|
"secure": true,
|
||||||
|
"auth": {
|
||||||
|
"user": "noreply@etaviaporte.com",
|
||||||
|
"pass": "-)WJt[oP~P$`76Q4"
|
||||||
|
}
|
||||||
|
},
|
||||||
"mongodb": "mongodb://localhost/etaviaporte?retryWrites=true&w=majority"
|
"mongodb": "mongodb://localhost/etaviaporte?retryWrites=true&w=majority"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,4 +63,16 @@ async function AccountPwdResetEmail( receiver, content ){
|
|||||||
return await sendMailTemplate( templateId, receiver, subject, content_to_send );
|
return await sendMailTemplate( templateId, receiver, subject, content_to_send );
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { AccountVerifyEmail, AccountConfirmed, AccountPwdResetEmail };
|
async function ContactEmail( receiver, content ){
|
||||||
|
const templateId = "d-1090dda1091442f3a75ee8ab39ad0f10";
|
||||||
|
const subject = "[ETA] Contact Email";
|
||||||
|
const content_to_send = {
|
||||||
|
project_name: SiteName,
|
||||||
|
user_name: content.name,
|
||||||
|
user_email: receiver
|
||||||
|
};
|
||||||
|
return await sendMailTemplate( templateId, receiver, subject, content_to_send );
|
||||||
|
}
|
||||||
|
//ContactEmail( "josepablo134@gmail.com", { email : "josepablo134@gmail.com", name:"Josepablo C.", message: "This is an example" } ).then().catch();
|
||||||
|
|
||||||
|
module.exports = { AccountVerifyEmail, AccountConfirmed, AccountPwdResetEmail, ContactEmail };
|
||||||
|
|||||||
24
src/lib/Handlers/MailClient/StandAlone.handler.js
Normal file
24
src/lib/Handlers/MailClient/StandAlone.handler.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
'user strict';
|
||||||
|
const { ROOT_PATH, API_CONFIG } = process.env;
|
||||||
|
const nodemailer = require("nodemailer");
|
||||||
|
|
||||||
|
const apiConfig = require( `${ROOT_PATH}/${API_CONFIG}` );
|
||||||
|
|
||||||
|
const transporter = nodemailer.createTransport(
|
||||||
|
apiConfig.email_standalone
|
||||||
|
);
|
||||||
|
|
||||||
|
async function StandAloneContactEmail( content ){
|
||||||
|
const default_from = apiConfig.email_standalone.auth.user;
|
||||||
|
const receiver = "support@etaviaporte.com";
|
||||||
|
const {name, email, message } = content;
|
||||||
|
return await transporter.sendMail({
|
||||||
|
from: `${name} <${default_from}>`,
|
||||||
|
to: receiver,
|
||||||
|
subject: "Contact Email From Landing Page",
|
||||||
|
text: `\n\n The following is an email from : ${email}\n\n\n` + message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//StandAloneContactEmail( { email : "josepablo134@gmail.com", name:"Josepablo C.", message: "This is an example" } ).then().catch();
|
||||||
|
|
||||||
|
module.exports = { StandAloneContactEmail };
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
'user strict';
|
'user strict';
|
||||||
const { ROOT_PATH, HANDLERS_PATH, MODELS_PATH, API_CONFIG } = process.env;
|
const { ROOT_PATH, HANDLERS_PATH, MODELS_PATH, API_CONFIG } = process.env;
|
||||||
const { AccountVerifyEmail, AccountConfirmed, AccountPwdResetEmail } = require('./SendGrid.handler');
|
const { StandAloneContactEmail } = require('./StandAlone.handler');
|
||||||
|
const { AccountVerifyEmail, AccountConfirmed, AccountPwdResetEmail, ContactEmail } = require('./SendGrid.handler');
|
||||||
|
|
||||||
const EMAIL_EVENTS={
|
const EMAIL_EVENTS={
|
||||||
ACCOUNT_VERIFY:1,
|
ACCOUNT_VERIFY:1,
|
||||||
ACCOUNT_CONFIRMED:2,
|
ACCOUNT_CONFIRMED:2,
|
||||||
ACCOUNT_PWD_RESET:3,
|
ACCOUNT_PWD_RESET:3,
|
||||||
|
CONTACT_EMAIL:4,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,13 +33,18 @@ async function emailEvent( eventId, receiver , content ){
|
|||||||
return await AccountPwdResetEmail( receiver, content );
|
return await AccountPwdResetEmail( receiver, content );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case EMAIL_EVENTS.CONTACT_EMAIL:
|
||||||
|
{
|
||||||
|
await StandAloneContactEmail( content );
|
||||||
|
return await ContactEmail( receiver, content );
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
throw new Error(`Email event not defined ${eventId}`);
|
throw new Error(`Email event not defined ${eventId}`);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return await usersModel.findById( id , { password : 0 } );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { emailEvent , EMAIL_EVENTS };
|
module.exports = { emailEvent , EMAIL_EVENTS };
|
||||||
|
|||||||
Reference in New Issue
Block a user