Closed that1guy closed 9 years ago
Josh can you send me an example of the object I should pass in to delete an item from posting api. I can't seem to figure it out.
Here's working solution that gets all a users items for sale.
factory.getUsersItemsForSale = function (username) {
var deferred = $q.defer();
var params = {
filters: {
mandatory: {
exact: {
username: username
}
}
}
};
$http({
method: 'GET',
url: ENV.postingAPI + utilsFactory.bracketNotationURL(params)
}).then(function (response) {
console.log('here it is', response);
deferred.resolve(response);
}, function (err) {
deferred.reject(err);
});
return deferred.promise;
};
factory.bracketNotationURL = function (params, bracketURL) {
for (var prop in params) {
if(!bracketURL) {
bracketURL = '?'+prop;
} else {
bracketURL += '[' + prop + ']';
}
if (typeof params[prop] === "object" && params[prop] !== null) {
return factory.bracketNotationURL(params[prop], bracketURL);
} else {
bracketURL += '=' + params[prop];
return bracketURL;
}
}
};
Looked into your router code and figured this one out.
router.delete('/:postingId', function (req, res, next) {
console.log(req.params);
models.postings.delete(req.params.postingId, function (err, posting) {
if (err) {
return next(err);
}
return res.status(204).json(posting);
});
});
therefore:
factory.deletePost = function (post) {
var deferred = $q.defer();
$http({
method: 'DELETE',
url: ENV.postingAPI + post.postingId
}).then(function (response, status, headers, config) {
console.log('delete response: ', response);
deferred.resolve(response);
}, function (response, status, headers, config) {
deferred.reject(response);
});
return deferred.promise;
};
This is the GET query I'm trying to formulate with Angular's $http module
Here is my code:
This get request actually translates to: