-
Notifications
You must be signed in to change notification settings - Fork 7
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
Nahom.crud for users #24
base: master
Are you sure you want to change the base?
Conversation
return res.status(404).end(); | ||
} | ||
|
||
res.status(200).json({ data: doc }); |
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.
remove password property when sending info over response
|
||
res.status(200).json({ data: doc }); | ||
} catch (e) { | ||
console.error(e); |
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.
remove debugging statements
const docs = await userModel.find().lean().exec(); | ||
res.status(200).json({ data: docs }); | ||
} catch (e) { | ||
console.error(e); |
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.
remove debugging statement
export const getAllUsers = async (req: Request, res: Response) => { | ||
try { | ||
const docs = await userModel.find().lean().exec(); | ||
res.status(200).json({ data: docs }); |
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.
here also you are sending password as a response
}; | ||
export const createUser = async (req: Request, res: Response) => { | ||
try { | ||
const doc = await userModel.create({ ...req.body }); |
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.
passing the whole req.body is not recommended so better to extract each property from req.body and pass it to create function
const doc = await userModel.create({ ...req.body }); | ||
return res.status(200).json({ data: doc }); | ||
} catch (e) { | ||
console.error(e); |
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.
same here
return res.status(200).json({ data: removed }); | ||
} catch (e) { | ||
console.error(e); | ||
res.status(404).end(); |
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.
better to send 500(internal server error from catch statement since client error has been handle in the try block
}) | ||
) | ||
expect(statusCode).toBe(200); | ||
}) |
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.
add more tests to each request and each scenario (failure and success scenarios)
nahom.CRUD-for-Users