jaggerabney / nodejs-the-complete-guide-code Goto Github PK
View Code? Open in Web Editor NEWA repository containing all of the code I wrote while going through the "NodeJS - The Complete Guide (MVC, REST APIs, GraphQL, Deno)" course on Udemy.
A repository containing all of the code I wrote while going through the "NodeJS - The Complete Guide (MVC, REST APIs, GraphQL, Deno)" course on Udemy.
This is because there are no IDs specified for the two number inputs on the page. Change this:
<input type="number" />
<input type="number" />
...to this:
<input id="num1" type="number" />
<input id="num2" type="number" />
This is because the modifications done to the creator
object in the createPost
resolver are never saved. To fix this, add the following after the mutation:
await creator.save();
This is due to the fact that the source is provided incorrectly. It should be a template literal.
Change from this...
img(src="#{product.imageUrl}")
...to this:
img(src=`${product.imageUrl}`)
This is because the total number of posts, which the pagination logic relies on, is not updated when the post is created. In finishEditHandler
, update this:
this.setState((prevState) => {
let updatedPosts = [...prevState.posts];
if (prevState.editPost) {
const postIndex = prevState.posts.findIndex(
(p) => p._id === prevState.editPost._id
);
updatedPosts[postIndex] = post;
} else {
if (prevState.posts.length >= 2) {
updatedPosts.pop();
}
updatedPosts.unshift(post);
}
return {
posts: updatedPosts,
isEditing: false,
editPost: null,
editLoading: false,
};
});
...to this:
this.setState((prevState) => {
let updatedPosts = [...prevState.posts];
let updatedTotal = prevState.totalPosts;
if (prevState.editPost) {
const postIndex = prevState.posts.findIndex(
(p) => p._id === prevState.editPost._id
);
updatedPosts[postIndex] = post;
} else {
updatedTotal++;
if (prevState.posts.length >= 2) {
updatedPosts.pop();
}
updatedPosts.unshift(post);
}
return {
posts: updatedPosts,
isEditing: false,
editPost: null,
editLoading: false,
totalPosts: updatedTotal,
};
});
The user that created a post does not show in both the feed and the single post view. This is because the "creator" field is not populated using the User model's populate
method. Change these:
// --- exports.getPosts ---
const posts = await Post.find()
// These functions are for pagination:
// skip excludes documents and limit restricts how many are returned
.skip((currentPage - 1) * paginationThreshold)
.limit(paginationThreshold);
// --- exports.getPost ---
const post = await Post.findById(postId);
...to these:
// --- exports.getPosts ---
const totalItems = await Post.find().countDocuments();
const posts = await Post.find()
.populate("creator")
// These functions are for pagination:
// skip excludes documents and limit restricts how many are returned
.skip((currentPage - 1) * paginationThreshold)
.limit(paginationThreshold);
// --- exports.getPost ---
const post = await Post.findById(postId).populate("creator");
This error occurs because you forgot to change the login
function in the auth
controller. Change this:
const token = jwt.sign(
{
email: loadedUser.email,
userId: loadedUser._id.toString(),
},
process.env.JWT_KEY,
{ expiresIn: "1h" }
);
...to this:
const token = jwt.sign(
{
email: user.email,
userId: user._id.toString(),
},
process.env.JWT_KEY,
{ expiresIn: "1h" }
);
In /project-1/app.js.
This is because the creator's information is only populated in the exports.getPosts
method in the feed
controller. To fix this, change exports.createPost
from this:
io.get().emit("posts", { action: "create", post });
...to this:
io.get().emit("posts", {
action: "create",
post: {
...post._doc,
creator: { _id: req.userId, name: creator.name },
},
});
The error message is rendered as a modal on the frontend and reads as follows:
Cannot read properties of undefined (reading '_id')
I'm not sure why this happens.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.