How to find payment collection using response id? - mongodb

I am developing angularjs nodejs application
Following has Payment Collection find function and result
var collectionId = "5673d6c7da28e94f51277894"
Payment.find({id: collectionId}).exec(function(err,payment)
console.log(payment);
);
Console result :
{
"_id" : ObjectId("5673d6c7da28e94f51277894"),
"response" : {
"status" : "approved",
"id" : "PAY-9N740711P28316116KZX5U4I"
}
}
I need to find payment collection using response id
My code here
var paymentId = "PAY-9N740711P28316116KZX5U4I"
Payment.find({ response : {id: paymentId}}).exec(function(err,payment)
console.log(payment);
);
Console result :
undefined
If you are not clear question, please comment
Hope answer, thanks

It should be:
Payment.find({ 'response.id': paymentId }).exec(function(err,payment) {
console.log(payment);
});

Related

Flutter : can't get all response body from get request

I have get request in Flutter app, when I test the request in postman I get all data, something like this :
{
"result":{
"name" : "somename",
"images":[
"test.jpg",
"test2.jpg"
],
"sizes":[
{
"id": 1,
"value" : 5
},
{
"id": 2,
"value" : 15
}
]
}
}
I call data and print them like this without using models:
var data = json.decode(response.body);
print(data['result']['name']);
print(data['result']['images']);
print(data['result']['sizes']);
it is print all things expect last one.
where must be the mistake?
Solved, by adding "?sizesView = true" to the link
final response = await http.get(path +'?sizesView = true'):
you should get the index of the last one because it is in a dictionary not a list do this:
print(data['result']['sizes'][0]['id']) // it will get the first index of the sizes list and then get the id key
or you can creat a model of list to get the indexes of your list

Flurry - custom events

Hi I am wondering why the custom events I have set up don't seem to be showing on flurry.com portal.
I am going to guess it has something to do with how I have set it up - but according to the flurry documentation I have done it correctly.
This is the result when I click a button that fires logEvent
msg = <FlurryStreamEvent: 0x28350e000, type = 134, json = { "fl.event.type" : "CUSTOM_EVENT", "fl.event.id" : 2, "fl.timed.event.duration" : 0, "fl.event.timed" : false, "fl.event.uptime" : 2284321185, "fl.timed.event.starting" : false, "fl.event.user.parameters" : { "RXBpc29kZV90aXRsZQ==" : "WW91ciBTbyBTdHVwaWQ=", "cG9kY2FzdA==" : "Mm5lcmRzIEluIEEgUm9vbQ==" }, "fl.event.name" : "UG9kY2FzdF9QbGF5", "fl.frame.version" : 1, "fl.event.flurry.parameters" : { }, "fl.event.timestamp" : 1603026151045 }>
My concern is "fl.event.flurry.parameters" : { }, it's empty - I have no idea if it is meant to be empty..
This is how I am calling it:
let data = ["podcast": post.title, "Episode_title":podcast.title]
Flurry.logEvent("Podcast_Play", withParameters: data)
fl.event.user.parameters is the one that contains the parameters you set, so in your example, they are reporting in. Not seeing them in the portal could be due to the expected time it takes for data to propagate. If it takes more than several hours, email us at support#flurry.com with the details.

how to make async call using request-promise in google home action

I am trying to call a API in onSync() and return payload so that I will get number of devices. Even the api is returning me the proper data I am unable to show the devices. Following is the code snippet.
app.onSync((body) => {
// TODO: Implement SYNC response
console.log('************** inside sync **************');
var payload = {
agentUserId:'123',
devices:[]
};
//Calling Discove Devices API
requestAPI('------ calling API ------')
.then(function(data){
let result = JSON.parse(data);
console.log('********** RESULT ********** '+util.inspect(result,{depth:null}));
var count = 0;
count = Object.keys(result.Devices).length;
console.log('********** DEVICE COUNT ********** '+count);
//forming payload json of devices
for(var i in result.Devices){
var item = result.Devices[i];
payload.devices.push({
"id" : item.ieee_address,
"type" : 'action.devices.types.OUTLET',
"traits" : ['action.devices.traits.OnOff'],
name : {
"defaultNames" : [item.mapped_load],
"name" : item.mapped_load,
"nicknames" : [item.mapped_load],
},
"willReportState" : false,
"deviceInfo" : {
"manufacturer" : 'some manufacturer',
"model" : 'Smart-Plug',
"hwVersion" : '1.0',
"swVersion" : '1.0.1',
},
});
}
}).catch(function(err){
console.log(err);
});
console.log('PAYLOAD %J ',payload); <----- it is always empty
return {
requestId: body.requestId,
payload: payload,
};
});
API is returning me correct value but the payload is always empty.
Please help. I am new to node.js and I dont know how to make async call.
You're using an asynchronous call to get devices, and you'll need to make sure you don't return data before your request is complete. You return the Promise to the function, so it will wait:
app.onSync((body) => {
return requestApi('...')
.then(data => {
return {
requestId: body.requestId,
payload: payload
}
})
})

