Skip to content

Commit

Permalink
ft(fetch-notification): fetch user notifications
Browse files Browse the repository at this point in the history
  - will return all user notification
  • Loading branch information
Emile-Nsengimana committed Sep 16, 2019
1 parent b5ba5cd commit 5be478c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/controllers/articleRatingControllers.js
Expand Up @@ -28,6 +28,16 @@ class ArticleRatingManager {
});
}

const hasRated = await Rating.findOne({ where: { user: findUser.id } });
if (hasRated) {
await hasRated.update({
rating,
where: { user: findUser.id }
});
return res.status(200).json({
message: `Article ratings changed to ${rating}`
});
}
const saveRating = await Rating.create({
rating,
user: findUser.id,
Expand Down
20 changes: 16 additions & 4 deletions src/controllers/notificationController.js
Expand Up @@ -17,10 +17,22 @@ class NotificationManager {
if (notifications.length === 0) {
return res.status(404).json({ message: 'You are all caught up, you have zero notifications' });
}
notifications.map(async (notification) => {
await notification.update({
status: 'seen'
});
return res.status(200).json({ number: notifications.length, notifications });
}

/**
*
* @param {object} req
* @param {object} res
* @returns {object} article
*/
static async readNotification(req, res) {
const notifications = await Notifications.findOne({ where: { id: req.params.id } });
if (notifications.length === 0) {
return res.status(404).json({ message: 'You are all caught up, you have zero notifications' });
}
await notifications.update({
status: req.body.status
});
return res.status(200).json({ number: notifications.length, notifications });
}
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/notifications/newArticle.js
Expand Up @@ -23,13 +23,13 @@ class articleNotification {

const { APP_URL } = process.env;
return followers.map(async (follower) => {
const url = `${APP_URL}/api/articles/${slug}`;
const url = `${APP_URL}/articles/${slug}`;

const user = await Users.findOne({ where: { id: follower } });
const config = await userConfig.get(user.dataValues.id);

const inAppMessage = `Hello ${user.dataValues.username}, ${author.dataValues.username} has just published a new article. Click on this link ${url} to read this article`;
const emailMessage = `Hello ${user.dataValues.username}, ${author.dataValues.username} has just published a new article. Click on this link ${url} to read this article`;
const inAppMessage = `Hello ${user.dataValues.username}, ${author.dataValues.username} has just published a new article.`;
const emailMessage = `Hello ${user.dataValues.username}, ${author.dataValues.username} has just published a new article.`;

const action = 'publish';

Expand Down
1 change: 1 addition & 0 deletions src/routes/api/notifications.js
Expand Up @@ -8,5 +8,6 @@ const router = express.Router();
router.get('/', auth.checkAuthentication, notificationManager.getNotifications);
router.get('/config', auth.checkAuthentication, notificationManager.getNotificationsConfig);
router.put('/config', auth.checkAuthentication, ValidateConfig.notificationConfigSchema, notificationManager.updateConfig);
router.put('/read/:id', auth.checkAuthentication, notificationManager.readNotification);

export default router;

0 comments on commit 5be478c

Please sign in to comment.