无法删除工作流程

时间:2019-06-24 14:05:28

标签: javascript node.js mongoose

我正在尝试删除该特定工作角色,然后删除ID。我用邮递员删除了这个东西,但我不能找出错误,我写的代码恰好是视频中显示的,但是我不能删除我的工作 在此工作流程之前,我还执行过用户删除过程,虽然工作正常,但是在此过程中,我不知道此功能有什么问题 这是删除工作流程的代码

请帮助我.....

// @type    DELETE
// @route   /api/profile/workrole/:w_id
// @desc    route for delete specific work profile of a person
// @access  PRIVATE

router.delete('/workrole/:w_id'), passport.authenticate('jwt' , {session: false}), (req, res) => {
    Profile.findOne({user: req.user.id})
        .then(profile => {
            //assignment to check if we got a profile
            const removeThis = profile.workrole
                .map(item => item.id)
                .indexOf(req.params.w_id);

            profile.workrole.splice(removeThis, 1);

            profile.save()
                .then(profile => {
                    res.json(profile)
                })
                .catch(err => console.log('Error on saving workrole after removing ' + err));
        })
        .catch(err => console.log('Error in deleting workrole ' + err));
}

module.exports = router;

这是邮递员中显示的错误消息

Cannot DELETE /api/profile/workrole/5d10cbba5fb5b11ab0cd3bdb

在控制台中没有显示错误消息

1 个答案:

答案 0 :(得分:0)

我不确定这个错误可能是由于我将常量变量更改为有效的(removeWorkrole)后使用的常量变量(removeThis)引起的。这是最终代码...

router.delete('/workrole/:w_id', passport.authenticate('jwt', {session: false}), (req, res)=> {
    Profile.findOne({user: req.user.id})
        .then(profile => {
            // assignment to check if we got a profile
            const removeWorkrole = profile.workrole.map(item => item.id).indexOf(req.params.w_id);

            profile.workrole.splice(removeWorkrole, 1);
            profile.save()
                .then(profile => res.json(profile))
                .catch(err => console.log('Error on saving workrole: ' + err));
        })
        .catch(err => console.log("Error on finding the user: " + err));
});