Skip to content

Commit a1f4cc5

Browse files
committed
utils/mail: update to named export
1 parent 836241e commit a1f4cc5

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

server/controllers/user.controller.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import crypto from 'crypto';
22

33
import User from '../models/user';
4-
import mail from '../utils/mail';
4+
import { mailerService } from '../utils/mail';
55
import { renderEmailConfirmation, renderResetPassword } from '../views/mail';
66

77
export * from './user.controller/apiKey';
@@ -83,7 +83,7 @@ export async function createUser(req, res) {
8383
});
8484

8585
try {
86-
await mail.send(mailOptions);
86+
await mailerService.send(mailOptions);
8787
res.json(userResponse(user));
8888
} catch (mailErr) {
8989
console.error(mailErr);
@@ -155,7 +155,7 @@ export async function resetPasswordInitiate(req, res) {
155155
to: user.email
156156
});
157157

158-
await mail.send(mailOptions);
158+
await mailerService.send(mailOptions);
159159
res.json({
160160
success: true,
161161
message:
@@ -203,7 +203,7 @@ export async function emailVerificationInitiate(req, res) {
203203
to: user.email
204204
});
205205
try {
206-
await mail.send(mailOptions);
206+
await mailerService.send(mailOptions);
207207
} catch (mailErr) {
208208
res.status(500).send({ error: 'Error sending mail' });
209209
return;
@@ -334,7 +334,7 @@ export async function updateSettings(req, res) {
334334
to: user.email
335335
});
336336

337-
await mail.send(mailOptions);
337+
await mailerService.send(mailOptions);
338338
} else {
339339
await saveUser(res, user);
340340
}

server/migrations/emailConsolidation.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
moveObjectToUserInS3,
88
copyObjectInS3
99
} from '../controllers/aws.controller';
10-
import mail from '../utils/mail';
10+
import { mailerService } from '../utils/mail';
1111
import { renderAccountConsolidation } from '../views/mail';
1212

1313
const mongoConnectionString = process.env.MONGO_URL;
@@ -31,7 +31,8 @@ mongoose.connection.on('error', () => {
3131
* https://mongodb.github.io/node-mongodb-native
3232
*/
3333

34-
const agg = [ // eslint-disable-line
34+
const agg = [
35+
// eslint-disable-line
3536
{
3637
$project: {
3738
email: {
@@ -187,7 +188,7 @@ async function consolidateAccount(email) {
187188
});
188189

189190
return new Promise((resolve, reject) => {
190-
mail.send(mailOptions, (mailErr, result) => {
191+
mailerService.send(mailOptions, (mailErr, result) => {
191192
console.log('Sent email.');
192193
if (mailErr) {
193194
return reject(mailErr);
@@ -226,7 +227,7 @@ async function consolidateAccount(email) {
226227
// });
227228

228229
// return new Promise((resolve, reject) => {
229-
// mail.send(mailOptions, (mailErr, result) => {
230+
// mailerService.send(mailOptions, (mailErr, result) => {
230231
// console.log('Sent email.');
231232
// if (mailErr) {
232233
// return reject(mailErr);

server/utils/mail.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/**
2-
* Mail service wrapping around mailgun
3-
*/
4-
51
import nodemailer from 'nodemailer';
62
import mg from 'nodemailer-mailgun-transport';
73
import { RenderedMailerData } from '../types/email';
@@ -15,6 +11,7 @@ const auth = {
1511
domain: process.env.MAILGUN_DOMAIN
1612
};
1713

14+
/** Mail service class wrapping around mailgun */
1815
class Mail {
1916
client: nodemailer.Transporter;
2017

@@ -38,7 +35,7 @@ class Mail {
3835
}
3936

4037
async send(data: RenderedMailerData) {
41-
const mailOptions = {
38+
const mailOptions: nodemailer.SendMailOptions = {
4239
from: this.sendOptions.from,
4340
to: data.to,
4441
subject: data.subject,
@@ -55,4 +52,7 @@ class Mail {
5552
}
5653
}
5754

58-
export default new Mail();
55+
/**
56+
* Mail service wrapping around mailgun
57+
*/
58+
export const mailerService = new Mail();

0 commit comments

Comments
 (0)