userId.getUserById is not a function [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
When a user click's on a username on the list below, it's meant to open up the add user page with the name's of the user in the fields.
I get this error message:
Here's the code in the manage users page:
componentWillMount: function () {
var userId = this.props.params.id; // from the path /user:id
if (userId) {
this.setState({ user: userId.getUserById(userId) });
}
},
Here's the code in the userApi:
getUserById: function(id) {
var user = _.find(users, {id: id});
return _clone(user);
},
I am new to StackOverflow and programming, so if this post doesn't meet the community's guidelines, please guide me on how to better make use this platform so I can further my learning progression.
Thanks,
Rickie

Using the userId variable you can't call your API. Since getUserById is from your API you must call the method from there.
userApi.getUserById(userId);

Related

No Invitations ID [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last month.
This post was edited and submitted for review last month and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I have many google classroom invitations and I want to accept all of them through google app script using
Classroom.Invitations.accept("courseId");
but then I get no data back...
so I tried listing all my invitations using
Classroom.Invitations.list({"userId":"my_email"});
and still I get no data back...
I am very sure that my google classroom is full of unaccepted courses
Modification points:
In your script, an error occurs at var teacherEmails=(john.doe#gmail.com,jane.doe#gmail.com);.
I thought that your script might be for a python script. If you want to use this method using Google Apps Script, it is required to modify it.
When these points are reflected in a Google Apps Script, how about the following sample script?
Sample script:
Before you use this script, please enable Classroom API at Advanced Google services.
function myFunction() {
const courseId = "###"; // Please set your course ID.
const teacherEmails = ["john.doe#gmail.com", "jane.doe#gmail.com"]; // Please set email addresses.
teacherEmails.forEach(userId => {
const res = Classroom.Invitations.create({ courseId, userId, role: "TEACHER" });
console.log(res)
});
}
Reference:
Method: invitations.create
Call this method in Google App Script, you will need to use the Classroom.Invitations.create() function in your code and pass the necessary parameters.
function createInvitation() {
var courseId = '1234567890';
var userEmail = 'test#google.com';
var role = 'TEACHER';
var invitation = {
userId: userEmail,
courseId: courseId,
role: role
};
var response = Classroom.Invitations.create(invitation);
Logger.log(response);
}

I cant fetch document.data from firebase [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I just cant seem to get the snapshot docs to show me the data from the server.
i have checked the collection. it is called "creaciones" without uppercase. I have 1 document and I have files written already. I've made no spelling mistakes whatsoever. I made this work before and now i cant.
ive tried using function "(querySnapshot){" but i got no positive results
//Setup grilla
const setupGrilla = (data) => {
let html = '';
data.forEach(doc => {
const grilla = doc.data();
const creacion = `
<div>
<img src='jpg/${grilla.tipoCreacion}.png' alt='tipoCreacion'>
<h2>${grilla.nombreCreacion}</h2>
<img src='Imagenes/${grilla.nombreFoto}' alt='nombrefoto' class='imagen'>
<span>piezas: ${grilla.piezas}</span>
<span class='separador'></span>
<span>tiempo: ${grilla.tiempo} minutos</span>
<p>padre: ${grilla.ayuda} </p>
<p class='puntos'>Puntos: ${grilla.puntos} </p>
</div>
`;
html += creacion;
});
}
//get Data
db.collection('creaciones').get().then(snapshot => {
setupGrilla(snapshot.docs);
console.log(snapshot.docs);
});
I expect it to fetch the database data.
I have already given you the answer here
You are passing the wrong argument in your method
db.collection('creaciones').get().then(snapshot => {
setupGrilla(snapshot);
});
And you can find the documentation here

Get document collections in Firestore [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
this is my firebase database
- conversations (collection)
-- xxx (document)
--- users (collection)
---- xxx (document)
I want to list all the conversations and its users
this.db.collection('conversations').get().then(querySnapshot => {
querySnapshot.docs.forEach(doc => {
console.log(doc.collection('users').get())
});
});
I´m getting doc.collection is not a function
update: this is what I have after getting the id and making a new query. now the question is. is this performant?
this.db.collection('conversations').get().then(conversationsQuerySnapshot => {
conversationsQuerySnapshot.docs.forEach(doc => {
this.db.collection('conversations').doc(doc.id).collection('users').get().then(usersQuerySnapshot => {
usersQuerySnapshot.docs.forEach(doc => {
console.table(doc.data());
});
});
});
});
You're looking for doc.ref.collection('users'), since you need go get from the DocumentSnapshot to its DocumentReference through doc.ref.
Note that I find it easiest to spot such mistakes by simply following the types. Your querySnapshot is a QuerySnapshot, which means that your doc is a QueryDocumentSnapshot. Since QueryDocumentSnapshot doesn't have a collection method, it's easier to figure out what's going wrong.
you would call it: db.collection('conversations').doc({docID}).collection('users')
Your current query is set up to look through every conversation and then get every user in each of those. Plus the second part (getting the users) has no base document to pull from, which is why you're seeing an error.
I recommend watching this video

Changing nickname of bot with a command [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I would like to make changes to my bot's name with a command like !Changenick nick - by 'nick' I mean the new bot's name. Could you guys help me? I just want bot to change username when someone writes !Changenick for example:
!changenick Freshname
bot changes his own name to Freshname
If you want to change a users nickname you need a GuildMember obj. You can apply this to the bot by searching the guild's member prop for the bots id. The following line will allow you to change the bot's username given a Message obj.
message.guild.me.setNickname('NICKNAME'); updated based on suggestion from #slothiful
If you need further assistance with how to create the entire command, reference https://discordjs.guide/ and https://discord.js.org/#/docs/
Update 1: I am having a hard time understanding your desired implementation with the examples you have provided.
Let's assume you want a command something like this: !changenick <#user> <nickname>
In this case, I would reference this. It explains how you can parse mentions. On to the actual question of changing the nickname, you can change the nickname of any user
(you will get this user via the mention) by using message.guild.members.find(user => user.id === mentionUser.id).setNickname('NICKNAME')
Update 2: I now see what you were getting at. My apologies. You do not need to restart the bot to allow the nickname to update. I have tested it.
The below code changes the bots nickname every 10 seconds.
const Discord = require('discord.js');
const Client = new Discord.Client();
Client.on('ready', () => {
let value = 0;
setInterval(() => {
Client.guilds.find(guild => guild.id === 'GUILD_ID').me.setNickname(value++);
}, 10000);
});
Client.login('TOKEN');
The important bit is
Client.guilds.find(guild => guild.id === 'GUILD_ID').me.setNickname('NICKNAME');
Edit: If this answers your question, mark the answer as accepted.

Load new content and keep track of oldest article [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I have never actually learned how to create a blog or anything the like up to now. I would like to create a personal portfolio/homepage, which will load older articles as soon as the user pushes the "load more" button. Now, I have it all set up, but I don't really know how to keep track of the oldest article ID.
As mentioned, here I load articles from a php script via AJAX.
$('#more_articles_button').click(function () {
$.ajax({ url: kBaseUrl+"content_loader.php",
data: {
action: 'load_more_articles',
article_id: 'insert_lowest_article_id'
},
type: 'post',
success: function(output) {
$('#articles_container').append(output);
}
});
});
Here I would like to get the last article's id and send it to the php script. How do I get hold of it ?
Put the article id in the id's attribute of your article's div and a common class in them (say, 'article'), and, using JQuery, iterate through them to get the maximum value:
var max_id = 0;
$('.article').each(function(i, object) {
curr_id = $(object).attr('id');
if (curr_id > max_id)
max_id = curr_id;
});
//Afterwards, your ajax JQuery call

Categories

Resources