Skip to content

Commit

Permalink
Merge pull request #52 from andela/bg-fixes-user-notification-168170909
Browse files Browse the repository at this point in the history
#168170909 fixes user notification
  • Loading branch information
tunedev committed Aug 29, 2019
2 parents 408e461 + e86600d commit 0a491f3
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/controllers/auth.controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export default {
lastName: request.body.lastName || request.foundUser.lastName,
bio: request.body.bio || request.foundUser.bio,
userName: request.body.userName || request.foundUser.userName,
isNotified: request.body.isNotifyActive || request.foundUser.isNotified,
twitterHandle:
request.body.twitterHandle || request.foundUser.twitterHandle,
facebookHandle:
Expand All @@ -167,7 +168,8 @@ export default {
userName: updatedUser.dataValues.userName,
twitterHandle: updatedUser.dataValues.twitterHandle,
facebookHandle: updatedUser.dataValues.facebookHandle,
image: updatedUser.dataValues.image
image: updatedUser.dataValues.image,
isNotifyActive: updatedUser.dataValues.isNotified
});
} catch (error) {
/* istanbul ignore next */
Expand Down
21 changes: 21 additions & 0 deletions src/controllers/notification.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { fetchNotificationService } from '../services/notification.service';
import Helper from '../services/helper';

export default {
/**
* @method fetchNotification
fetches all notifications
*
* @param {*} request
* @param {*} response
*/

async fetchNotification(request, response) {
try {
const value = await fetchNotificationService(request);
return Helper.successResponse(response, 200, value);
} catch (error) {
return error;
}
}
};
2 changes: 2 additions & 0 deletions src/routes/v1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import article from './article.route';
import profile from './profile.route';
import socialAuth from './social.route';
import search from './search.route';
import notification from './notification.route';

export default app => {
app.use(`${process.env.API_VERSION}/users`, auth);
Expand All @@ -12,4 +13,5 @@ export default app => {
app.use(`${process.env.API_VERSION}/profiles`, profile);
app.use(`${process.env.API_VERSION}/auth`, socialAuth);
app.use(`${process.env.API_VERSION}/search`, search);
app.use(`${process.env.API_VERSION}/notifications`, notification);
};
9 changes: 9 additions & 0 deletions src/routes/v1/notification.route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import express from 'express';
import notificationController from '../../controllers/notification.controller';
import authorization from '../../middlewares/auth.middleware';

const { verifyToken } = authorization;
const { fetchNotification } = notificationController;
const router = express.Router();
router.get('/', verifyToken, fetchNotification);
export default router;
23 changes: 23 additions & 0 deletions src/services/notification.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,29 @@ const pushNotification = (receiver, message) => {
});
};

/**
* @method fetchNotificationService
* @description method that fetches all notifications
*
* @param {Object} request receiver details
*
* @returns {Object} true or false
*/
export const fetchNotificationService = async request => {
const userId = request.user.id;
// notifications
try {
const findNotification = await Notification.findAll({
where: {
receiverUserId: userId
}
});
return findNotification;
} catch (error) {
throw Error(error);
}
};

/**
* @method createNotificationMessage
* @description persist data into the Notification table
Expand Down
1 change: 1 addition & 0 deletions src/services/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export const getUserFollowersService = async userId => {
}
const followers = await Follow.findAll({
where: { userId, isFollowing: true },
attributes: ['id'],
include: [
{
model: User,
Expand Down

0 comments on commit 0a491f3

Please sign in to comment.