Skip to content

Commit c65d135

Browse files
author
Hamid Tavakoli
committed
Add standard lint lib
1 parent 956b8a1 commit c65d135

18 files changed

+685
-345
lines changed

.eslintrc.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

config/default.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ module.exports = {
1111
dialect: 'postgres',
1212
logging: false,
1313
dialectOptions: {
14-
ssl: process.env.DATABASE_SSL != null,
14+
ssl: process.env.DATABASE_SSL != null
1515
},
1616
pool: {
1717
max: 5,
1818
min: 0,
19-
idle: 10000,
20-
},
19+
idle: 10000
20+
}
2121
},
2222
DISABLE_LOGGING: process.env.DISABLE_LOGGING || 'false',
2323

@@ -29,8 +29,9 @@ module.exports = {
2929

3030
KAFKA_GROUP_ID: process.env.KAFKA_GROUP_ID,
3131
KAFKA_CLIENT_CERT: process.env.KAFKA_CLIENT_CERT ? process.env.KAFKA_CLIENT_CERT.replace('\\n', '\n') : null,
32-
KAFKA_CLIENT_CERT_KEY: process.env.KAFKA_CLIENT_CERT_KEY ?
33-
process.env.KAFKA_CLIENT_CERT_KEY.replace('\\n', '\n') : null,
32+
KAFKA_CLIENT_CERT_KEY: process.env.KAFKA_CLIENT_CERT_KEY
33+
? process.env.KAFKA_CLIENT_CERT_KEY.replace('\\n', '\n')
34+
: null,
3435

3536
// mapping from event type to sendgrid email template id
3637
TEMPLATE_MAP: process.env.TEMPLATE_MAP,
@@ -41,16 +42,16 @@ module.exports = {
4142
EMAIL_MAX_ERRORS: process.env.EMAIL_MAX_ERRORS || 2,
4243
EMAIL_PAUSE_TIME: process.env.EMAIL_PAUSE_TIME || 30,
4344

44-
//in every 2 minutes will retry for failed status
45+
// in every 2 minutes will retry for failed status
4546
EMAIL_RETRY_SCHEDULE: process.env.EMAIL_RETRY_SCHEDULE || '0 */2 * * * *',
46-
//wont't retry failed emails older than this time (msec)
47+
// wont't retry failed emails older than this time (msec)
4748
EMAIL_RETRY_MAX_AGE: process.env.EMAIL_RETRY_MAX_AGE || 1000 * 60 * 60 * 24,
4849

4950
API_CONTEXT_PATH: process.env.API_CONTEXT_PATH || '/v5/email',
5051

5152
PAYLOAD_SENDGRID_TEMPLATE_KEY: process.env.PAYLOAD_SENDGRID_TEMPLATE_KEY || 'sendgrid_template_id',
52-
//Tracing information
53+
// Tracing information
5354
APM_OTLP_TRACE_EXPORTER_URL: process.env.APM_OTLP_TRACE_EXPORTER_URL || '',
5455
APM_SERVICE_NAME: process.env.APM_SERVICE_NAME || 'tc-email-service-svc',
55-
APM_TRACER_NAME: process.env.APM_TRACER_NAME || 'tc-email-service-svc',
56-
};
56+
APM_TRACER_NAME: process.env.APM_TRACER_NAME || 'tc-email-service-svc'
57+
}

config/development.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
*/
44
module.exports = {
55
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',
6-
PORT: process.env.PORT || 4000,
7-
};
6+
PORT: process.env.PORT || 4000
7+
}

config/production.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
module.exports = {
55
LOG_LEVEL: process.env.LOG_LEVEL || 'error',
66
PORT: process.env.PORT || 4000,
7-
DISABLE_LOGGING: process.env.DISABLE_LOGGING || 'true',
8-
};
7+
DISABLE_LOGGING: process.env.DISABLE_LOGGING || 'true'
8+
}

config/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
*/
44
module.exports = {
55
LOG_LEVEL: process.env.LOG_LEVEL || 'debug',
6-
PORT: process.env.PORT || 4000,
7-
};
6+
PORT: process.env.PORT || 4000
7+
}

connect/connectEmailServer.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
/**
22
* This is TopCoder connect email server.
33
*/
4-
const _ = require('lodash');
5-
const config = require('config');
6-
const emailServer = require('../index');
7-
const service = require('./service');
8-
const logger = require('../src/common/logger');
4+
const _ = require('lodash')
5+
const config = require('config')
6+
const emailServer = require('../index')
7+
const service = require('./service')
8+
const logger = require('../src/common/logger')
99

1010
// set configuration for the server, see ../config/default.js for available config parameters
1111
// setConfig should be called before initDatabase and start functions
12-
emailServer.setConfig({ LOG_LEVEL: config.LOG_LEVEL });
12+
emailServer.setConfig({ LOG_LEVEL: config.LOG_LEVEL })
1313

