【问题标题】:Cannot Delete the Workrole无法删除工作角色
【发布时间】:2019-06-24 14:05:28
【问题描述】:

我正在尝试删除该特定工作角色,后跟 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

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

【问题讨论】:

  • 我猜 DELETE 不是受支持的方法
  • 以下应用程序我还执行了用户删除其作品完美@frobinsonj

标签: javascript node.js mongoose


【解决方案1】:

我不确定这个错误是否来自我使用的常量变量(removeThis),在将这个常量变量更改为(removeWorkrole)之后它起作用了。这是最终代码...

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));
});

【讨论】:

    猜你喜欢
    • 2018-05-23
    • 1970-01-01
    • 2021-10-10
    • 2020-01-04
    • 2021-03-28
    • 1970-01-01
    • 2022-10-17
    • 1970-01-01
    • 2020-11-20
    相关资源
    最近更新 更多