Skip to content

Commit

Permalink
user profile informations to be remembered
Browse files Browse the repository at this point in the history
  • Loading branch information
MajemiteJames committed Sep 12, 2019
1 parent 886e6f9 commit 841a3ec
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"jsonwebtoken": "^8.5.1",
"method-override": "^3.0.0",
"mock-req-res": "^1.1.1",
"morgan": "^1.9.1",
"morgan-body": "^2.4.7",
"multer": "^1.4.2",
"multer-storage-cloudinary": "^2.2.1",
Expand Down
27 changes: 23 additions & 4 deletions src/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const updateUserDetails = async (req, res) => {
}
const {
firstName, lastName, phoneNo, birthDate, preferredLanguage,
preferredCurrency, gender, lineManager, currentLocation
preferredCurrency, gender, lineManager, currentLocation, rememberProfile
} = req.body;
const phoneNoExists = await getByOptions(User, {
where: {
Expand All @@ -158,7 +158,8 @@ const updateUserDetails = async (req, res) => {
preferredCurrency,
gender,
lineManager,
currentLocation
currentLocation,
rememberProfile
};
const options = {
returning: true,
Expand Down Expand Up @@ -270,7 +271,24 @@ const resetPassword = async (req, res) => {
return response(res, 500, 'error', { error: error.message });
}
};

/**
* @param {object} req request object
* @param {object} res response object
* @return {object} message
*/
const rememberUserProfile = async (req, res) => {
try {
const { rememberProfile } = req.body;
const { id } = req.user;
const user = await User.findByPk(id);
if (!user) return response(res, 404, 'error', { message: messages.userNotFound });
const options = { returning: true, where: { id } };
const updatedUser = await update(User, { rememberProfile }, options);
return response(res, 200, 'success', { message: 'Remember Profile Information Successfully Updated' }, updatedUser.firstName);
} catch (error) {
return response(res, 500, 'error', { error: error.message });
}
};
export default {
signUp,
socialAuth,
Expand All @@ -280,5 +298,6 @@ export default {
updateUserDetails,
forgotPassword,
resetPassword,
setUserRole
setUserRole,
rememberUserProfile
};
7 changes: 6 additions & 1 deletion src/database/migrations/20190815205048-create-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ module.exports = {
allowNull: true,
type: Sequelize.BOOLEAN,
defaultValue: true
}
},
rememberProfile: {
allowNull: true,
type: Sequelize.BOOLEAN,
defaultValue: false
},
})
},
down: (queryInterface, Sequelize) => {
Expand Down
5 changes: 5 additions & 0 deletions src/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ export default (Sequelize, DataTypes) => {
type: DataTypes.BOOLEAN,
defaultValue: false
},
rememberProfile: {
allowNull: true,
type: DataTypes.BOOLEAN,
defaultValue: false
},
emailNotificationEnabled: {
allowNull: true,
type: DataTypes.BOOLEAN,
Expand Down
2 changes: 2 additions & 0 deletions src/routes/api/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const {
forgotPassword,
resetPassword,
setUserRole,
rememberUserProfile,
} = userController;

const {
Expand Down Expand Up @@ -360,6 +361,7 @@ const userRoute = (router) => {
*/
.patch(checkToken, checkBlacklist, validate(setUserRoleSchema),
authorize([roles.SUPER_ADMIN]), checkUserId, setUserRole);
router.patch('/remember/profile', rememberUserProfile);
};

export default userRoute;

0 comments on commit 841a3ec

Please sign in to comment.