Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. const userSchema=new Schema({
  2. email: { type: String, required: true, unique: true, lowercase: true, validate: emailValidators},
  3. username: { type: String, required: true, unique: true, lowercase: true, validate: usernameValidators},
  4. bio: { type:String,default:null,validate:bioValidators},
  5. location: {type:String, default:null},
  6. gender: {type:String,default:null,validate:genderValidators},
  7. birthday: { type:String,default:null},
  8. password: { type: String, required: true,validate: passwordValidators}
  9. });
  10.  
  11. router.put('/editProfile',(req,res)=>{
  12. if(!req.body.bio){
  13. res.json({success:false,message:"No bio provided"});
  14. }
  15. else{
  16. if(!req.body.location){
  17. res.json({success:false,message:"No location provided"});
  18. }
  19. else{
  20. if(!req.body.gender){
  21. res.json({success:false,message:"No gender provided"});
  22. }
  23. else{
  24. if (!req.body.birthday) {
  25. res.json({success:false,message:"No birthday provided"});
  26. }
  27. else{
  28. User.findOne({_id:req.decoded.userId},(err,user)=>{
  29. if(err){
  30. res.json({success:false,message:"Something went wrong: "+err});
  31. }
  32. else{
  33. if(!user){
  34. res.json({success:false,message:"User not found"});
  35. }
  36. else{
  37. user.bio=req.body.bio;
  38. user.location=req.body.location;
  39. user.gender=req.body.gender;
  40. user.birthday=req.body.birthday;
  41. user.save((err)=>{
  42. if(err){
  43. res.json({success:false,message:'Something went wrong: '+ err}); //returns this
  44. }
  45. else{
  46. res.json({success:true,message:"Account updated !"});
  47. }
  48. });
  49. }
  50. }
  51. });
  52. }
  53. }
  54. }
  55. }
  56. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement