I'm doing a small app where I display friend requests and an 'accept/reject' button beside each request.
here's my Template.notifications.helpers:
listRequests: function(){
return Notifications.find({toUser: Meteor.userId()});
}
and here's my notifications (where I display notifications for friend requests) template:
<template name="notifications">
{{#each listRequests}}
<p>{{displayUserName}}
<span id="fromUserId"><strong>{{fromUser}}</strong></span> sent you a friend request.
<button class="btn btn-primary" id="btnAcceptRequest">Accept</button>
<button class="btn btn-danger" id="btnRejectRequest">Reject</button>
</p>
<p>{{createdAt}}</p>
{{/each}}
</template>
And here's my user collection:
{
"_id": "zaSuTBgRh3oQcPSkh",
"emails": [
{
"address": "johnsmith#yahoo.com",
"verified": false
}
],
"profile": {
"firstname": "John",
"lastname": "Smith"
}
}
Currently, this code works. The issue is that it only displays the _id of the user who sent the request, thus, fromUser. What I wanted to do is display the firstname and lastname of the requesting user but I don't know where to go from here.
Of course, I tried replacing {{fromUser}} with {{profile.firstname profile.lastname}} and return Meteor.users.find({}); on the Template helpers but it does not work. Can anyone help me with this? Any help would be greatly appreciated.
You need a helper that does the lookup of the other user document and returns the appropriate values:
Template.notifications.helpers({
fromUserName: function(){
var fromUser = Meteor.users.findOne({ _id: this.fromUser });
if ( fromUser ){
return fromUser.profile.firstname + ' ' + fromUser.profile.lastname;
}
}
});
Note that if you have removed autopublish you must also be publishing the profile field (at least) from the user collection from the server and then subscribing to that on the client.
Related
I am totally a beginner in payment gateway no idea how to approach it. But I went through Razorpay side and all the other stackoverflow questions and from 2 days I am struggling to integrate the Razorpay gateway in my project. Now I am approaching the payment gateway by using JavaScript.
My project is a online shopping website which is based on java but I used JavaScript for giving the functionality in the website.
I don't have any idea about Reactjs and I am trying to integrate the gateway using basic Js.
directly into the jsp .
<script type="text/javascript" src="https://checkout.razorpay.com/v1/razorpay.js"></script>
</head>
<input type="button" id="razorGateway" name="submit" class="submit action-button"
value="Pay" />
<script type="text/javascript">
var options = {
"key": "rzp_test_1234567UHGSssj", // Enter the Key ID generated from the Dashboard
"amount": "50000", // Amount is in currency subunits. Default currency is INR. Hence, 50000 refers to 50000 paise or INR 500.
"currency": "INR",
"name": "Acme Corp",
"description": "Ecommerce",
"image": "image",
"order_id": "order_9A33XWu170gUtm",//This is a sample Order ID. Create an Order using Orders API. (https://razorpay.com/docs/payment-gateway/orders/integration/#step-1-create-an-order). Refer the Checkout form table given below
"handler": function (response){
alert(response.razorpay_payment_id);
},
"prefill": {
"name": "Gaurav Kumar",
"email": "gaurav.kumar#example.com",
"contact": "9999999999"
},
"notes": {
"address": "note value"
},
"theme": {
"color": "#EA5B29"
}
};
var rzp1 = new window.Razorpay(options);
document.getElementById('razorGateway').onclick = function(e){
rzp1.open();
e.preventDefault();
}
</script>
After debugging I am getting an error message. rzp1.open().
Screenshot
When I am not able to integrate with above method I went with another way.
<script>
// Single instance on page.
var razorpay = new Razorpay({
key: 'rzp_test_1234567UHGSssj',
// logo, displayed in the payment processing popup
image: 'https://i.imgur.com/n5tjHFD.png',
});
//Fetching the payment.
razorpay.once('ready', function(response) {
console.log(response.methods);
})
//Submitting the data.
var data = {
amount: 1000, // in currency subunits. Here 1000 = 1000 paise, which equals to ₹10
currency: "INR",// Default is INR. We support more than 90 currencies.
email: 'test.appmomos#gmail.com',
contact: '9123456780',
notes: {
address: 'Ground Floor, SJR Cyber, Laskar Hosur Road, Bengaluru',
},
// order_id: '123',
method: 'netbanking',
// method specific fields
bank: 'HDFC'
};
$("#razorGateway").click (function(){
alert("payment clicked");
// has to be placed within user initiated context, such as click, in order for popup to open.
razorpay.createPayment(data);
razorpay.on('payment.success', function(resp) {
alert("payment checking.");
alert(resp.razorpay_payment_id),
alert(resp.razorpay_order_id),
alert(resp.razorpay_signature)}); // will pass payment ID, order ID, and Razorpay signature to success handler.
razorpay.on('payment.error', function(resp){alert(resp.error.description)}); // will pass error object to error handler
})
</script>
Here I am able to hit the razorpay and pop-up is also visible but as it is hard coded I am not able to get the various options of payment method as it is shown in the demo. Directly it is giving me success and fail message(last page of gateway).
https://razorpay.com/demo
This option I am not getting it.Different payment methods
I will be at cloud no.9 if I get the answer or I am able to integrate it in either way or any other way. If options of integrating in Java is also welcomed.
Hi, i think you need to generate an actual order_id from server side as it is mentioned in their docs here. Instead of the sample order id.
I have the following in my buildSchema:
type User {
id: ID
firstname: String
age : Int
company : Company
}
type Company {
id: ID
name: String
description : String
}
type RootQuery {
user(id: ID): User
}
When making this request:
user(id:"1"){
firstname,
company{
id,
name
}
}
company is returning a null value:
{
"data": {
"user": {
"firstname": "Jhoni",
"company": null
}
}
}
How can I get the company value?
The problem here will be to do with what data is coming into your query. The execution itself is successful, but you are not getting the company data for some reason.
To debug this, I would look at what data is actually returned in your resolver for the user query by the request. It could be the reference ID parameter is not linking to any results in where you store company details.
I guess one other possibility is that you may have may not pass back the company data into a parameter named 'company', again, looking at the object that is returned to the resolver for 'user' before it is returned by the function should give you an idea of what's not matching up.
I'm building a multiplayer, turn-based game using meteor.js. The application will handle multiple games, so I'd like to separate my users into rooms.
I've done it before using socket.io channels, but I'm struggling to understand how it should be done in Meteor.
The flow I'd like to achieve is:
User visits http://localhost:3000/join/userId
I make a server-side call to an external API using "sessionId" as parameter, getting user's userId, his assigned roomId and an array of allowed userId's for this room
I'd like to create a room with roomId for the user or join him to an existing one. I know I should create a 'Rooms' collection, but I don't know how to tie users to my rooms and publish messages only to those present in the given room.
I'd like to avoid using 'accounts' package, because I don't need authorisation on my side - it'll be handled by step #2 mentioned above - but if the easiest and cleanest way of doing it involves adding this package, I can change my mind.
Your Rooms collection could look like:
{
_id: "<auto-generated>",
roomId: "roomId",
users: [ "user1", "user2", "user3", ... ],
messages: [
{ message: "", userId: "" },
{ message: "", userId: "" },
{ message: "", userId: "" },
...
]
}
The server-side API call returns
userId and roomId among other information.
So you can do a
Rooms.update({ roomId: roomId }, { $push: { users: userId } }, { upsert: true });
This would push the user into the exiting room or create a new room and add the user.
Your publish function could look like:
Meteor.publish("room", function(roomId) {
// Since you are not using accounts package, you will have to get the userId using the sessionId that you've specified or some other way.
// Let us assume your function getUserId does just that.
userId: getUserId( sessionId );
return Rooms.find({ roomId: roomId, users: userId });
// Only the room's users will get the data now.
});
Hope this helps.
I've come across something so bizarre. I had this below set up to read from a data.json file. It should show up a list of people. Instead it's ignoring the json file and is reading out non existing words! I just want it to read from data.json. Even if I delete "data.json" , the search function still prints out these words which don't exist.
As you can see from the photo, it's showing up a list of words that I DO NOT have stored anywhere in my code or on my server. It's puzzling me.
<body ng-app="personApp">
<div class="container">
<header></header>
<div ng-controller="PersonListCtrl">
<div class="bar">Search:
<input ng-model="query">
</div>
<ul class="">
<li ng-repeat="person in persons | filter:query">{{person.name}}</li>
and
var personApp = angular.module('personApp', []);
personApp.controller('PersonListCtrl', function ($scope, $http) {
$http.get('js/data.json').success(function (data) {
$scope.persons = data;
})
});
data.json
[{
"name": "Mike Doe"
}, {
"name": "Jhon Doe"
}, {
"name": "Sam Doe"
}, {
"name": "Sam Doe"
}, ];
Go to browser console -> Network.
Most probably you will see 304 status of your request, that means ajax request was cached by browser. Either clean cache, add query string to request etc.
I want to add a new field to Meteor's user collection:
server/fixtures.js:
Accounts.onCreateUser(function(options, user) {
user.role = 'Student'
// We still want the default hook's 'profile' behavior.
if (options.profile)
user.profile = options.profile;
return user
})
But when I do Meteor.users.find().fetch();:
Object
_id: "7zLDKQE4ACJCfeEhr"
username: "alex"
__proto__: Object
I don't see the field.
Isn't working in the template, either:
documents/document_page.js:
users: function() {
var users = _.map(Meteor.presences.find().fetch(), function(user) {
return Meteor.users.findOne({_id: user.userId})
})
return users
},
documents/user.html
<template name="user">
<li class="clearfix">
<img src="/avatar.png"/>
<div class="user-info">
<p>{{userId}}</p>
<p>{{username}}</p>
<p>{{role}}</p>
</div>
</li>
</template>
Only username is showing. What could be the problem?
You need to publish the custom fields. From the docs:
By default the server publishes username, emails, and profile (writable by user). See Meteor.users for more on the fields used in user documents.
The easiest way to do this is just to publish with a name of null which will automatically publish the documents without the need for a corresponding Meteor.subscribe:
Meteor.publish(null, function() {
return Meteor.users.find(this.userId, {fields: {role: 1}});
});
In this case we are publishing the role field which will be merged with the default fields already published for the current user.