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

added a new user #11

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
exports.handler = async (event) => {
// TODO: fetch these users from the databse

Choose a reason for hiding this comment

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

There's a typo in the comment. 'databse' should be 'database'.

- // TODO: fetch these users from the databse
+ // TODO: fetch these users from the database

const users = [
{ id: 1, name: 'John Doe', email: '[email protected]' },
{ id: 2, name: 'Jane Smith', email: '[email protected]' },
{ id: 3, name: 'Alice Johnson', email: '[email protected]' }
{ id: 3, name: 'Alice Johnson', email: '[email protected]' },
{ id: 3, name: 'Bob Brown', email: 'bob@mail' },

Choose a reason for hiding this comment

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

There are two issues with this user entry:

  1. The id is duplicated (3 is already used for Alice Johnson).
  2. The email address is not in a valid format.
- { id: 3, name: 'Bob Brown', email: 'bob@mail' },
+ { id: 4, name: 'Bob Brown', email: '[email protected]' },

];
user = users.map(user => {
user.name = user.name.toUpperCase();
return user;
});
Comment on lines +9 to +12

Choose a reason for hiding this comment

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

The user variable is declared without const, let, or var, which may lead to unexpected behavior. Also, the mapping operation doesn't affect the original users array. If the intention is to modify the original array, use users = users.map(...) instead.

- user = users.map(user => {
-     user.name = user.name.toUpperCase();
-     return user;
- });
+ users = users.map(user => ({
+     ...user,
+     name: user.name.toUpperCase()
+ }));


const response = {
statusCode: 200,
body: JSON.stringify(users),
};

return response;

console.log('Unreachable code');

Choose a reason for hiding this comment

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

This line contains unreachable code as it's placed after the return statement. It should be removed or moved before the return statement if logging is necessary.

- console.log('Unreachable code');

};
Loading