Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs? #118

Open
davidquintard opened this issue Aug 7, 2018 · 1 comment
Open

Bugs? #118

davidquintard opened this issue Aug 7, 2018 · 1 comment

Comments

@davidquintard
Copy link

Hi there
I dont understand this function.
Param currentUser is unused
Variable users is undeclared : "or (let x in users) {"

let getContacts = currentUser => {
		return new Promise((resolve, reject) => {
			db.collection('users').find({

			}).toArray((err, data) => {
				if (err) {
					reject();
					return console.log(err);
				}
				if (!data || !data[0]) {
					resolve([]);
					return;
				}

				let contacts = data.map(contact => {
					let online = false;

					for (let x in users) {
						if (users[x].id == contact._id) {
							online = true;
							break;
						}
					}
					return {
						id: contact._id + '',
						name: contact.name,
						username: contact.username,
						image: contact.image,
						online: online
					};
				});
				resolve(contacts);

			});
		});
	};
@therealjimwolff
Copy link

Let x in users iterates over the users array, x representing the current user being iterated. If you aren't connected to the server (and it to MONGODB) and have accounts created, there won't be any and the array will be empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants