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

Nahom.crud for users #24

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Nahom.crud for users #24

wants to merge 6 commits into from

Conversation

NahomSeleshi
Copy link
Contributor

nahom.CRUD-for-Users

return res.status(404).end();
}

res.status(200).json({ data: doc });
Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

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 });
Copy link
Collaborator

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 });
Copy link
Collaborator

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);
Copy link
Collaborator

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();
Copy link
Collaborator

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);
})
Copy link
Collaborator

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)

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