-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(notification): add mark as read
Add mark as read endpoint Add controllers Write tests [Finishes #168407551]
- Loading branch information
Showing
12 changed files
with
214 additions
and
99 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
import helpers from '../helpers'; | ||
import services from '../services'; | ||
|
||
const { notificationServices: { getUserNotification } } = services; | ||
const { notificationServices: { getUserNotification, markAsRead: markAsReadService } } = services; | ||
|
||
|
||
const { responseMessage } = helpers; | ||
|
||
const getNotification = async (req, res) => { | ||
export const getNotification = async (req, res) => { | ||
const { id } = req.user; | ||
try { | ||
const userNotificationObject = await getUserNotification(id); | ||
responseMessage(res, 200, { notifications: userNotificationObject }); | ||
return responseMessage(res, 200, { notifications: userNotificationObject }); | ||
} catch (error) { | ||
responseMessage(res, 500, { error: error.message }); | ||
return responseMessage(res, 500, { error: error.message }); | ||
} | ||
}; | ||
|
||
export default getNotification; | ||
export const markAsRead = async (req, res) => { | ||
const { id: userId } = req.user; | ||
const id = req.params.id || null; | ||
try { | ||
await markAsReadService(id, userId); | ||
return responseMessage(res, 200, { message: 'Notification was mark as read successfully' }); | ||
} catch (error) { | ||
return responseMessage(res, 500, { error: 'Something went wrong' }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const up = queryInterface => queryInterface.bulkInsert('NotificationObjects', [{ | ||
id: 'aeab6e66-b8e9-4045-803a-92eced0c56db', | ||
entityId: '929a1f0b-3338-42c0-ade2-71eaa67cc653', | ||
actorId: '11fb0350-5b46-4ace-9a5b-e3b788167915', | ||
entityTypeId: 2, | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
}], {}); | ||
export const down = queryInterface => queryInterface.bulkDelete('NotificationObjects', null, {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const up = queryInterface => queryInterface.bulkInsert('Notifications', [{ | ||
id: 'f83238c9-258f-4c38-a548-5c939a7fdf22', | ||
notificationObjectId: 'aeab6e66-b8e9-4045-803a-92eced0c56db', | ||
notifierId: '8f3e7eda-090a-4c44-9ffe-58443de5e1f8', | ||
isRead: false, | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
}], {}); | ||
export const down = queryInterface => queryInterface.bulkDelete('Notifications', null, {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import validator from '../helpers/validator'; | ||
import errorHandler from './errorHandler'; | ||
|
||
const { | ||
isValidUUIDOptional | ||
} = validator; | ||
|
||
const { validatorError } = errorHandler; | ||
|
||
const notificationValidator = { | ||
markAsRead: [ | ||
isValidUUIDOptional('id'), | ||
validatorError | ||
] | ||
}; | ||
|
||
export default notificationValidator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import express from 'express'; | ||
import middlewares from '../middlewares'; | ||
import getNotification from '../controllers/NotificationController'; | ||
import { getNotification, markAsRead } from '../controllers/NotificationController'; | ||
|
||
const { verifyToken } = middlewares; | ||
const { verifyToken, notificationValidator } = middlewares; | ||
|
||
const notification = express.Router(); | ||
|
||
notification.get('/notifications', verifyToken, getNotification); | ||
notification.patch('/notification/:id?', verifyToken, notificationValidator.markAsRead, markAsRead); | ||
|
||
export default notification; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters