Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default function validateSendForm(res, name, email, text, number, host, emailNotification, smsNotification, callNotification) {
- let emailValidated = validator.isEmail(email);
- let numberValidated;
- let formattedNumber;
- function showInvalidNumber(res) {
- res.statusMessage = "invalid number";
- res.status(400).end();
- }
- function showInvalidEmail(res) {
- res.statusMessage = "invalid email";
- res.status(400).end();
- }
- function sendResponse() {
- if(emailValidated && numberValidated) {
- sendNotification(name, email, text, number, host, emailNotification, smsNotification, callNotification);
- res.end("Sent")
- } else {
- if(!emailValidated && !numberValidated) {
- res.statusMessage = "invalid email and number";
- res.status(400).end();
- } else if (!emailValidated) {
- showInvalidEmail(res)
- } else if (!numberValidated) {
- showInvalidNumber(res);
- }
- }
- }
- function validateSend() {
- if (emailNotification && (smsNotification || callNotification)) {
- sendResponse()
- } else if(emailNotification) {
- if(emailValidated) {
- sendNotification(name, email, text, number, host, emailNotification, smsNotification, callNotification);
- res.end("Sent")
- } else {
- showInvalidEmail(res)
- }
- } else if(smsNotification || callNotification ) {
- if(numberValidated) {
- sendNotification(name, email, text, number, host, emailNotification, smsNotification, callNotification);
- res.end("Sent")
- } else {
- showInvalidNumber(res)
- }
- }
- }
- client.lookups.v1
- .phoneNumbers(number)
- .fetch({ countryCode: 'US' })
- .then((numberData) => {
- formattedNumber = numberData.phoneNumber
- numberValidated = true;
- }, err => numberValidated = false).then(() => {
- validateSend();
- });
- }
Add Comment
Please, Sign In to add comment