mirror of
https://bitbucket.org/tagfer_team/tagfer-server.git
synced 2025-12-25 03:37:38 +00:00
T-954157790482088: Refactor signup endpoint using awaits
This commit is contained in:
parent
59d2530d09
commit
e055b608fa
@ -182,7 +182,7 @@ module.exports = {
|
||||
signinWithEmail,
|
||||
createNewUser,
|
||||
createNewSessionId,
|
||||
getSession
|
||||
getSession,
|
||||
resetPassword
|
||||
};
|
||||
|
||||
|
||||
@ -95,7 +95,7 @@ function signin(req, res) {
|
||||
* @param {Object} req { tagferId: String, email: String, password: String, phoneNumber: String, fullName: String }
|
||||
* @param {Object} res { sessionId: String } | { error: String }
|
||||
*/
|
||||
function signup(req, res) {
|
||||
async function signup(req, res) {
|
||||
const {user, profile} = req.body;
|
||||
const userVerifier = () => user.tagferId && user.email && user.password && user.phoneNumber && user.fullName;
|
||||
const profileVerifier = () => profile.company && profile.company.profession && profile.company.name && profile.company.address && profile.company.number;
|
||||
@ -107,21 +107,14 @@ function signup(req, res) {
|
||||
profile.name = appConfig.defaultProfileName;
|
||||
profile.email = user.email
|
||||
|
||||
authDao.createNewUser(user).then( user => {
|
||||
const sessionId = authDao.createNewSessionId(user.uid);
|
||||
try {
|
||||
profileDao.createInitialProfiles(profile,user.uid).then (() => {
|
||||
res.json({sessionId});
|
||||
}).catch((error) => {
|
||||
res.status(http.BAD_REQUEST).json({error});
|
||||
})
|
||||
} catch (error) {
|
||||
res.status(http.BAD_REQUEST).json({error});
|
||||
}
|
||||
}).catch(error => {
|
||||
res.json( {error} );
|
||||
});
|
||||
|
||||
try {
|
||||
await authDao.createNewUser(user);
|
||||
await profileDao.createInitialProfiles(profile, user.tagferId);
|
||||
const sessionId = authDao.createNewSessionId(user.tagferId);
|
||||
res.status(http.CREATED).json({sessionId});
|
||||
} catch (error) {
|
||||
res.status(http.BAD_REQUEST).json({error:error.code});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user