Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] An easy to use mail validator #8

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

Joe-Degs
Copy link

@Joe-Degs Joe-Degs commented Jun 10, 2020

This feature introduces a way to seamlessly validate the mail about to be sent and it is also promised based which means it is unblocking

Using this is extremely simple, you just import the mail_validator.js file inside the utils folder, this file when imported returns an object with two things

  • a validator function: the function that coordinates the mail object validation
  • schema table: that contains the schema functions that do the actual validation of the mail objects

It is extremely easy to use and structured in a way you don't have to think about the implementation to use it.

The validator function takes two parameters, a mail object to validate and the route on which you are validating. We have two routes, so that will be either a sendmail or sendmailwithtemplate option.

validator([mailObject -> Object], [route -> 'sendmail' | 'sendmailwithtemplate'])

The validator is promised based, so if you call it either

  • resolves a value object that contains all the mail objects that have undergone the validation
  • or rejects with an error object containing the specific reason it failed

A simple way to use this will be

const { validate } = require('./utils/mail_validator');

const samplemail = {
      from: 'Noreply <[email protected]>',
      recipient: '[email protected]',
      cc: ['[email protected]', '[email protected]'],
      bcc: [],
      subject: 'subject of the motherfucking email',
      text: 'Body of the email'
}

validate(samplemail, 'sendmail')
    .then(console.log).catch(console.log);

slackName: Joe.Attah
Team Fierce.

Joe-Degs added 2 commits June 10, 2020 09:00
…mely easy and clear to use.

So you just import the mail_validator.js file, which returns an object with two things, a validator function and a schema table.
It is extremely easy to use and structured in a way you dont have to think about the implementation to use it.
The validator is promised based, so if you call it, it resolves a `value` or rejects an `error`.
slackName: Joe.Attah
Team Fierce.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant