@tech4good/angular-schematics 13.6.0 → 13.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/package.json +1 -1
- package/src/component/files/__name@dasherize__/__name@dasherize__.component.ts.template +8 -8
- package/src/container/files/__name@dasherize__/+state/__name@dasherize__.actions.ts.template +3 -2
- package/src/container/files/__name@dasherize__/+state/__name@dasherize__.effects.ts.template +6 -5
- package/src/container/files/__name@dasherize__/+state/__name@dasherize__.selectors.ts.template +2 -2
- package/src/container/files/__name@dasherize__/__name@dasherize__.component.ts.template +25 -14
- package/src/container/index.js +13 -2
- package/src/container/index.js.map +1 -1
- package/src/entity/files/__name@dasherize__/__name@dasherize__.actions.ts.template +9 -30
- package/src/entity/files/__name@dasherize__/__name@dasherize__.effects.ts.template +23 -24
- package/src/init/files/CHANGELOG.md.template +10 -0
- package/src/init/files/README.md.template +24 -0
- package/src/init/files/package.json.template +4 -2
- package/src/init/files/src/app/admin/admin-routing.module.ts.template +17 -0
- package/src/init/files/src/app/admin/admin.module.spec.ts.template +13 -0
- package/src/init/files/src/app/admin/admin.module.ts.template +28 -0
- package/src/init/files/src/app/admin/waitlist/+state/waitlist.actions.ts.template +23 -0
- package/src/init/files/src/app/admin/waitlist/+state/waitlist.effects.ts.template +50 -0
- package/src/init/files/src/app/admin/waitlist/+state/waitlist.selectors.ts.template +39 -0
- package/src/init/files/src/app/admin/waitlist/+state/waitlist.state.ts.template +13 -0
- package/src/init/files/src/app/admin/waitlist/waitlist.animations.ts.template +4 -0
- package/src/init/files/src/app/admin/waitlist/waitlist.component.html.template +30 -0
- package/src/init/files/src/app/admin/waitlist/waitlist.component.scss.template +14 -0
- package/src/init/files/src/app/admin/waitlist/waitlist.component.spec.ts.template +25 -0
- package/src/init/files/src/app/admin/waitlist/waitlist.component.ts.template +136 -0
- package/src/init/files/src/app/app-routing.module.ts.template +13 -5
- package/src/init/files/src/app/core/analytics/log.service.ts.template +89 -4
- package/src/init/files/src/app/core/analytics/time-analytics.service.ts.template +204 -69
- package/src/init/files/src/app/core/auth/auth.guard.ts.template +85 -0
- package/src/init/files/src/app/core/core.module.ts.template +4 -0
- package/src/init/files/src/app/core/firebase/firebase.service.ts.template +4 -4
- package/src/init/files/src/app/core/local-storage/local-storage.service.ts.template +47 -0
- package/src/init/files/src/app/core/local-storage/session-local-storage.service.ts.template +67 -0
- package/src/init/files/src/app/core/local-storage/session.service.ts.template +48 -0
- package/src/init/files/src/app/core/store/app-state/app-state.actions.ts.template +270 -0
- package/src/init/files/src/app/core/store/app-state/app-state.effects.ts.template +131 -0
- package/src/init/files/src/app/core/store/app-state/app-state.model.ts.template +8 -0
- package/src/init/files/src/app/core/store/app-state/app-state.reducer.spec.ts.template +13 -0
- package/src/init/files/src/app/core/store/app-state/app-state.reducer.ts.template +51 -0
- package/src/init/files/src/app/core/store/app-state/app-state.service.ts.template +50 -0
- package/src/init/files/src/app/core/store/app.effects.ts.template +10 -2
- package/src/init/files/src/app/core/store/app.reducer.ts.template +6 -0
- package/src/init/files/src/app/core/store/app.selectors.ts.template +12 -0
- package/src/init/files/src/app/core/store/auth/auth.actions.ts.template +3 -1
- package/src/init/files/src/app/core/store/auth/auth.effects.ts.template +27 -31
- package/src/init/files/src/app/core/store/auth/auth.reducer.ts.template +1 -1
- package/src/init/files/src/app/core/store/auth/auth.selectors.ts.template +5 -1
- package/src/init/files/src/app/core/store/cached-load-connections.service.ts.template +9 -8
- package/src/init/files/src/app/core/store/user/user.model.ts.template +14 -0
- package/src/init/files/src/app/core/store/user-context/user-context.actions.ts.template +270 -0
- package/src/init/files/src/app/core/store/user-context/user-context.effects.ts.template +131 -0
- package/src/init/files/src/app/core/store/user-context/user-context.model.ts.template +13 -0
- package/src/init/files/src/app/core/store/user-context/user-context.reducer.spec.ts.template +13 -0
- package/src/init/files/src/app/core/store/user-context/user-context.reducer.ts.template +51 -0
- package/src/init/files/src/app/core/store/user-context/user-context.service.ts.template +50 -0
- package/src/init/files/src/app/general/general-routing.module.ts.template +6 -2
- package/src/init/files/src/app/general/general.module.ts.template +8 -2
- package/src/init/files/src/app/general/home/+state/home.actions.ts.template +26 -0
- package/src/init/files/src/app/general/home/+state/home.effects.ts.template +48 -0
- package/src/init/files/src/app/general/home/+state/home.model.ts.template +0 -0
- package/src/init/files/src/app/general/home/+state/home.selectors.ts.template +20 -0
- package/src/init/files/src/app/general/home/+state/home.state.ts.template +13 -0
- package/src/init/files/src/app/general/home/home.animations.ts.template +4 -0
- package/src/init/files/src/app/general/home/home.component.html.template +5 -0
- package/src/init/files/src/app/general/home/home.component.scss.template +5 -0
- package/src/init/files/src/app/general/{e404/e404.component.spec.ts.template → home/home.component.spec.ts.template} +6 -6
- package/src/init/files/src/app/general/home/home.component.ts.template +88 -0
- package/src/init/files/src/app/general/landing/+state/landing.actions.ts.template +26 -0
- package/src/init/files/src/app/general/landing/+state/landing.effects.ts.template +48 -0
- package/src/init/files/src/app/general/landing/+state/landing.model.ts.template +0 -0
- package/src/init/files/src/app/general/landing/+state/landing.selectors.ts.template +20 -0
- package/src/init/files/src/app/general/landing/+state/landing.state.ts.template +13 -0
- package/src/init/files/src/app/general/landing/landing.animations.ts.template +4 -0
- package/src/init/files/src/app/general/landing/landing.component.html.template +3 -0
- package/src/init/files/src/app/general/landing/landing.component.scss.template +13 -0
- package/src/init/files/src/app/general/landing/landing.component.spec.ts.template +25 -0
- package/src/init/files/src/app/general/landing/landing.component.ts.template +98 -0
- package/src/init/files/src/app/general/login/login.component.html.template +5 -5
- package/src/init/files/src/app/general/login/login.component.ts.template +12 -4
- package/src/init/files/src/app/onboarding/consent/+state/consent.actions.ts.template +23 -0
- package/src/init/files/src/app/onboarding/consent/+state/consent.effects.ts.template +47 -0
- package/src/init/files/src/app/onboarding/consent/+state/consent.model.ts.template +0 -0
- package/src/init/files/src/app/onboarding/consent/+state/consent.selectors.ts.template +20 -0
- package/src/init/files/src/app/onboarding/consent/+state/consent.state.ts.template +13 -0
- package/src/init/files/src/app/onboarding/consent/consent.animations.ts.template +4 -0
- package/src/init/files/src/app/onboarding/consent/consent.component.html.template +61 -0
- package/src/init/files/src/app/onboarding/consent/consent.component.scss.template +77 -0
- package/src/init/files/src/app/onboarding/consent/consent.component.spec.ts.template +25 -0
- package/src/init/files/src/app/onboarding/consent/consent.component.ts.template +152 -0
- package/src/init/files/src/app/onboarding/onboarding-routing.module.ts.template +19 -0
- package/src/init/files/src/app/onboarding/onboarding.module.spec.ts.template +13 -0
- package/src/init/files/src/app/onboarding/onboarding.module.ts.template +32 -0
- package/src/init/files/src/app/onboarding/waiting/+state/waiting.actions.ts.template +26 -0
- package/src/init/files/src/app/onboarding/waiting/+state/waiting.effects.ts.template +52 -0
- package/src/init/files/src/app/onboarding/waiting/+state/waiting.model.ts.template +9 -0
- package/src/init/files/src/app/onboarding/waiting/+state/waiting.selectors.ts.template +42 -0
- package/src/init/files/src/app/onboarding/waiting/+state/waiting.state.ts.template +13 -0
- package/src/init/files/src/app/onboarding/waiting/waiting.animations.ts.template +4 -0
- package/src/init/files/src/app/onboarding/waiting/waiting.component.html.template +57 -0
- package/src/init/files/src/app/onboarding/waiting/waiting.component.scss.template +99 -0
- package/src/init/files/src/app/onboarding/waiting/waiting.component.spec.ts.template +25 -0
- package/src/init/files/src/app/onboarding/waiting/waiting.component.ts.template +279 -0
- package/src/init/files/src/app/shared/shared.module.ts.template +3 -0
- package/src/init/files/src/index.html.template +0 -3
- package/src/module/files/__name@dasherize__/__name@dasherize__-routing.module.ts.template +2 -0
- package/src/init/files/src/app/general/e404/e404.component.html.template +0 -1
- package/src/init/files/src/app/general/e404/e404.component.ts.template +0 -28
- /package/src/init/files/src/app/{general/e404/e404.component.scss.template → admin/waitlist/+state/waitlist.model.ts.template} +0 -0
|
@@ -12,7 +12,7 @@ import * as firebase from 'firebase/compat/app';
|
|
|
12
12
|
|
|
13
13
|
import { switchMap, mergeMap, map, catchError, tap, take, pluck } from 'rxjs/operators';
|
|
14
14
|
import { LOAD, LOGIN, LOGIN_SUCCESS, LOGIN_FAIL, LOGOUT, LOGOUT_SUCCESS, LOGOUT_FAIL, Login, LoginSuccess, LoginFail, Logout, LogoutSuccess, LogoutFail, LoadAuth, LoadedAuth } from './auth.actions';
|
|
15
|
-
import { User } from '../user/user.model';
|
|
15
|
+
import { User, AccessState } from '../user/user.model';
|
|
16
16
|
import { UserActionTypes, AddUser, UpdateUser } from '../user/user.actions';
|
|
17
17
|
|
|
18
18
|
@Injectable()
|
|
@@ -24,9 +24,11 @@ export class AuthEffects {
|
|
|
24
24
|
mergeMap((action: Logout) => {
|
|
25
25
|
return this.db.logout().pipe(
|
|
26
26
|
mergeMap(() => [
|
|
27
|
-
|
|
27
|
+
...(action.payload.doNotRoute ? [] : [
|
|
28
|
+
// Change this to where you want to navigate to after logout
|
|
29
|
+
new RouterNavigate(['/landing']),
|
|
30
|
+
]),
|
|
28
31
|
new LogoutSuccess(action.correlationId),
|
|
29
|
-
new RouterNavigate(['/login']),
|
|
30
32
|
]),
|
|
31
33
|
catchError((error) => of(new LogoutFail(error, action.correlationId))),
|
|
32
34
|
);
|
|
@@ -38,17 +40,17 @@ export class AuthEffects {
|
|
|
38
40
|
LoadAuth$: Observable<Action> = createEffect(
|
|
39
41
|
() => this.actions$.pipe(
|
|
40
42
|
ofType<LoadAuth>(LOAD),
|
|
41
|
-
switchMap(() => this.db.afUser()
|
|
42
|
-
|
|
43
|
+
switchMap(() => this.db.afUser()),
|
|
44
|
+
switchMap((afUser: any) => {
|
|
43
45
|
if (afUser) {
|
|
44
46
|
return this.db.queryObjValueChanges<User>('users', afUser.uid).pipe(
|
|
45
|
-
take(1),
|
|
46
47
|
map((user: User) => {
|
|
47
48
|
if (user) {
|
|
48
49
|
return new LoadedAuth({ user });
|
|
49
50
|
} else {
|
|
50
|
-
//
|
|
51
|
-
|
|
51
|
+
// This should not happen. If there is no entry in DB despite
|
|
52
|
+
// having a FireAuth user, make them login again to create an entry
|
|
53
|
+
return new Logout({ doNotRoute: true });
|
|
52
54
|
}
|
|
53
55
|
}),
|
|
54
56
|
);
|
|
@@ -94,6 +96,8 @@ export class AuthEffects {
|
|
|
94
96
|
action: new AddUser(Object.assign({}, userParams, {
|
|
95
97
|
__id: afUser.uid,
|
|
96
98
|
tokens: this.getToken(results.credential),
|
|
99
|
+
consented: false,
|
|
100
|
+
accessState: AccessState.CONSENT,
|
|
97
101
|
})),
|
|
98
102
|
responseActionTypes: {
|
|
99
103
|
success: UserActionTypes.ADD_SUCCESS,
|
|
@@ -102,30 +106,22 @@ export class AuthEffects {
|
|
|
102
106
|
};
|
|
103
107
|
}
|
|
104
108
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
// don't route anywhere
|
|
112
|
-
new LoginSuccess({ ...action.payload, ...results }, action.correlationId),
|
|
113
|
-
];
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
} else {
|
|
117
|
-
return new ActionFlow({
|
|
118
|
-
actionSets: [userActionSet],
|
|
119
|
-
successActionFn: (actionSetResponses) => {
|
|
120
|
-
return [
|
|
121
|
-
new LoadAuth(),
|
|
109
|
+
return new ActionFlow({
|
|
110
|
+
actionSets: [userActionSet],
|
|
111
|
+
successActionFn: (actionSetResponses) => {
|
|
112
|
+
return [
|
|
113
|
+
// Don't route if there is a doNotRoute parameter passed in
|
|
114
|
+
...(action.payload.doNotRoute ? [] : [
|
|
122
115
|
// Change this to where you want to navigate to after login
|
|
123
|
-
new RouterNavigate(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
116
|
+
new RouterNavigate(
|
|
117
|
+
['/home'],
|
|
118
|
+
{ queryParamsHandling: 'preserve' },
|
|
119
|
+
)
|
|
120
|
+
]),
|
|
121
|
+
new LoginSuccess({ ...action.payload, ...results }, action.correlationId),
|
|
122
|
+
];
|
|
123
|
+
},
|
|
124
|
+
});
|
|
129
125
|
}),
|
|
130
126
|
catchError((error) => of(new LoginFail(error, action.correlationId))),
|
|
131
127
|
);
|
|
@@ -15,7 +15,7 @@ export function reducer(state = initialState, action: actions.AuthActions) {
|
|
|
15
15
|
switch (action.type) {
|
|
16
16
|
case actions.LOADED:
|
|
17
17
|
return {
|
|
18
|
-
user:
|
|
18
|
+
user: action.payload.user,
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
default:
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Injectable } from '@angular/core';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
+
import { filter } from 'rxjs/operators';
|
|
3
4
|
|
|
4
5
|
import { Store, select } from '@ngrx/store';
|
|
5
6
|
import * as fromStore from '../app.reducer';
|
|
@@ -16,6 +17,9 @@ export class AuthSelectorsService {
|
|
|
16
17
|
) { }
|
|
17
18
|
|
|
18
19
|
public selectAuthUser = (): Observable<User> => {
|
|
19
|
-
return this.store.pipe(
|
|
20
|
+
return this.store.pipe(
|
|
21
|
+
select(fromAuth.selectUser),
|
|
22
|
+
filter((user) => user !== null),
|
|
23
|
+
);
|
|
20
24
|
};
|
|
21
25
|
}
|
|
@@ -57,30 +57,31 @@ export class CachedLoadConnectionsService {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/** Define a unique key for each connection. */
|
|
60
|
+
// NOTE: The order matters, so we could potentially execute the same query if in some case
|
|
61
|
+
// we had one where query first then the other and in the other case it was reversed
|
|
60
62
|
private getLoadKey(action: LoadAction): string {
|
|
61
|
-
|
|
63
|
+
let queryOptionsString = '';
|
|
62
64
|
if (action.queryOptions) {
|
|
63
65
|
if (action.queryOptions.orderBy) {
|
|
64
|
-
queryOptionsString.concat(
|
|
66
|
+
queryOptionsString = queryOptionsString.concat(`orderBy${action.queryOptions.orderBy}`);
|
|
65
67
|
}
|
|
66
68
|
if (action.queryOptions.limit) {
|
|
67
|
-
queryOptionsString.concat(
|
|
69
|
+
queryOptionsString = queryOptionsString.concat(`limit${action.queryOptions.limit}`);
|
|
68
70
|
}
|
|
69
71
|
if (action.queryOptions.startAt) {
|
|
70
|
-
queryOptionsString.concat(
|
|
72
|
+
queryOptionsString = queryOptionsString.concat(`startAt${action.queryOptions.startAt}`);
|
|
71
73
|
}
|
|
72
74
|
if (action.queryOptions.startAfter) {
|
|
73
|
-
queryOptionsString.concat(
|
|
75
|
+
queryOptionsString = queryOptionsString.concat(`startAfter${action.queryOptions.startAfter}`);
|
|
74
76
|
}
|
|
75
77
|
if (action.queryOptions.endAt) {
|
|
76
|
-
queryOptionsString.concat(
|
|
78
|
+
queryOptionsString = queryOptionsString.concat(`endAt${action.queryOptions.endAt}`);
|
|
77
79
|
}
|
|
78
80
|
if (action.queryOptions.endBefore) {
|
|
79
|
-
queryOptionsString.concat(
|
|
81
|
+
queryOptionsString = queryOptionsString.concat(`endBefore${action.queryOptions.endBefore}`);
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
84
|
const [entityName, collection] = this.getActionAttributes(action);
|
|
83
|
-
|
|
84
85
|
return `${entityName}.${action.queryParams}.${queryOptionsString}`;
|
|
85
86
|
}
|
|
86
87
|
|
|
@@ -12,4 +12,18 @@ export interface User {
|
|
|
12
12
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
13
|
[index: string]: any;
|
|
14
14
|
};
|
|
15
|
+
accessState: AccessState;
|
|
16
|
+
consented: boolean;
|
|
17
|
+
positionNumber?: number;
|
|
18
|
+
joinedWaitlistAt?: Timestamp;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export enum AccessState {
|
|
22
|
+
CONSENT = '01 - consent', // on consent form
|
|
23
|
+
SUBMIT_INTEREST = '02 - submit interest', // short form on login with basic interest
|
|
24
|
+
SUBMIT_DETAILED = '03 - submit detailed', // longer form on richer context
|
|
25
|
+
WAITING = '04 - waiting', // on waitlist for early access
|
|
26
|
+
// PLACEHOLDER: uncomment below for app-specific walkthrough page
|
|
27
|
+
// WALKTHROUGH = '05 - walkthrough', // on app specific walkthrough page
|
|
28
|
+
DONE = 'done', // finished with the entire flow
|
|
15
29
|
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { Action } from '@ngrx/store';
|
|
2
|
+
import { LoadAction } from '../app.actions';
|
|
3
|
+
import { UserContext } from './user-context.model';
|
|
4
|
+
|
|
5
|
+
export enum UserContextActionTypes {
|
|
6
|
+
STREAM = '[UserContext] stream userContext',
|
|
7
|
+
STREAM_SUCCESS = '[UserContext] stream userContext success',
|
|
8
|
+
STREAM_FAIL = '[UserContext] stream userContext fail',
|
|
9
|
+
LOAD = '[UserContext] load userContext',
|
|
10
|
+
LOAD_SUCCESS = '[UserContext] load userContext success',
|
|
11
|
+
LOAD_FAIL = '[UserContext] load userContext fail',
|
|
12
|
+
ADD = '[UserContext] add userContext',
|
|
13
|
+
ADD_SUCCESS = '[UserContext] add userContext success',
|
|
14
|
+
ADD_FAIL = '[UserContext] add userContext fail',
|
|
15
|
+
UPDATE = '[UserContext] update userContext',
|
|
16
|
+
UPDATE_SUCCESS = '[UserContext] update userContext success',
|
|
17
|
+
UPDATE_FAIL = '[UserContext] update userContext fail',
|
|
18
|
+
UPSERT = '[UserContext] upsert userContext',
|
|
19
|
+
UPSERT_SUCCESS = '[UserContext] upsert userContext success',
|
|
20
|
+
UPSERT_FAIL = '[UserContext] upsert userContext fail',
|
|
21
|
+
REMOVE = '[UserContext] remove userContext',
|
|
22
|
+
REMOVE_SUCCESS = '[UserContext] remove userContext success',
|
|
23
|
+
REMOVE_FAIL = '[UserContext] remove userContext fail',
|
|
24
|
+
LOADED = '[UserContext] loaded',
|
|
25
|
+
ADDED = '[UserContext] added',
|
|
26
|
+
MODIFIED = '[UserContext] modified',
|
|
27
|
+
REMOVED = '[UserContext] removed',
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// See Firebase Docs for current constraints on valid queries
|
|
31
|
+
export class StreamUserContext implements Action {
|
|
32
|
+
readonly type = UserContextActionTypes.STREAM;
|
|
33
|
+
constructor(
|
|
34
|
+
// property, comparator, value
|
|
35
|
+
public queryParams: [string, string, any][],
|
|
36
|
+
public queryOptions: {
|
|
37
|
+
orderBy?: string | [string, string],
|
|
38
|
+
limit?: number,
|
|
39
|
+
startAt?: string,
|
|
40
|
+
startAfter?: string,
|
|
41
|
+
endAt?: string,
|
|
42
|
+
endBefore?: string,
|
|
43
|
+
},
|
|
44
|
+
public correlationId: string,
|
|
45
|
+
public followupActions?: (userContext: UserContext) => LoadAction[],
|
|
46
|
+
) {}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class StreamUserContextSuccess implements Action {
|
|
50
|
+
readonly type = UserContextActionTypes.STREAM_SUCCESS;
|
|
51
|
+
constructor(
|
|
52
|
+
public queryParams: [string, string, any][],
|
|
53
|
+
public queryOptions: {
|
|
54
|
+
orderBy?: string | [string, string],
|
|
55
|
+
limit?: number,
|
|
56
|
+
startAt?: string,
|
|
57
|
+
startAfter?: string,
|
|
58
|
+
endAt?: string,
|
|
59
|
+
endBefore?: string,
|
|
60
|
+
},
|
|
61
|
+
public correlationId: string,
|
|
62
|
+
public followupActions?: (userContext: UserContext) => LoadAction[],
|
|
63
|
+
) {}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export class StreamUserContextFail implements Action {
|
|
67
|
+
readonly type = UserContextActionTypes.STREAM_FAIL;
|
|
68
|
+
constructor(
|
|
69
|
+
public error: any,
|
|
70
|
+
public correlationId?: string,
|
|
71
|
+
) {}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
export class LoadUserContext implements Action {
|
|
76
|
+
readonly type = UserContextActionTypes.LOAD;
|
|
77
|
+
constructor(
|
|
78
|
+
// property, comparator, value
|
|
79
|
+
public queryParams: [string, string, any][],
|
|
80
|
+
public queryOptions: {
|
|
81
|
+
orderBy?: string | [string, string],
|
|
82
|
+
limit?: number,
|
|
83
|
+
startAt?: string,
|
|
84
|
+
startAfter?: string,
|
|
85
|
+
endAt?: string,
|
|
86
|
+
endBefore?: string,
|
|
87
|
+
},
|
|
88
|
+
public correlationId: string,
|
|
89
|
+
public followupActions?: (userContext: UserContext) => LoadAction[],
|
|
90
|
+
) {}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export class LoadUserContextSuccess implements Action {
|
|
94
|
+
readonly type = UserContextActionTypes.LOAD_SUCCESS;
|
|
95
|
+
constructor(
|
|
96
|
+
public queryParams: [string, string, any][],
|
|
97
|
+
public queryOptions: {
|
|
98
|
+
orderBy?: string | [string, string],
|
|
99
|
+
limit?: number,
|
|
100
|
+
startAt?: string,
|
|
101
|
+
startAfter?: string,
|
|
102
|
+
endAt?: string,
|
|
103
|
+
endBefore?: string,
|
|
104
|
+
},
|
|
105
|
+
public correlationId: string,
|
|
106
|
+
public followupActions?: (userContext: UserContext) => LoadAction[],
|
|
107
|
+
) {}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export class LoadUserContextFail implements Action {
|
|
111
|
+
readonly type = UserContextActionTypes.LOAD_FAIL;
|
|
112
|
+
constructor(
|
|
113
|
+
public error: any,
|
|
114
|
+
public correlationId?: string,
|
|
115
|
+
) {}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export class AddUserContext implements Action {
|
|
119
|
+
readonly type = UserContextActionTypes.ADD;
|
|
120
|
+
constructor(
|
|
121
|
+
public userContext: UserContext,
|
|
122
|
+
public correlationId?: string,
|
|
123
|
+
) {}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export class AddUserContextSuccess implements Action {
|
|
127
|
+
readonly type = UserContextActionTypes.ADD_SUCCESS;
|
|
128
|
+
constructor(
|
|
129
|
+
public userContext: UserContext,
|
|
130
|
+
public correlationId?: string,
|
|
131
|
+
) {}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export class AddUserContextFail implements Action {
|
|
135
|
+
readonly type = UserContextActionTypes.ADD_FAIL;
|
|
136
|
+
constructor(
|
|
137
|
+
public error: any,
|
|
138
|
+
public correlationId?: string,
|
|
139
|
+
) {}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export class UpdateUserContext implements Action {
|
|
143
|
+
readonly type = UserContextActionTypes.UPDATE;
|
|
144
|
+
constructor(
|
|
145
|
+
public __id: string,
|
|
146
|
+
public changes: Partial<UserContext>,
|
|
147
|
+
public correlationId?: string,
|
|
148
|
+
) { }
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export class UpdateUserContextSuccess implements Action {
|
|
152
|
+
readonly type = UserContextActionTypes.UPDATE_SUCCESS;
|
|
153
|
+
constructor(
|
|
154
|
+
public __id: string,
|
|
155
|
+
public changes: Partial<UserContext>,
|
|
156
|
+
public correlationId?: string,
|
|
157
|
+
) {}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export class UpdateUserContextFail implements Action {
|
|
161
|
+
readonly type = UserContextActionTypes.UPDATE_FAIL;
|
|
162
|
+
constructor(
|
|
163
|
+
public error: any,
|
|
164
|
+
public correlationId?: string,
|
|
165
|
+
) {}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export class UpsertUserContext implements Action {
|
|
169
|
+
readonly type = UserContextActionTypes.UPSERT;
|
|
170
|
+
constructor(
|
|
171
|
+
public userContext: UserContext,
|
|
172
|
+
public correlationId?: string,
|
|
173
|
+
) {}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export class UpsertUserContextSuccess implements Action {
|
|
177
|
+
readonly type = UserContextActionTypes.UPSERT_SUCCESS;
|
|
178
|
+
constructor(
|
|
179
|
+
public userContext: UserContext,
|
|
180
|
+
public correlationId?: string,
|
|
181
|
+
) {}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export class UpsertUserContextFail implements Action {
|
|
185
|
+
readonly type = UserContextActionTypes.UPSERT_FAIL;
|
|
186
|
+
constructor(
|
|
187
|
+
public error: any,
|
|
188
|
+
public correlationId?: string,
|
|
189
|
+
) {}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export class RemoveUserContext implements Action {
|
|
193
|
+
readonly type = UserContextActionTypes.REMOVE;
|
|
194
|
+
constructor(
|
|
195
|
+
public __id: string,
|
|
196
|
+
public correlationId?: string,
|
|
197
|
+
) { }
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export class RemoveUserContextSuccess implements Action {
|
|
201
|
+
readonly type = UserContextActionTypes.REMOVE_SUCCESS;
|
|
202
|
+
constructor(
|
|
203
|
+
public __id: string,
|
|
204
|
+
public correlationId?: string,
|
|
205
|
+
) {}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export class RemoveUserContextFail implements Action {
|
|
209
|
+
readonly type = UserContextActionTypes.REMOVE_FAIL;
|
|
210
|
+
constructor(
|
|
211
|
+
public error: any,
|
|
212
|
+
public correlationId?: string,
|
|
213
|
+
) {}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export class LoadedUserContext implements Action {
|
|
217
|
+
readonly type = UserContextActionTypes.LOADED;
|
|
218
|
+
constructor(
|
|
219
|
+
public payload: UserContext[],
|
|
220
|
+
public correlationId?: string,
|
|
221
|
+
) {}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export class AddedUserContext implements Action {
|
|
225
|
+
readonly type = UserContextActionTypes.ADDED;
|
|
226
|
+
constructor(
|
|
227
|
+
public payload: UserContext,
|
|
228
|
+
public correlationId?: string,
|
|
229
|
+
) {}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export class ModifiedUserContext implements Action {
|
|
233
|
+
readonly type = UserContextActionTypes.MODIFIED;
|
|
234
|
+
constructor(
|
|
235
|
+
public payload: UserContext,
|
|
236
|
+
public correlationId?: string,
|
|
237
|
+
) {}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export class RemovedUserContext implements Action {
|
|
241
|
+
readonly type = UserContextActionTypes.REMOVED;
|
|
242
|
+
constructor(
|
|
243
|
+
public payload: UserContext,
|
|
244
|
+
public correlationId?: string,
|
|
245
|
+
) {}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export type UserContextActions =
|
|
249
|
+
StreamUserContext |
|
|
250
|
+
StreamUserContextSuccess |
|
|
251
|
+
StreamUserContextFail |
|
|
252
|
+
LoadUserContext |
|
|
253
|
+
LoadUserContextSuccess |
|
|
254
|
+
LoadUserContextFail |
|
|
255
|
+
AddUserContext |
|
|
256
|
+
AddUserContextSuccess |
|
|
257
|
+
AddUserContextFail |
|
|
258
|
+
UpdateUserContext |
|
|
259
|
+
UpdateUserContextSuccess |
|
|
260
|
+
UpdateUserContextFail |
|
|
261
|
+
UpsertUserContext |
|
|
262
|
+
UpsertUserContextSuccess |
|
|
263
|
+
UpsertUserContextFail |
|
|
264
|
+
RemoveUserContext |
|
|
265
|
+
RemoveUserContextSuccess |
|
|
266
|
+
RemoveUserContextFail |
|
|
267
|
+
LoadedUserContext |
|
|
268
|
+
AddedUserContext |
|
|
269
|
+
ModifiedUserContext |
|
|
270
|
+
RemovedUserContext;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { Action } from '@ngrx/store';
|
|
3
|
+
import { Actions, createEffect, ofType } from '@ngrx/effects';
|
|
4
|
+
import { EMPTY, of, Observable, throwError, forkJoin, from, pipe, merge } from 'rxjs';
|
|
5
|
+
import { switchMap, flatMap, mergeMap, map, catchError, tap, take } from 'rxjs/operators';
|
|
6
|
+
import { FirebaseService } from '../../firebase/firebase.service';
|
|
7
|
+
import { CachedLoadConnectionsService } from '../cached-load-connections.service';
|
|
8
|
+
|
|
9
|
+
import { UserContext } from './user-context.model';
|
|
10
|
+
import { UserContextActionTypes, UserContextActions,
|
|
11
|
+
StreamUserContext, StreamUserContextSuccess, StreamUserContextFail,
|
|
12
|
+
LoadUserContext, LoadUserContextSuccess, LoadUserContextFail,
|
|
13
|
+
AddUserContext, AddUserContextSuccess, AddUserContextFail,
|
|
14
|
+
UpdateUserContext, UpdateUserContextSuccess, UpdateUserContextFail,
|
|
15
|
+
UpsertUserContext, UpsertUserContextSuccess, UpsertUserContextFail,
|
|
16
|
+
RemoveUserContext, RemoveUserContextSuccess, RemoveUserContextFail } from './user-context.actions';
|
|
17
|
+
|
|
18
|
+
@Injectable()
|
|
19
|
+
export class UserContextEffects {
|
|
20
|
+
/** Process the stream action to create firebase connections. */
|
|
21
|
+
stream$: Observable<Action> = createEffect(
|
|
22
|
+
() => this.actions$.pipe(
|
|
23
|
+
ofType<StreamUserContext>(UserContextActionTypes.STREAM),
|
|
24
|
+
mergeMap((action: StreamUserContext) => {
|
|
25
|
+
const connection = this.clc.processLoadAction(action);
|
|
26
|
+
return connection.loadStream.pipe(
|
|
27
|
+
take(1),
|
|
28
|
+
map(() => new StreamUserContextSuccess(action.queryParams, action.queryOptions, action.correlationId, action.followupActions)),
|
|
29
|
+
catchError((error) => of(new StreamUserContextFail(error, action.correlationId))),
|
|
30
|
+
);
|
|
31
|
+
}),
|
|
32
|
+
),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
/** Process the load action to create firebase connections. */
|
|
36
|
+
load$: Observable<Action> = createEffect(
|
|
37
|
+
() => this.actions$.pipe(
|
|
38
|
+
ofType<LoadUserContext>(UserContextActionTypes.LOAD),
|
|
39
|
+
mergeMap((action: LoadUserContext) => {
|
|
40
|
+
const connection = this.clc.processLoadAction(action);
|
|
41
|
+
return connection.loadStream.pipe(
|
|
42
|
+
take(1),
|
|
43
|
+
map(() => new LoadUserContextSuccess(action.queryParams, action.queryOptions, action.correlationId, action.followupActions)),
|
|
44
|
+
catchError((error) => of(new LoadUserContextFail(error, action.correlationId))),
|
|
45
|
+
);
|
|
46
|
+
}),
|
|
47
|
+
),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
/** Process the add action to update database and initiate callbacks. */
|
|
51
|
+
add$: Observable<Action> = createEffect(
|
|
52
|
+
() => this.actions$.pipe(
|
|
53
|
+
ofType<AddUserContext>(UserContextActionTypes.ADD),
|
|
54
|
+
mergeMap((action: AddUserContext) => {
|
|
55
|
+
return this.db.addEntity('userContexts', action.userContext).pipe(
|
|
56
|
+
mergeMap(() => merge(
|
|
57
|
+
of(new AddUserContextSuccess(action.userContext, action.correlationId)),
|
|
58
|
+
this.actionsOnAdd(action),
|
|
59
|
+
)),
|
|
60
|
+
catchError((error) => of(new AddUserContextFail(error, action.correlationId))),
|
|
61
|
+
);
|
|
62
|
+
}),
|
|
63
|
+
),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
/** Process the update action to update database and initiate callbacks. */
|
|
67
|
+
update$: Observable<Action> = createEffect(
|
|
68
|
+
() => this.actions$.pipe(
|
|
69
|
+
ofType<UpdateUserContext>(UserContextActionTypes.UPDATE),
|
|
70
|
+
mergeMap((action: UpdateUserContext) => {
|
|
71
|
+
return this.db.updateEntity('userContexts', action.__id, action.changes).pipe(
|
|
72
|
+
mergeMap(() => merge(
|
|
73
|
+
of(new UpdateUserContextSuccess(action.__id, action.changes, action.correlationId)),
|
|
74
|
+
this.actionsOnUpdate(action),
|
|
75
|
+
)),
|
|
76
|
+
catchError((error) => of(new UpdateUserContextFail(error, action.correlationId))),
|
|
77
|
+
);
|
|
78
|
+
}),
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
/** Process the upsert action to update database and initiate callbacks. */
|
|
83
|
+
upsert$: Observable<Action> = createEffect(
|
|
84
|
+
() => this.actions$.pipe(
|
|
85
|
+
ofType<UpsertUserContext>(UserContextActionTypes.UPSERT),
|
|
86
|
+
mergeMap((action: UpsertUserContext) => {
|
|
87
|
+
return this.db.upsertEntity('userContexts', action.userContext).pipe(
|
|
88
|
+
mergeMap((results) => merge(
|
|
89
|
+
of(new UpsertUserContextSuccess(action.userContext, action.correlationId)),
|
|
90
|
+
results.type === 'add' ? this.actionsOnAdd(new AddUserContext(action.userContext, action.correlationId)) : this.actionsOnUpdate(new UpdateUserContext(action.userContext.__id, action.userContext, action.correlationId)),
|
|
91
|
+
)),
|
|
92
|
+
catchError((error) => of(new UpsertUserContextFail(error, action.correlationId))),
|
|
93
|
+
);
|
|
94
|
+
}),
|
|
95
|
+
),
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
/** Process the remove action to update database and initiate callbacks. */
|
|
99
|
+
remove$: Observable<Action> = createEffect(
|
|
100
|
+
() => this.actions$.pipe(
|
|
101
|
+
ofType<RemoveUserContext>(UserContextActionTypes.REMOVE),
|
|
102
|
+
mergeMap((action: RemoveUserContext) => {
|
|
103
|
+
return this.db.removeEntity('userContexts', action.__id).pipe(
|
|
104
|
+
mergeMap(() => merge(
|
|
105
|
+
of(new RemoveUserContextSuccess(action.__id, action.correlationId)),
|
|
106
|
+
this.actionsOnRemove(action),
|
|
107
|
+
)),
|
|
108
|
+
catchError((error) => of(new RemoveUserContextFail(error, action.correlationId))),
|
|
109
|
+
);
|
|
110
|
+
}),
|
|
111
|
+
),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
actionsOnAdd(action: AddUserContext): Observable<Action> {
|
|
115
|
+
return EMPTY;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
actionsOnUpdate(action: UpdateUserContext): Observable<Action> {
|
|
119
|
+
return EMPTY;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
actionsOnRemove(action: RemoveUserContext): Observable<Action> {
|
|
123
|
+
return EMPTY;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
constructor(
|
|
127
|
+
private actions$: Actions,
|
|
128
|
+
private db: FirebaseService,
|
|
129
|
+
private clc: CachedLoadConnectionsService,
|
|
130
|
+
) {}
|
|
131
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Timestamp } from '@angular/fire/firestore';
|
|
2
|
+
|
|
3
|
+
export interface UserContext {
|
|
4
|
+
__id: string;
|
|
5
|
+
__userId: string;
|
|
6
|
+
background: {
|
|
7
|
+
selections: string[];
|
|
8
|
+
other?: string;
|
|
9
|
+
}
|
|
10
|
+
desiredValue: string;
|
|
11
|
+
_createdAt?: Timestamp;
|
|
12
|
+
_updatedAt?: Timestamp;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { reducer, initialState } from './user-context.reducer';
|
|
2
|
+
|
|
3
|
+
describe('UserContext Reducer', () => {
|
|
4
|
+
describe('unknown action', () => {
|
|
5
|
+
it('should return the initial state', () => {
|
|
6
|
+
const action = {} as any;
|
|
7
|
+
|
|
8
|
+
const result = reducer(initialState, action);
|
|
9
|
+
|
|
10
|
+
expect(result).toBe(initialState);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity';
|
|
2
|
+
import { UserContext } from './user-context.model';
|
|
3
|
+
import { UserContextActions, UserContextActionTypes } from './user-context.actions';
|
|
4
|
+
import { createFeatureSelector } from '@ngrx/store';
|
|
5
|
+
|
|
6
|
+
export interface State extends EntityState<UserContext> {
|
|
7
|
+
// additional entities state properties
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const adapter: EntityAdapter<UserContext> = createEntityAdapter<UserContext>({
|
|
11
|
+
selectId: (userContext: UserContext) => userContext.__id,
|
|
12
|
+
sortComparer: false,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const initialState: State = adapter.getInitialState({
|
|
16
|
+
// additional entity state properties
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export function reducer(
|
|
20
|
+
state: State = initialState,
|
|
21
|
+
action: UserContextActions,
|
|
22
|
+
) {
|
|
23
|
+
switch (action.type) {
|
|
24
|
+
case UserContextActionTypes.ADDED:
|
|
25
|
+
return adapter.upsertOne(action.payload, state);
|
|
26
|
+
|
|
27
|
+
case UserContextActionTypes.LOADED:
|
|
28
|
+
return adapter.upsertMany(action.payload, state);
|
|
29
|
+
|
|
30
|
+
case UserContextActionTypes.MODIFIED:
|
|
31
|
+
return adapter.updateOne({
|
|
32
|
+
id: action.payload.__id,
|
|
33
|
+
changes: action.payload,
|
|
34
|
+
}, state);
|
|
35
|
+
|
|
36
|
+
case UserContextActionTypes.REMOVED:
|
|
37
|
+
return adapter.removeOne(action.payload.__id, state);
|
|
38
|
+
|
|
39
|
+
default:
|
|
40
|
+
return state;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const getUserContextState = createFeatureSelector<State>('userContext');
|
|
45
|
+
|
|
46
|
+
export const {
|
|
47
|
+
selectIds,
|
|
48
|
+
selectEntities,
|
|
49
|
+
selectAll,
|
|
50
|
+
selectTotal,
|
|
51
|
+
} = adapter.getSelectors(getUserContextState);
|