1414
// add topic handlers,
1515
// handler is used build a notification list for a message of a topic,
1616
// it is defined as: function(topic, message),
1717
// the topic is topic name,
1818
// the message is JSON event message,
1919
const handler = async (topic, message) => {
20-
let templateId = config.TEMPLATE_MAP[topic];
21-
templateId = _.get(message, config.PAYLOAD_SENDGRID_TEMPLATE_KEY, templateId);
20+
let templateId = config.TEMPLATE_MAP[topic]
21+
templateId = _.get(message, config.PAYLOAD_SENDGRID_TEMPLATE_KEY, templateId)
2222
if (!templateId) {
23-
return { success: false, error: `Template not found for topic ${topic}` };
23+
return { success: false, error: `Template not found for topic ${topic}` }
2424
}
2525

2626
try {
2727
await service.sendEmail(templateId, message)
28-
return { success: true };
28+
return { success: true }
2929
} catch (err) {
30-
logger.error("Error occurred in sendgrid api calling:", err);
31-
return { success: false, error: err };
30+
logger.error('Error occurred in sendgrid api calling:', err)
31+
return { success: false, error: err }
3232
}
33-
34-
};
33+
}
3534

3635
// init all events
3736
_.keys(config.TEMPLATE_MAP).forEach((eventType) => {
38-
emailServer.addTopicHandler(eventType, handler);
39-
});
37+
emailServer.addTopicHandler(eventType, handler)
38+
})
4039

4140
// init database, it will clear and re-create all tables
4241
emailServer
@@ -47,9 +46,9 @@ emailServer
4746
emailServer.start()
4847
})
4948
.catch((e) => {
50-
logger.error('Error occurred in starting email server:', e);
51-
process.exit(1);
52-
}); // eslint-disable-line no-console
49+
logger.error('Error occurred in starting email server:', e)
50+
process.exit(1)
51+
}) // eslint-disable-line no-console
5352

5453
// if no need to init database, then directly start the server:
55-
// emailServer.start()
54+
// emailServer.start()

connect/service.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22
* This is TopCoder connect email service.
33
*/
44

5-
const sgMail = require('@sendgrid/mail');
6-
const config = require('config');
7-
const logger = require('../src/common/logger');
5+
const sgMail = require('@sendgrid/mail')
6+
const config = require('config')
7+
const logger = require('../src/common/logger')
88

99
// set api key for SendGrid email client
10-
sgMail.setApiKey(config.SENDGRID_API_KEY);
10+
sgMail.setApiKey(config.SENDGRID_API_KEY)
1111

1212
const sendEmail = async (templateId, message) => { // send email
13-
const span = await logger.startSpan('sendEmail');
13+
const span = await logger.startSpan('sendEmail')
1414
let msg = {}
15-
const from = message.from ? message.from : config.EMAIL_FROM;
16-
const replyTo = message.replyTo ? message.replyTo : config.EMAIL_FROM;
17-
const substitutions = message.data;
18-
const categories = message.categories ? message.categories : [];
19-
const to = message.recipients;
20-
const cc = message.cc ? message.cc : [];
21-
const bcc = message.bcc ? message.bcc : [];
22-
const sendAt = message.sendAt ? message.sendAt : undefined;
15+
const from = message.from ? message.from : config.EMAIL_FROM
16+
const replyTo = message.replyTo ? message.replyTo : config.EMAIL_FROM
17+
const substitutions = message.data
18+
const categories = message.categories ? message.categories : []
19+
const to = message.recipients
20+
const cc = message.cc ? message.cc : []
21+
const bcc = message.bcc ? message.bcc : []
22+
const sendAt = message.sendAt ? message.sendAt : undefined
2323
const personalizations = message.personalizations ? message.personalizations : undefined
24-
const attachments = message.attachments ? message.attachments : [];
24+
const attachments = message.attachments ? message.attachments : []
2525

26-
if (message.version && message.version == "v3") {
26+
if (message.version && message.version === 'v3') {
2727
msg = {
2828
to,
2929
templateId,
@@ -36,7 +36,7 @@ const sendEmail = async (templateId, message) => { // send email
3636
bcc,
3737
attachments,
3838
sendAt
39-
};
39+
}
4040
} else {
4141
msg = {
4242
to,
@@ -47,23 +47,23 @@ const sendEmail = async (templateId, message) => { // send email
4747
replyTo,
4848
categories,
4949
cc,
50-
bcc,
51-
};
50+
bcc
51+
}
5252
}
53-
logger.info(`Sending email with templateId: ${templateId} and message: ${JSON.stringify(msg)}`);
53+
logger.info(`Sending email with templateId: ${templateId} and message: ${JSON.stringify(msg)}`)
5454
try {
55-
await logger.endSpan(span);
56-
const sgSpan = await logger.startSpan('sendgrid');
55+
await logger.endSpan(span)
56+
const sgSpan = await logger.startSpan('sendgrid')
5757
const result = await sgMail.send(msg)
58-
await logger.endSpan(sgSpan);
59-
logger.info(`Email sent successfully with result: ${JSON.stringify(result)} \n ${JSON.stringify(msg)}`);
58+
await logger.endSpan(sgSpan)
59+
logger.info(`Email sent successfully with result: ${JSON.stringify(result)} \n ${JSON.stringify(msg)}`)
6060
return result
6161
} catch (err) {
62-
logger.error(`Error occurred in sendgrid api calling: ${err}`);
62+
logger.error(`Error occurred in sendgrid api calling: ${err}`)
6363
throw err
6464
}
6565
}
6666
module.exports = {
67-
sendEmail,
67+
sendEmail
6868
}
69-
logger.buildService(module.exports)
69+
logger.buildService(module.exports)

0 commit comments

Comments
 (0)