Skip to content

Commit

Permalink
bug(userId):return userid after updating user profile
Browse files Browse the repository at this point in the history
To add userId to the attributes being returned
[#168203691]
  • Loading branch information
dharmykoya committed Aug 30, 2019
1 parent e092620 commit 87087e5
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/controllers/auth.controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export default {

return Helper.successResponse(response, 200, {
firstName: updatedUser.dataValues.firstName,
id: updatedUser.dataValues.id,
lastName: updatedUser.dataValues.lastName,
bio: updatedUser.dataValues.bio,
userName: updatedUser.dataValues.userName,
Expand Down
22 changes: 21 additions & 1 deletion src/controllers/notification.controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { fetchNotificationService } from '../services/notification.service';
import {
fetchNotificationService,
readNotificationService
} from '../services/notification.service';
import Helper from '../services/helper';

export default {
Expand All @@ -17,5 +20,22 @@ export default {
} catch (error) {
return error;
}
},

/**
* @method readNotification
read a notification
*
* @param {*} request
* @param {*} response
*/

async readNotification(request, response) {
try {
const value = await readNotificationService(request.params);
return Helper.successResponse(response, 200, value);
} catch (error) {
return error;
}
}
};
3 changes: 2 additions & 1 deletion src/routes/v1/notification.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import notificationController from '../../controllers/notification.controller';
import authorization from '../../middlewares/auth.middleware';

const { verifyToken } = authorization;
const { fetchNotification } = notificationController;
const { fetchNotification, readNotification } = notificationController;
const router = express.Router();
router.get('/', verifyToken, fetchNotification);
router.put('/:notificationId', verifyToken, readNotification);
export default router;
2 changes: 1 addition & 1 deletion src/services/article.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const getArticleService = async data => {
{
model: User,
as: 'author',
attributes: ['id', 'firstName', 'lastName', 'image']
attributes: ['id', 'firstName', 'lastName', 'image', 'userName', 'bio']
},
{
model: Tag,
Expand Down
6 changes: 5 additions & 1 deletion src/services/auth.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ export const signUpService = async body => {
lastName: result.lastName,
email: result.email,
image: result.image,
token: getToken(result)
token: getToken(result),
userName: result.userName,
bio: result.bio,
id: result.id,
isNotified: result.isNotified
};

sendWelcomeEmail(
Expand Down
9 changes: 9 additions & 0 deletions src/services/bookmark.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const getBookmarks = async userId => {
'body',
'image',
'likesCount',
'isPublished',
'viewsCount',
'description'
],
Expand All @@ -79,6 +80,14 @@ export const getBookmarks = async userId => {
if (userBookmarks.bookmarks.length < 1) {
return { message: `You currently don't have any bookmarks` };
}

if (userBookmarks.bookmarks) {
userBookmarks.bookmarks.forEach((article, index) => {
if (article.isPublished === false) {
userBookmarks.bookmarks.splice(index);
}
});
}
return userBookmarks;
};

Expand Down
23 changes: 23 additions & 0 deletions src/services/notification.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,26 @@ export const sendNotificationOnArticlePublish = async details => {
return response;
}
};

/**
* @method readNotificationService
* @description read a notification
*
* @param {Object} details details of the notification to be sent
*
* @returns {Boolean} true or false
*/
export const readNotificationService = async details => {
try {
const { notificationId } = details;
const readNotification = await Notification.findOne({
where: { id: notificationId }
});
readNotification.update({ isRead: true });
const response = { message: 'you have read the notification' };
return response;
} catch (error) {
const response = { message: 'something went wrong' };
return response;
}
};
4 changes: 4 additions & 0 deletions src/tests/controller/auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ describe('Auth API endpoints', () => {
expect(response.body.data.userName).to.be.equal('aboyhasnoname');
expect(response.body.data).to.have.keys(
'bio',
'id',
'isNotifyActive',
'userName',
'firstName',
'lastName',
Expand Down Expand Up @@ -478,6 +480,8 @@ describe('Auth API endpoints', () => {
expect(response.body.data).to.have.keys(
'bio',
'userName',
'id',
'isNotifyActive',
'firstName',
'lastName',
'twitterHandle',
Expand Down
1 change: 1 addition & 0 deletions src/tests/controller/bookmark.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ describe('Bookmarks API Endpoints', () => {
'body',
'image',
'likesCount',
'isPublished',
'viewsCount',
'description',
'bookmarks'
Expand Down
Binary file removed uploads/2019-08-29T14:24:01.159Zimage.jpeg
Binary file not shown.
Binary file removed uploads/2019-08-29T14:24:01.492Zimage.jpeg
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes

0 comments on commit 87087e5

Please sign in to comment.