Skip to content

Commit

Permalink
[Profile](CLIENT/SERVER): refactor profile page and functions {IA}
Browse files Browse the repository at this point in the history
  • Loading branch information
ianaa committed Dec 11, 2016
1 parent 2f74be5 commit 5c4c3cb
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 93 deletions.
3 changes: 1 addition & 2 deletions client/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ angular.module('jobTracker', [
'jobTracker.signup',
'jobTracker.mainList',
'jobTracker.profile',
'jobTracker.editProfile',
'jobTracker.changePassword',
'jobTracker.profileDir',
'jobTracker.authService',
'jobTracker.jobService',
'jobTracker.directives',
Expand Down
48 changes: 28 additions & 20 deletions client/app/services/AuthFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,42 +40,49 @@ angular.module('jobTracker.authService', [])
console.error("ERROR:", err);
});
};
var getProfile = function() {
return $http({
method: 'GET',
url: '/users',
}).then((res) => {
console.log("GOT USER", res.data)
return res.data;
}, (err) => {
console.error("ERROR:", err);
});
}

var updateAccount = function(infoPeople) {

var updateAccount = function(user) {
return $http({
method: 'PUT',
url: '/user',
data: infoPeople
url: '/users',
data: user,
}).then((res) => {
console.log(res);
$location.path('/profile');

return res.data;
},(err) => {
console.error("ERROR:", err);
});
};

var updatePassword = function(infoPeople) {

var updatePassword = function(user) {
return $http({
method: 'PUT',
url: '/changepassword',
data: infoPeople
}).then((res) => {
url: '/users/password',
data: user
}).then((res) => {
console.log(res);
$location.path('/profile');

});
};
var deleteProfile = function(infoPeople) {

var deleteAccount = function() {
return $http({
method: 'DELETE',
url: '/user',
data: infoPeople
method: 'POST',
url: '/users/delete',
}).then((res) => {
console.log(res);
$location.path('/login');

$location.path('/');
});
};

Expand All @@ -86,7 +93,8 @@ angular.module('jobTracker.authService', [])
isAuth: isAuth,
updateAccount: updateAccount,
updatePassword: updatePassword,
deleteProfile:deleteProfile
deleteAccount: deleteAccount,
getProfile: getProfile
};

});
7 changes: 1 addition & 6 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,8 @@
<script src="app/demo/demo.js"></script>
<script src="app/mainList/getNews/getNews.js"></script>
<script src="app/mainList/removeModal/removeModal.js"></script>

<script src="app/profile/profile.js"></script>
<script src="app/profile/editProfile.js"></script>
<script src="app/profile/changePassword.js"></script>



