86 lines
1.9 KiB
JavaScript
86 lines
1.9 KiB
JavaScript
const Student = require('../models/Student') ;
|
|
const User = require('../models/User') ;
|
|
|
|
function trim_arr(arr)
|
|
{
|
|
let newArr = arr.map(a => {
|
|
return a.trim() ;
|
|
})
|
|
return newArr ;
|
|
}
|
|
|
|
module.exports.getProfile =async (req , res , next) => {
|
|
try
|
|
{
|
|
const userId = req.user._id ;
|
|
let user = await User.findById(userId) ;
|
|
let student = await Student.findOne({user : userId}) ;
|
|
res.json({
|
|
user:user ,
|
|
student:student
|
|
}) ;
|
|
}
|
|
catch(err)
|
|
{
|
|
res.json({
|
|
error:err
|
|
}) ;
|
|
}
|
|
}
|
|
|
|
module.exports.postProfile = async (req , res , next) => {
|
|
try
|
|
{
|
|
const userId = req.user._id ;
|
|
|
|
let courses = req.body.courses ;
|
|
let interests = req.body.interests ;
|
|
let projects = req.body.projects ;
|
|
let yearofgrad = req.body.yearofgrad ;
|
|
let phoneNumber = req.body.phoneNumber ;
|
|
let institute = req.body.institute ;
|
|
let skills = req.body.skills ;
|
|
|
|
let student = await Student.findOne({user : userId}) ;
|
|
if(courses)
|
|
{
|
|
student.courses = trim_arr(courses.split(",")) ;
|
|
}
|
|
if(interests)
|
|
{
|
|
student.interests = trim_arr(interests.split(",")) ;
|
|
}
|
|
if(projects)
|
|
{
|
|
student.projects = trim_arr(projects.split(",")) ;
|
|
}
|
|
if(skills)
|
|
{
|
|
student.skills = trim_arr(skills.split(",")) ;
|
|
}
|
|
if(yearofgrad)
|
|
{
|
|
student.yearofgrad = yearofgrad.trim() ;
|
|
}
|
|
if(phoneNumber)
|
|
{
|
|
student.phoneNumber = phoneNumber.trim() ;
|
|
}
|
|
if(institute)
|
|
{
|
|
student.institute = institute.trim() ;
|
|
}
|
|
await student.save() ;
|
|
|
|
res.json({
|
|
message:"Updated profile"
|
|
})
|
|
}
|
|
catch(err)
|
|
{
|
|
console.log(err);
|
|
res.json({
|
|
error:err
|
|
}) ;
|
|
}
|
|
} |