-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Exam1 dhlieu2 #67
Conversation
res.status(500).json({ | ||
message: error.message | ||
}); | ||
next(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
next(error)
src/models/user.model.js
Outdated
const mongoose = require("mongoose") | ||
const Schema = mongoose.Schema | ||
|
||
const blogSchema = new Schema( |
There was a problem hiding this comment.
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"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[] => ()
src/models/blog.model.js
Outdated
@@ -2,26 +2,26 @@ const mongoose = require("mongoose"); | |||
const Schema = mongoose.Schema; | |||
|
|||
const blogSchema = new Schema( | |||
{ |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http status: 404
src/controllers/Auth.controller.js
Outdated
const { name, userCode, password } = req.body; | ||
try { | ||
if (!name || !password) { | ||
const err = new Error("Name or password is require"); |
There was a problem hiding this comment.
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
src/controllers/Auth.controller.js
Outdated
const { password, userCode } = req.body; | ||
try { | ||
if (!password) { | ||
const err = new Error("Password is require"); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
src/middleware/Auth.middleware.js
Outdated
const userId = payload.userId | ||
const user = await User.findById(userId) | ||
if(!user) { | ||
const err = new Error("User not exist") |
There was a problem hiding this comment.
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")
Em nộp bài ạ