Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const userSchema=new Schema({
- email: { type: String, required: true, unique: true, lowercase: true, validate: emailValidators},
- username: { type: String, required: true, unique: true, lowercase: true, validate: usernameValidators},
- bio: { type:String,default:null,validate:bioValidators},
- location: {type:String, default:null},
- gender: {type:String,default:null,validate:genderValidators},
- birthday: { type:String,default:null},
- password: { type: String, required: true,validate: passwordValidators}
- });
- router.put('/editProfile',(req,res)=>{
- if(!req.body.bio){
- res.json({success:false,message:"No bio provided"});
- }
- else{
- if(!req.body.location){
- res.json({success:false,message:"No location provided"});
- }
- else{
- if(!req.body.gender){
- res.json({success:false,message:"No gender provided"});
- }
- else{
- if (!req.body.birthday) {
- res.json({success:false,message:"No birthday provided"});
- }
- else{
- User.findOne({_id:req.decoded.userId},(err,user)=>{
- if(err){
- res.json({success:false,message:"Something went wrong: "+err});
- }
- else{
- if(!user){
- res.json({success:false,message:"User not found"});
- }
- else{
- user.bio=req.body.bio;
- user.location=req.body.location;
- user.gender=req.body.gender;
- user.birthday=req.body.birthday;
- user.save((err)=>{
- if(err){
- res.json({success:false,message:'Something went wrong: '+ err}); //returns this
- }
- else{
- res.json({success:true,message:"Account updated !"});
- }
- });
- }
- }
- });
- }
- }
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement