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

Add register user mutation #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dpang314
Copy link
Member

@dpang314 dpang314 commented Jan 28, 2025

Description

Resolves #8

Checklist

  • The ticket is mentioned above
  • The changes fulfill the success criteria of the ticket
  • The changes were self-reviewed
  • A review was requested

Copy link

netlify bot commented Jan 28, 2025

Deploy Preview for hope-for-haiti ready!

Name Link
🔨 Latest commit 30cdbba
🔍 Latest deploy log https://app.netlify.com/sites/hope-for-haiti/deploys/67986436b7f1490008b34776
😎 Deploy Preview https://deploy-preview-14--hope-for-haiti.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@dpang314 dpang314 marked this pull request as ready for review January 30, 2025 21:44
@dpang314 dpang314 requested a review from kavinphan January 30, 2025 21:44
* @returns 200
*/
export async function POST(req: NextRequest) {
const parsed = schema.safeParse(await req.formData());
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL about safeParse, nice

Comment on lines +39 to +53
const existingUser = await db.user.findUnique({
where: {
email: userInvite.email
}
});
if (existingUser) {
return conflictError("User already exists");
}
const newUsers = await db.user.create({
data: {
email: userInvite.email,
passwordHash: await argon2.hash(password),
type: userInvite.userType
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

dont use a query to look up existing account-- the db will throw an error because we have a unique index on email

Comment on lines +22 to +31
const goodFormData = new FormData();
goodFormData.append('inviteToken', 'test_token');
goodFormData.append('password', 'test_password');

const mockUser: User = {
type: UserType.SUPER_ADMIN,
id: 0,
email: "[email protected]",
passwordHash: "hashed_test_password"
};
Copy link
Contributor

Choose a reason for hiding this comment

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

super duper tiny nit: not ideal to have mutable data live outside of the scope of tests. theres a chance they could be changed between tests and affect runs

Copy link
Contributor

Choose a reason for hiding this comment

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

one solution is to have these be generator functions that get called in each individual test

type: userInvite.userType
}
});
return NextResponse.json(newUsers, {status: 200});
Copy link
Contributor

Choose a reason for hiding this comment

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

dont return the created user

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.

Register User Mutation
2 participants