我为我的api服务器创建了一个自定义端点,该端点删除了一个听力测试:
Account.deleteSingleHearingTest = function (req, callback) {
// console.log('accounts.js: deleteSingleHearingTest: are we being reached????', req)
Account.findById(req.accessToken.userId)
.then(account => {
if (!account) {
throw new Error('Cannot find user');
}
console.log('account.js: deleteSingleHearingTest: req.body.hearingTestId N: ', req.body.hearingTestId);
return app.models.HearingTest.updateAll({ accountId: account.id, id: req.body.hearingTestId }, { isDeleted: new Date() });
})
.then(() => {
callback(null);
})
.catch(error => {
callback(error);
});
}
Account.remoteMethod(
'deleteSingleHearingTest', {
http: {
path: '/deleteSingleHearingTest',
verb: 'post'
},
accepts: [
{ arg: 'req', type: 'object', description: 'removes a single hearing test', http: { source: 'req' } }
],
description: 'this is the end point for a single delete',
returns: {}
}
);
我还更新了account.json中的ACL:
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW",
"property": "deleteSingleHearingTest"
}
使用邮递员,我向服务器地址发出了POST请求,该请求看起来像:
https://xxx.xxxxxxxx.com/api/Accounts/deleteSingleHearingTest?access_token=XXXXXXXXXXXXXXXXXKyBdxkwxm5s8TSceMgclvXjjrTnyn3UJWIa
我对Postman的回复是带有附加消息的404
“共享类\“帐户\”没有处理POST / deleteSingleHearingTest?access_token = XXXXXXXXXXXXXXXXXXqAoKyBdxkwxm5s8TSceMgclvXjjrTnyn3UJWIa的方法”,
奇怪的是,这种方法在两周前首次创建时就起作用了,唯一的区别是我在本地运行服务器。
答案 0 :(得分:2)
我需要重新启动服务器,以便可以使用新方法。对于实际阅读此内容的1个人。要重新启动服务器,命令为pm2 start all