What am I doing wrong when manipulating data in Meteor/MongoDB?

I have this helper
myClub: function(){
var currentUserId = Meteor.userId();
var user = Meteor.users.findOne({_id: currentUserId});
return user;
}
I want it to return user.role
Here is my user in MongoDB
{
"_id" : "RdirmrLG3t8qBk4js",
"createdAt" : ISODate("2016-04-17T19:40:56.877Z"),
"services" : {
"password" : {
"bcrypt" : "$2a$10$cPe92XR9DT238bH/RanYEu.J6K2ImvAEbWOcVq6j9luI0BH08Qdly"
},
"resume" : {
"loginTokens" : [
{
"when" : ISODate("2016-04-17T19:51:49.474Z"),
"hashedToken" : "uVKUj/7JEkkOuizXhjl212Z38E47HXCex+D4zRikQ1k="
}
]
}
},
"username" : "worker",
"role" : "worker",
"club" : "hzSKAJfPXo7hSpTYS"
}
The code above works just fine. So it finds the current user and outputs info about it. But when I change user to user.role I get the following errormessage.
TypeError: Cannot read property 'role' of undefined
at Object.myClub
How can it be undefined? Is my syntax incorrect?
Template helpers are reactive, which means they update themselves as the app state changes or new data appears. In your case, the helper is called immediately when the template is rendered and before the Meteor.users collection is filled. Therefore, the .findOne() method returns undefined. It will be corrected in the second pass after new data arrives.
The simple fix here is to check whether the data is present inside the helper:
myClub: function(){
var currenUserId = Meteor.userId();
var user = Meteor.users.findOne({_id: currenUserId});
if(!user) return 'NO DATA';
return user.role;
},
In real life you'll probably want to wait for the basic data to be loaded before you render the template. That is usually done on the controller level.
Try:
myClub: function(){
return Meteor.user() && Meteor.user().role;
}
This is shorthand for return the role if there's a user.
As far as the role field not showing up, make sure that you are publishing that key from the server and subscribing to it. For example:
Meteor.publish('me',function(){
return Meteor.users.find(this.userId,{fields: {role: 1, username: 1, profile: 1, emails: 1}});
});
And on the client:
var me = Meteor.subscribe('me');
if ( me.ready() ) console.log("Ta-da! The role is: "+Meteor.user().role);
make sure that you subscribed to all data you need.
By the way, you can try following:
role: function(){ return (Meteor.user() || {}).role; }
Cheers

Firebase many to many relationship retrieve data

I have the following data structure , users and services have many to many
relationship
users : {
user1 : {
name : blah,
email : a#a.com,
services : {
servicekey1 : true,
servicekey9 : true
}
}
}
services : {
servicekey1 : {
name : blahserve,
category : blahbers,
providers : {
user1 : true,
user7 : true
}
}
}
I want to get the list of user objects for a service. How can this be done with and without angularfire.
I came up with this query (without angularfire) -
var refu = new Firebase("https://myapp.firebaseio.com/users");
var refs = new Firebase("https://myapp.firebaseio.com/services");
refs.child("servicekey1/providers").once("value",function(s){
var users = s.val();
angular.forEach(users, function(v,k){
refu.child(k).once("value", function(su){
console.log(su.val());
})
})
});
This solves my purpose but I feel there should be a better way to do it , may be with angular fire. Please suggest if there are any other/ better ways to achieve this?