Skip to content

221 add validation to patch#227

Open
Rayna-Yu wants to merge 2 commits into
mainfrom
221-check-input-before-patch
Open

221 add validation to patch#227
Rayna-Yu wants to merge 2 commits into
mainfrom
221-check-input-before-patch

Conversation

@Rayna-Yu

@Rayna-Yu Rayna-Yu commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

#221

Closes #221

📝 Description

Briefly list the changes made to the code:

  1. Add validation utils to users
  2. Updated patch to check input before passing to db using validation utils
  3. Updated post to use validation utils
  4. Added unit tests

✔️ Verification

Added tests

🏕️ (Optional) Future Work / Notes

Did you notice anything ugly during the course of this ticket? Any bugs, design challenges, or unexpected behavior? Write it down so we can clean it up in a future ticket!

@Rayna-Yu Rayna-Yu marked this pull request as ready for review June 8, 2026 22:28
@Rayna-Yu Rayna-Yu requested a review from nourshoreibah as a code owner June 8, 2026 22:28
@github-actions github-actions Bot requested a review from tsudhakar87 June 8, 2026 22:28
github-actions Bot added a commit that referenced this pull request Jun 8, 2026

@tsudhakar87 tsudhakar87 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great! Just one question


const profileImageResult = UserValidationUtils.validateProfileImage(body.profileImage);
if (!profileImageResult.isValid) return json(400, { message: profileImageResult.error });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I might be missing something obvious but do isAdmin and profile_image also need to be checked against the validation utils here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added checking isAdmin against validation utils!

@nourshoreibah nourshoreibah left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Mainly one comment about required fields!

let profileImage = body.profileImage as string | undefined;
const updates: { email?: string; name?: string; is_admin?: boolean; profile_image?: string } = {};

const emailResult = UserValidationUtils.validateEmail(body.email);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Very much a nit but I wonder if we should just throw the whole body into the validation utils and let it handle all these conditionals 👀 I don't feel super strongly about this just an idea

static readonly EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

// Validates email - if provided, must be a correctly formatted string
static validateEmail(input: unknown): ValidationResult<string | null> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think email, name, isAdmin should be required. profile image optional makes sense

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.

Check user input before passing to db on PATCH /users

3 participants