index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const CoreClass = require("../../core.js");
  2. const config = require("config");
  3. let mailgun = null;
  4. class MailModule extends CoreClass {
  5. constructor() {
  6. super("mail");
  7. }
  8. initialize() {
  9. return new Promise((resolve, reject) => {
  10. this.schemas = {
  11. verifyEmail: require("./schemas/verifyEmail"),
  12. resetPasswordRequest: require("./schemas/resetPasswordRequest"),
  13. passwordRequest: require("./schemas/passwordRequest"),
  14. };
  15. this.enabled = config.get("apis.mailgun.enabled");
  16. if (this.enabled)
  17. mailgun = require("mailgun-js")({
  18. apiKey: config.get("apis.mailgun.key"),
  19. domain: config.get("apis.mailgun.domain"),
  20. });
  21. resolve();
  22. });
  23. }
  24. SEND_MAIL(payload) {
  25. //data, cb
  26. return new Promise((resolve, reject) => {
  27. if (this.enabled)
  28. mailgun.messages().send(payload.data, () => {
  29. resolve();
  30. });
  31. else resolve();
  32. });
  33. }
  34. GET_SCHEMA(payload) {
  35. return new Promise((resolve, reject) => {
  36. resolve(this.schemas[payload.schemaName]);
  37. });
  38. }
  39. }
  40. module.exports = new MailModule();