Я пытаюсь заставить http-запрос на удаление работать.Я использую AngularJS в своем внешнем интерфейсе и Node.js и PostgreSQL для задней части.
Хочу, чтобы я хотел иметь возможность удалять сеанс на основе его идентификатора, и это происходит, но по какой-то причине он удаляет только идентификатор 1, а не других.
Так что, если бы я имел
id 1 id 2 id 3
Мой запрос на удаление удалит id 1, но не будет работать для остальных.
Вот мой код
HTML
ng-click="cancelUserSession()"
контроллер
$scope.cancelUserSession = (userId) => {
const subtracting = currentIndex - 1;
if (subtracting <= 0) {
swal({
title: "Cancel Session",
type: "warning",
showCancelButton: true,
confirmButtonText: "Cancel",
cancelButtonText: "Keep",
animation: "slide-from-top"
},
() => {
loginService.cancelUserSession(userId).then((response) => {
console.log(response);
console.log("session canceled")
getSessions();
})
})
}
};
служба
this.cancelUserSession = (userId) => {
return $http({
method: "DELETE",
url: '/remove-session/' + userId
}).then((response) => {
return response;
})
};
index.js
app.delete('/remove-session/:userId', userCtrl.userCancelSession);
userCtrl
userCancelSession: (req, res) => {
app.get('db').delete_client_session([req.params.userId]).then(response => {
res.status(200).send(response + "item removed succesfully")
}).catch(err => console.log(err))
},
SQL
delete from client_sessions
where client_sessions.id = $1;