AngularJS HTTP Response Missing Values? - angularjs

You read that right, this is AngularJS, the old one.
I have an Angular $http.post that returns an object with various values including a fairly large dictionary of more objects that map to a bunch of fields on a spreadsheet.
The magic:
If I debug the backend (.NET) and look at the object being returned all is well and as expected. If I log out the res.data object right after it is returned in the JS callback there is one particular (possibly more) string value within that dictionary of objects I mentioned that is set from "Some text" to "". No errors, no warnings...
But get this... if I look at the response in Fiddler THE VALUE IS THERE.
The discovery:
If I do a Request for only that Dictionary of Objects rather than it plus other data the value does indeed appear. Cool, so I can work around this... But WHY?
Why would this happen? Is there some size cap on response objects to Angulars $http.post? I am passing in no options to the post and I cannot find any info on this.
Thanks for any ideas!
UPDATE: (Code has been requested)
$http.post(baseUrl + "TESTCompData?p1=" + p1 + "&c1=" + c1).then(function (res) {
console.log(res);
})
The dictionary object I'm referring to:
public Dictionary<string, Dictionary<string,object>> ControlData;
The object in question:
{txt_SomeTexty: {
LineItemDataID=998,
LineItemMetaDataID=325,
SectionID=11,
Value=Some Text for XX (not a abc): $999,999,999}}
Value here comes in blank.

Figured it out though.
Turns out I was just accidentally clearing the field during a transformation method I had.
But what I don't understand: I was console.log'ing the object BEFORE this took place yet I saw it changed there. See I expected the logged object to be what it was when the response was returned (since that's where the log was) but somehow it isn't... it's the updated version.

Related

How to get the URL of an attachment in a message

I'm trying to get the URL of any attachments in a message. I can't seem to find a way to do this: whenever I try to run console.log(message.attachments.url), it just outputs undefined. What am I doing wrong?
I've tried reading the docs and other Stack Overflow questions but nothing worked.
I expect the output to be a URL of the attachment, i.e. 'https://cdn.discordapp.com/attachments/serverid/channelid/file.png' However, it just outputs undefined.
message.attachments is a Collection (a Map with additional Utility functions) so you either have to get the specific attachment via message.attachments.get('ID') or if you are sure that the message only has one attachment you can use message.attachments.first(). Otherwise you have to iterate through the Collection via
message.attachments.forEach(attachment => {
// do something with the attachment
const url = attachment.url;
});
I linked to the Collection docs of Discord.js. You also have access to the typical Map functions as well.

Trying to search mongo and send results to angular through express

I recently went through the www.clementinejs.com tutorial as I'm trying to learn the MEAN stack. I was able to complete it and understand most of it. However when i'm trying to repeat the process with mongoose and get slightly more data, I keep failing.
What i'm trying to do:
When page loads angular performs get request to '/api/entries' which searches mongo(via mongoose) and returns all docs in the collection, then load those docs into a div via angular ng-repeat.
If I insert dumby data into an object in the controller file I have no problem getting the data to show on the page, but when I try with the database I messed up somewhere. Even the angular curly brackets show up when I try to do it that way.
Here is my repo.
https://github.com/nickolaskg/journal
Should I just use mongo instead of mongoose? I'm not sure if i've set it up correctly.
Any help is greatly appreciated. I've been stuck for days trying so many different approaches, at this point I have no doubt there is multiple problems in the code.
Entry.get(function(result){
$scope.entries = result;
})
get() expects single object in the response.
Please read $resource's docs
Use:
Entry.query({field1: 'criterion'}) for queries and multiple resources.
Entry.get({_id: 'someid'}) for a single resource.
Entry.save({my: 'properties'}) for saving existing resource or creating a new resource.
Entry.delete({_id: 'someid'}) for deleting a single resource.
Also next time please post relevant code (IE your $resource calls) directly.

Getting $http.put() to send correctly formatted data, instead of JSON object

So, I spent some time and built a quick API for a project that I'm doing for myself.
I used the Postman add-on for Chrome to mimic PUT and DELETE quests to make sure everything worked correctly. Really happy I did that, as I learned a lot about PHP's shortcomings with PUT and DELETE requests.
Using the API I've had working with Postman, I started moving everything over to AngularJs controllers and such.
I'm trying to get a user to claim a row in a database as the login information for the users is different than this particular information. I couldn't figure out why the put requests to claim the row in my database wasn't working. Lo and behold, the data being parsed from my parsestr(file_get_contents('php://input')) had 1 array key, which was a JSON string.
I've looked, and I can't seem to find a solid answer either through Stackoverflow or Google (maybe I missed it somewhere in the config options), So my question is this: is there any way I can get the $http.put call send the data to the server correctly?
Thanks to user Chandermani for pointing me to the link at this URL which answered the base of my question.
From the above link, I found myself on This Blog post submitted by another user. In the end, what I ended up doing was the following:
taking param() function from the above link, as well as implementing these lines of code:
var app = angular.module('ucpData', [] , function($httpProvider){
$httpProvider.defaults.transformRequest = [function(data) {
return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
}];
});
Is how I worked around the problem. For some developers, you may actually want to keep the default transformRequest settings, but for the project I am doing I know that I will end up forgetting to call param() at some point, and my server doesn't naturally accept json data anyway. I would caution future developers to consider what they are attempting to do before they alter the transformRequest array directly.

Getting incorrect paths in Restangular. What am I doing wrong?

Here is a miniature proof of concept. It fetches thing #100 and then saves it.
var things = ThingsAPI.all("things");
things.one(100).get()
.then(function(thing) {
thing.put();
})
First it makes a GET request to
http://localhost:8080/things/100
but after that it PUTs to
http://localhost:8080/things/100/100
I would expect it to PUT to the same URL it came from, instead it's treating the url http://localhost:8080/things/100 as a list and then trying to find entity 100 within it.
I just want this to PUT back to http://localhost:8080/things/100. What am I doing wrong?
EDIT:
If I fetch with this instead, the PUTting works. But I would have expected to be able to do this with the all method.
ThingsAPI.one('things', 100).get()
And, for clarity, here is where I define ThingsAPI.
app.factory('ThingsAPI', function(Restangular) {
return Restangular.withConfig(function(RestangularConfigurer) {
RestangularConfigurer.setBaseUrl('http://localhost:8080/');
});
});
The reason is that you are treating the 100 as a nested resource for things. Therefore Restangular will generate routes as if http://localhost:8080/things/100 is the index route for the resource named 100 -- although it actually is the show route for things resource with id 100. These routes just accidentally happen to have the same URI.
As you can see, Restangular has misunderstood your intented resource definiton, and eg. PUT will generate an incorrect route.
Treating 100 as an identifier for things resource will correct the issue, as you seem to have found out: ThingsAPI.one('things', 100).get()
This translates to one(resource, identifier).get().

How can I test /_ah/bounce?

I have implemented a bounce handler by copying the code from the documentation, but now I would like to test that this code works before I push it out to production. Is there an easy way to do this?
I wound up using a Chrome extension called POSTMan to formulate a POST request with all of the required parameters, as shown in the docstring of the BounceNotification class:
post_vars: a dict-like object containing bounce information.
This is typically the self.request.POST variable of a RequestHandler
object. The following keys are expected in the dict:
original-from
original-to
original-subject
original-text
notification-from
notification-to
notification-subject
notification-text
raw-message
When I sent all of the required POST params, I indeed saw my bounce handler get the request and log the appropriate information.

Resources