<script src="app/profile/profileDir.js"></script>
<script src="app/services/externalApiFactory.js"></script>
<script src="app/services/AuthFactory.js"></script>
<script src="app/services/JobFactory.js"></script>
Expand Down
41 changes: 16 additions & 25 deletions server/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,31 @@ module.exports = {
});
});
},
updateUserInDb: function(user, username) {

return User.update(
{"username": username},
{"$set":
{"firstname": user.firstname ,
"lastname" : user.lastname,
"emailid":user.emailid,
"dob":user.dob,
"jobstatus":user.jobstatus
}

})
updateUserInDb: function(user, userId) {
return User.update({"_id": userId}, user)
.exec()
.then(function(resp) {
return resp;
});
},
updateUserPasswordInDb: function(user, username) {

changePassword: function(user, userId) {
return User.update(
{"username": username},
{"$set":
{"password": user.password}
})
.exec()
.then(function(resp) {
return resp;
});
//TO BE REDONE
// {"username": username},
// {"$set":
// {"password": user.password}
// })
// .exec()
// .then(function(resp) {
// return resp;
);
},
deleteProfile: function(username) {

deleteUser: function(userId) {
return User.remove(
{"username": username}
{"_id": userId}
)
.exec()
.then(function(resp) {
Expand Down
50 changes: 20 additions & 30 deletions server/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ getUser: function(req, res) {
var userId = req.user._id;
var job = req.body;
jobsController.addJobToDb(job, userId)
.then(function(resp) {
res.send(resp);
.then(function(data) {
res.send(data);
})
.catch(function(err) {
console.error(err);
Expand All @@ -71,8 +71,8 @@ getUser: function(req, res) {
var userId = req.user._id;
var job = req.body;
jobsController.removeJobFromDb(job, userId)
.then(function(resp) {
res.send(resp);
.then(function(data) {
res.send(data);
})
.catch(function(err) {
console.error(err);
Expand All @@ -84,8 +84,8 @@ getUser: function(req, res) {
var userId = req.user._id;
var job = req.body;
jobsController.updateJobInDb(job, userId)
.then(function(resp) {
res.send(resp);
.then(function(data) {
res.send(data);
})
.catch(function(err) {
console.error(err);
Expand All @@ -95,52 +95,42 @@ getUser: function(req, res) {
},

uploadFile: function(req, res) {
console.log(req);
res.json({success : true});
},

updateUser : function(req,res){
var username = req.user.username;

updateUser: function(req, res){
var userId = req.user._id;
var user = req.body;
userController.updateUserInDb(user, username)
.then(function(resp) {
//getUser(req,res)
res.send(resp)
userController.updateUserInDb(user, userId)
.then(function(data) {
res.send(data)
})
.catch(function(err) {
console.error(err);
res.sendStatus(204);
});
},
updatePassword : function(req,res){
var username = req.user.username;
console.log(username)
updatePassword: function(req,res){
var userId = req.user._id;
var user = req.body;
userController.updateUserPasswordInDb(user, username)
.then(function(resp) {
//getUser(req,res)
userController.changePassword(user, userId)
.then(function(data) {
res.send(resp)
})
.catch(function(err) {
console.error(err);
res.sendStatus(204);
});
},
deleteProfile : function(req,res){
var username = req.user.username;
console.log(username)
// var user = req.body;
userController.deleteProfile(username)
.then(function(resp) {
//getUser(req,res)
res.send(resp)
deleteAccount: function(req, res){
var userId = req.user._id;
userController.deleteUser(userId)
.then(function(data) {
res.send(data)
})
.catch(function(err) {
console.error(err);
res.sendStatus(204);
});

}

};
22 changes: 15 additions & 7 deletions server/models/userModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ var jobSchema = require('./jobSchema.js');
var passportLocalMongoose = require('passport-local-mongoose');

var userSchema = mongoose.Schema({
firstname:{type: String, default:''},
lastname:{type: String, default:''},
emailid:{type: String, default:''},
dob:{type: Date, default:''},
jobstatus:{type: String, default:''},

username: {type: String, unique: true},
facebookId: String,
password: String,
jobList: [jobSchema],

firstname: String,
lastname: String,
email: String,
jobList: [jobSchema]
phone: Number,
jobstatus: {type: Number, default: 1}
});

userSchema.plugin(passportLocalMongoose);
Expand All @@ -23,3 +22,12 @@ var User = mongoose.model('User', userSchema);


module.exports = User;


///////////////////////////
////Job status explained///
///////////////////////////

//1 - actively looking for a job
//2 - found a job
//3 - not actively looking for a job
8 changes: 5 additions & 3 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ app.post('/jobs/delete', handlers.deleteJob);

app.put('/jobs', handlers.updateJob);

app.put('/user', handlers.updateUser);
app.get('/users', handlers.getUser);

app.put('/changepassword', handlers.updatePassword);
app.delete('/user', handlers.deleteProfile);
app.put('/users', handlers.updateUser);

app.put('/users/password', handlers.updatePassword);

app.post('/users/delete', handlers.deleteAccount);


db.on('error', (err) => {
Expand Down

0 comments on commit 5c4c3cb

Please sign in to comment.