This is my enable course.js
let params = new URLSearchParams(window.location.search)
let courseId = params.get('courseId')
let token = localStorage.getItem('token')
fetch(`http://localhost:3000/api/courses/${courseId}`, {
method: "PUT",
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({
isActive: true
})
})
.then(res => res.json())
.then(data => {
if(data === true){
window.location.replace('./courses.html')
}else{
alert("Something went wrong.")
}
})
This is my controller
module.exports.unArchive = (params) => {
let update = {
isActive: true
}
return Course.findOneAndUpdate(params.courseId, update)
.then((course, err) => {
return (err) ? false : true
})
}
This is my routes
router.put('/:courseId', auth.verify, (req, res) => {
let courseId = req.params.courseId
CourseController.unArchive({courseId})
.then(resultFromUnArchive => res
.send(resultFromUnArchive))
})
please help me point out what's wrong with my code,
my console doesn't return any error,
but the value isActive
of my data doesn't update either.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…