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

Exam1 dhlieu2 #67

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Exam1 dhlieu2 #67

wants to merge 16 commits into from

Conversation

dinhhonglieu
Copy link
Collaborator

Em nộp bài ạ

res.status(500).json({
message: error.message
});
next(err)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next(error)

const mongoose = require("mongoose")
const Schema = mongoose.Schema

const blogSchema = new Schema(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userSchema vaf chưa export

const { blogId } = req.params;
try {
const blog = await Blog.findById(blogId);
const blog = await Blog.findById(blogId).populate["author"];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[] => ()

@@ -2,26 +2,26 @@ const mongoose = require("mongoose");
const Schema = mongoose.Schema;

const blogSchema = new Schema(
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thiếu trường image

const blog = await Blog.findById(blogId).populate["author"];
if (!blog) {
const err = new Error("Blog is not found!");
err.status = 400;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http status: 404

const { name, userCode, password } = req.body;
try {
if (!name || !password) {
const err = new Error("Name or password is require");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name or password is required

const { password, userCode } = req.body;
try {
if (!password) {
const err = new Error("Password is require");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required

err.status = 400;
throw err;
}
const token = await jwt.sign(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check comparePassword vs trả về lỗi cho người dùng là: username or password is incorrect

const userId = payload.userId
const user = await User.findById(userId)
if(!user) {
const err = new Error("User not exist")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const err = new Error("Unauthorized")

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

Successfully merging this pull request may close these issues.

2 participants