activated typescript strict mode
This commit is contained in:
@@ -10,11 +10,11 @@ import {first} from 'rxjs/operators';
|
||||
export class ConfigService {
|
||||
public constructor(private db: DbService) {}
|
||||
|
||||
public get get$(): Observable<Config> {
|
||||
public get get$(): Observable<Config | null> {
|
||||
return this.db.doc$<Config>('global/config');
|
||||
}
|
||||
|
||||
public async get(): Promise<Config> {
|
||||
public async get(): Promise<Config | null> {
|
||||
return await this.db.doc$<Config>('global/config').pipe(first()).toPromise();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export interface Config {
|
||||
id: string;
|
||||
ccliLicenseId: string;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import {Injectable} from '@angular/core';
|
||||
import {AngularFirestore, AngularFirestoreCollection, AngularFirestoreDocument} from '@angular/fire/firestore';
|
||||
import {Observable} from 'rxjs';
|
||||
import {QueryFn} from '@angular/fire/firestore/interfaces';
|
||||
import {map} from 'rxjs/operators';
|
||||
|
||||
type CollectionPredicate<T> = string | AngularFirestoreCollection<T>;
|
||||
type DocumentPredicate<T> = string | AngularFirestoreDocument<T>;
|
||||
@@ -20,8 +21,10 @@ export class DbService {
|
||||
return typeof ref === 'string' ? this.afs.doc<T>(ref) : ref;
|
||||
}
|
||||
|
||||
public doc$<T>(ref: DocumentPredicate<T>): Observable<T> {
|
||||
return this.doc(ref).valueChanges({idField: 'id'});
|
||||
public doc$<T>(ref: DocumentPredicate<T>): Observable<(T & {id: string}) | null> {
|
||||
return this.doc(ref)
|
||||
.valueChanges({idField: 'id'})
|
||||
.pipe(map(_ => (_ ? _ : null)));
|
||||
}
|
||||
|
||||
public col$<T>(ref: CollectionPredicate<T>, queryFn?: QueryFn): Observable<T[]> {
|
||||
|
||||
@@ -5,8 +5,8 @@ export function filterSong(song: Song, filterValue: string): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
const textMatch = song.text && normalize(song.text).indexOf(normalize(filterValue)) !== -1;
|
||||
const titleMatch = song.title && normalize(song.title).indexOf(normalize(filterValue)) !== -1;
|
||||
const textMatch = !!song.text && normalize(song.text).indexOf(normalize(filterValue)) !== -1;
|
||||
const titleMatch = !!song.title && normalize(song.title).indexOf(normalize(filterValue)) !== -1;
|
||||
|
||||
return textMatch || titleMatch;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import {Observable} from 'rxjs';
|
||||
export class GlobalSettingsService {
|
||||
public constructor(private db: DbService) {}
|
||||
|
||||
public get get$(): Observable<GlobalSettings> {
|
||||
public get get$(): Observable<GlobalSettings | null> {
|
||||
return this.db.doc$<GlobalSettings>('global/static');
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import {BehaviorSubject} from 'rxjs';
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ScrollService {
|
||||
private scrollPosition: number;
|
||||
private scrollPosition = 0;
|
||||
private scrollSlots: {[key: string]: number} = {};
|
||||
private iRestoreScrollPosition$ = new BehaviorSubject<number>(0);
|
||||
public restoreScrollPosition$ = this.iRestoreScrollPosition$.asObservable();
|
||||
|
||||
@@ -5,11 +5,15 @@ import {UserService} from './user.service';
|
||||
selector: '[appOwner]',
|
||||
})
|
||||
export class OwnerDirective implements OnInit {
|
||||
private currentUserId: string;
|
||||
private currentUserId: string | null = null;
|
||||
private iAppOwner: string | null = null;
|
||||
|
||||
private iAppOwner: string;
|
||||
|
||||
public constructor(private element: ElementRef, private templateRef: TemplateRef<unknown>, private viewContainer: ViewContainerRef, private userService: UserService) {}
|
||||
public constructor(
|
||||
private element: ElementRef,
|
||||
private templateRef: TemplateRef<unknown>,
|
||||
private viewContainer: ViewContainerRef,
|
||||
private userService: UserService
|
||||
) {}
|
||||
|
||||
@Input()
|
||||
public set appOwner(value: string) {
|
||||
|
||||
@@ -8,10 +8,15 @@ import {User} from './user';
|
||||
})
|
||||
export class RoleDirective implements OnInit {
|
||||
@Input() public appRole: roles[] = [];
|
||||
private currentUser: User;
|
||||
private loggedIn: boolean;
|
||||
private currentUser: User | null = null;
|
||||
private loggedIn = false;
|
||||
|
||||
public constructor(private element: ElementRef, private templateRef: TemplateRef<unknown>, private viewContainer: ViewContainerRef, private userService: UserService) {}
|
||||
public constructor(
|
||||
private element: ElementRef,
|
||||
private templateRef: TemplateRef<unknown>,
|
||||
private viewContainer: ViewContainerRef,
|
||||
private userService: UserService
|
||||
) {}
|
||||
|
||||
public ngOnInit(): void {
|
||||
this.userService.user$.subscribe(user => {
|
||||
|
||||
@@ -9,12 +9,12 @@ import {Observable} from 'rxjs';
|
||||
styleUrls: ['./user-name.component.less'],
|
||||
})
|
||||
export class UserNameComponent {
|
||||
public name$: Observable<string>;
|
||||
public name$: Observable<string | null> | null = null;
|
||||
|
||||
public constructor(private userService: UserService) {}
|
||||
|
||||
@Input()
|
||||
public set userId(id: string) {
|
||||
this.name$ = this.userService.getUserbyId$(id).pipe(map(_ => _.name));
|
||||
this.name$ = this.userService.getUserbyId$(id).pipe(map(_ => _?.name ?? null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {AngularFireAuth} from '@angular/fire/auth';
|
||||
import {BehaviorSubject, Observable} from 'rxjs';
|
||||
import {filter, first, switchMap, tap} from 'rxjs/operators';
|
||||
import {filter, first, map, switchMap, tap} from 'rxjs/operators';
|
||||
import {User} from './user';
|
||||
import {DbService} from '../db.service';
|
||||
import {environment} from '../../../environments/environment';
|
||||
@@ -11,41 +11,43 @@ import {Router} from '@angular/router';
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class UserService {
|
||||
private iUserId$ = new BehaviorSubject<string>(null);
|
||||
private iUser$ = new BehaviorSubject<User>(null);
|
||||
private iUserId$ = new BehaviorSubject<string | null>(null);
|
||||
private iUser$ = new BehaviorSubject<User | null>(null);
|
||||
|
||||
public constructor(private afAuth: AngularFireAuth, private db: DbService, private router: Router) {
|
||||
this.afAuth.authState
|
||||
.pipe(
|
||||
filter(_ => !!_),
|
||||
tap(auth => this.iUserId$.next(auth.uid)),
|
||||
switchMap(auth => this.readUser$(auth.uid))
|
||||
filter(auth => !!auth),
|
||||
map(auth => auth?.uid ?? ''),
|
||||
tap(uid => this.iUserId$.next(uid)),
|
||||
switchMap(uid => this.readUser$(uid))
|
||||
)
|
||||
.subscribe(_ => this.iUser$.next(_));
|
||||
}
|
||||
|
||||
public get userId$(): Observable<string> {
|
||||
public get userId$(): Observable<string | null> {
|
||||
return this.iUserId$.asObservable();
|
||||
}
|
||||
|
||||
public get user$(): Observable<User> {
|
||||
public get user$(): Observable<User | null> {
|
||||
return this.iUser$.pipe(filter(_ => !!_));
|
||||
}
|
||||
|
||||
public async currentUser(): Promise<User> {
|
||||
public async currentUser(): Promise<User | null> {
|
||||
return this.user$.pipe(first()).toPromise();
|
||||
}
|
||||
|
||||
public getUserbyId(userId: string): Promise<User> {
|
||||
public getUserbyId(userId: string): Promise<User | null> {
|
||||
return this.getUserbyId$(userId).pipe(first()).toPromise();
|
||||
}
|
||||
|
||||
public getUserbyId$(userId: string): Observable<User> {
|
||||
public getUserbyId$(userId: string): Observable<User | null> {
|
||||
return this.db.doc$<User>('users/' + userId);
|
||||
}
|
||||
|
||||
public async login(user: string, password: string): Promise<string> {
|
||||
public async login(user: string, password: string): Promise<string | null> {
|
||||
const aUser = await this.afAuth.signInWithEmailAndPassword(user, password);
|
||||
if (!aUser.user) return null;
|
||||
const dUser = await this.readUser(aUser.user.uid);
|
||||
this.iUser$.next(dUser);
|
||||
this.iUserId$.next(aUser.user.uid);
|
||||
@@ -73,6 +75,7 @@ export class UserService {
|
||||
|
||||
public async createNewUser(user: string, name: string, password: string): Promise<void> {
|
||||
const aUser = await this.afAuth.createUserWithEmailAndPassword(user, password);
|
||||
if (!aUser.user) return;
|
||||
const userId = aUser.user.uid;
|
||||
await this.db.doc('users/' + userId).set({name, chordMode: 'onlyFirst'});
|
||||
const dUser = await this.readUser(aUser.user.uid);
|
||||
@@ -80,6 +83,6 @@ export class UserService {
|
||||
await this.router.navigateByUrl('/brand/new-user');
|
||||
}
|
||||
|
||||
private readUser$ = (uid: string) => this.db.doc$<User>('users/' + uid);
|
||||
private readUser = async (uid: string): Promise<User> => await this.readUser$(uid).pipe(first()).toPromise();
|
||||
private readUser$ = (uid: string) => this.db.doc$<User | null>('users/' + uid);
|
||||
private readUser = async (uid: string): Promise<User | null> => await this.readUser$(uid).pipe(first()).toPromise();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user