-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for hope-for-haiti ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
* @returns 200 | ||
*/ | ||
export async function POST(req: NextRequest) { | ||
const parsed = schema.safeParse(await req.formData()); |
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.
TIL about safeParse
, nice
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 | ||
} | ||
}); |
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.
dont use a query to look up existing account-- the db will throw an error because we have a unique index on email
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" | ||
}; |
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.
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
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.
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}); |
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.
dont return the created user
Description
Resolves #8
Checklist