-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #735 from Real-Dev-Squad/onboarding/signup-api
Integrate signup api in onboarding
- Loading branch information
Showing
10 changed files
with
247 additions
and
99 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const ERROR_MESSAGES = { | ||
somethingWentWrong: 'Something went wrong!', | ||
usernameGeneration: 'Username cannot be generated', | ||
}; |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import Service from '@ember/service'; | ||
import { inject as service } from '@ember/service'; | ||
import { TOAST_OPTIONS } from '../constants/toast-options'; | ||
import { ERROR_MESSAGES } from '../constants/error-messages'; | ||
|
||
export default class OnboardingService extends Service { | ||
@service store; | ||
@service toast; | ||
|
||
async signup(dataToUpdate) { | ||
try { | ||
let user = this.store.peekRecord('user', dataToUpdate.username); | ||
|
||
if (!user) { | ||
user = this.store.createRecord('user', {}); | ||
} | ||
|
||
if (dataToUpdate.roles) { | ||
user.set('roles', { | ||
...user.get('roles'), | ||
...dataToUpdate.roles, | ||
}); | ||
} | ||
|
||
user.setProperties({ | ||
first_name: dataToUpdate.first_name, | ||
last_name: dataToUpdate.last_name, | ||
}); | ||
|
||
await user.save(); | ||
} catch (error) { | ||
this.toast.error( | ||
ERROR_MESSAGES.somethingWentWrong, | ||
'error!', | ||
TOAST_OPTIONS, | ||
); | ||
} | ||
} | ||
|
||
async generateUsername(firstname, lastname) { | ||
try { | ||
const sanitizedFirstname = firstname.toLowerCase(); | ||
const sanitizedLastname = lastname.toLowerCase(); | ||
const user = await this.store.queryRecord('user', { | ||
firstname: sanitizedFirstname, | ||
lastname: sanitizedLastname, | ||
dev: true, | ||
}); | ||
if (user && user.username) { | ||
return user; | ||
} | ||
} catch (err) { | ||
this.toast.error( | ||
ERROR_MESSAGES.usernameGeneration, | ||
'error!', | ||
TOAST_OPTIONS, | ||
); | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.