Skip to content

Instantly share code, notes, and snippets.

@mosufy
Created June 5, 2021 01:40
Show Gist options
  • Save mosufy/f695ea79af7b981a38615996388144e2 to your computer and use it in GitHub Desktop.
Save mosufy/f695ea79af7b981a38615996388144e2 to your computer and use it in GitHub Desktop.
export const createNewAccount = async (params) => {
const validated = validateCreateNewAccountParameters(params);
if (validated) {
const usernameExists = await checkUsernameExists(params.username);
if (!usernameExists) {
const emailExists = await checkEmailExists(params.email);
if (!emailExists) {
return insertUser(params);
} else {
throw new Error('Email already exists');
}
} else {
throw new Error('Username already exists');
}
} else {
throw new Error('Validation error');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment