added docs, added new logger

This commit is contained in:
Wyatt Johnson
2018-02-12 16:51:39 -07:00
parent 79cb8b0fb2
commit 5221ebbe9a
17 changed files with 160 additions and 57 deletions
@@ -1,4 +1,3 @@
const debug = require('debug')('talk-plugin-notifications-reply');
const { graphql } = require('graphql');
const { get } = require('lodash');
const path = require('path');
@@ -9,7 +8,7 @@ const handle = async (ctx, comment) => {
// Check to see if this is a reply to an existing comment.
const parentID = get(comment, 'parent_id', null);
if (parentID === null) {
debug('could not get parent comment id');
ctx.log.debug('could not get parent comment id');
return;
}
@@ -51,14 +50,14 @@ const handle = async (ctx, comment) => {
const userID = get(reply, 'data.comment.user.id', null);
if (!userID) {
debug('could not get parent comment user id');
ctx.log.debug('could not get parent comment user id');
return;
}
// Check to see if this is yourself replying to yourself, if that's the case
// don't send a notification.
if (userID === get(comment, 'author_id')) {
debug('user id of parent comment is the same as the new comment');
ctx.log.debug('user id of parent comment is the same as the new comment');
return;
}
@@ -65,7 +65,7 @@ class NotificationManager {
// Send the notification.
return this.send(ctx, userID, date, handler, context);
} catch (err) {
// TODO: handle error.
ctx.log.error({ err }, 'could not handle the event');
return;
}
})
@@ -114,14 +114,18 @@ class NotificationManager {
'organizationName'
);
if (organizationName === null) {
// TODO: handle error
ctx.log.debug(
'could not send the notification, organization name not in settings'
);
return;
}
// Get the User's email.
const to = await this.getEmail(ctx, userID);
if (!to) {
// TODO: handle error
ctx.log.debug(
'could not send the notification, destination email address not available'
);
return;
}
@@ -142,9 +146,12 @@ class NotificationManager {
to,
});
debug(`Sent the notification for Job.ID[${task.id}]`);
ctx.log.debug(`Sent the notification for Job.ID[${task.id}]`);
} catch (err) {
// TODO: print out the error.
ctx.log.error(
{ err },
'could not send the notification, an error occurred'
);
return;
}
}