Created
June 5, 2021 01:40
-
-
Save mosufy/f695ea79af7b981a38615996388144e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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