2020-10-30 22:18:17 +03:00
|
|
|
import { createNewUser } from '@wasp/core/auth.js'
|
2020-11-17 13:49:10 +03:00
|
|
|
import HttpError from '@wasp/core/HttpError.js'
|
2020-10-30 22:18:17 +03:00
|
|
|
|
|
|
|
export const signup = async ({ username, email, password }, context) => {
|
2020-11-17 13:49:10 +03:00
|
|
|
try {
|
|
|
|
await createNewUser({ username, email, password })
|
|
|
|
} catch (err) {
|
|
|
|
// TODO: I wish I didn't have to do this, I would love this to be in some
|
|
|
|
// degree done automatically.
|
|
|
|
if (err.code == 'P2002') {
|
|
|
|
throw new HttpError(400, err.meta.target + " must be unique.")
|
|
|
|
}
|
|
|
|
throw err
|
|
|
|
}
|
2020-10-30 22:18:17 +03:00
|
|
|
}
|
2020-11-19 17:11:23 +03:00
|
|
|
|
|
|
|
export const updateUser = async ({ email, username, bio, profilePictureUrl, newPassword }, context) => {
|
|
|
|
// TODO: Nicer error handling! Right now everything is returned as 500 while it could be instead
|
|
|
|
// useful error message about username being taken / not unique, and other validation errors.
|
|
|
|
await context.entities.User.update({
|
|
|
|
where: { email },
|
|
|
|
data: {
|
|
|
|
username,
|
|
|
|
bio,
|
|
|
|
profilePictureUrl,
|
|
|
|
password: newPassword || undefined
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|