email.js 989 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. const { CrudService } = require('naf-framework-mongoose-free/lib/service');
  3. const { BusinessError, ErrorCode } = require('naf-core').Error;
  4. const _ = require('lodash');
  5. const assert = require('assert');
  6. //
  7. class EmailService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'email');
  10. this.httpUtil = this.ctx.service.util.httpUtil;
  11. this.emailServiceUrl = _.get(this.app, 'config.httpPrefix.email');
  12. this.emailServiceConfig = _.get(this.app, 'config.emailConfig.config');
  13. }
  14. async resetPwd(email, password) {
  15. const data = { config: this.emailServiceConfig, template: 'resetPwd', receiver: email, params: { password } };
  16. const url = `${this.emailServiceUrl}/sendEmail`;
  17. await this.httpUtil.cpost(url, data);
  18. }
  19. async errorEmail(error) {
  20. const data = { config: this.emailServiceConfig, params: error };
  21. const url = `${this.emailServiceUrl}/error`;
  22. await this.httpUtil.cpost(url, data);
  23. }
  24. }
  25. module.exports = EmailService;