-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
50 lines (45 loc) · 1.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import Ember from 'ember';
import AuthenticatedRouteMixin from 'flaredown/mixins/authenticated-route-mixin';
import CheckinByDate from 'flaredown/mixins/checkin-by-date';
import moment from 'moment';
const {
get,
Route,
} = Ember;
export default Route.extend(CheckinByDate, AuthenticatedRouteMixin, {
/*
REQUIREMENTS:
If the user hasn't completed the onboarding process
default route is the last completed onboarding step
Else
If the user has already checked-in today
default route should be start screen of today's check-in
Else
default route should be summary screen of today's check-in
*/
beforeModel(transition) {
if (typeof FastBoot !== 'undefined') { return; }
transition.abort();
if (get(this, 'session.isAuthenticated')) {
get(this, 'session.currentUser').then(currentUser => {
get(currentUser, 'profile').then(profile => {
if (get(profile, 'isOnboarded')) {
const date = moment(new Date()).format('YYYY-MM-DD');
this.checkinByDate(date).then(
() => {
this.routeToCheckinsForDate(date);
},
() => {
this.routeToNewCheckin(date);
}
);
} else {
this.transitionTo('onboarding', get(profile, 'onboardingStep.stepName'));
}
});
});
} else {
return this._super(...arguments);
}
},
});