publish show
This commit is contained in:
@@ -12,7 +12,7 @@ export class ShowDataService {
|
||||
constructor(private dbService: DbService) {
|
||||
}
|
||||
|
||||
public list$ = (): Observable<Show[]> => this.dbService.col$(this.collection);
|
||||
public list$ = (queryFn?): Observable<Show[]> => this.dbService.col$(this.collection, queryFn);
|
||||
public read$ = (showId: string): Observable<Show | undefined> => this.dbService.doc$(`${this.collection}/${showId}`);
|
||||
public update = async (showId: string, data: Partial<Show>): Promise<void> => await this.dbService.doc(`${this.collection}/${showId}`).update(data);
|
||||
public add = async (data: Partial<Show>): Promise<string> => (await this.dbService.col(this.collection).add(data)).id
|
||||
|
||||
@@ -2,6 +2,9 @@ import {Injectable} from '@angular/core';
|
||||
import {ShowDataService} from './show-data.service';
|
||||
import {Show} from './show';
|
||||
import {Observable} from 'rxjs';
|
||||
import {UserService} from '../../../services/user.service';
|
||||
import {map, switchMap} from 'rxjs/operators';
|
||||
import {User} from '../../../services/user';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -11,15 +14,32 @@ export class ShowService {
|
||||
public static SHOW_TYPE = ['service-worship', 'service-praise', 'home-group-big', 'home-group', 'prayer-group', 'teens-group', 'kids-group', 'misc-public', 'misc-private'];
|
||||
public static SHOW_TYPE_PUBLIC = ['service-worship', 'service-praise', 'home-group-big', 'teens-group', 'kids-group', 'misc-public'];
|
||||
public static SHOW_TYPE_PRIVATE = ['home-group', 'prayer-group', 'misc-private',];
|
||||
private user: User;
|
||||
|
||||
constructor(private showDataService: ShowDataService) {
|
||||
constructor(private showDataService: ShowDataService, private userService: UserService) {
|
||||
userService.user$.subscribe(_ => this.user = _);
|
||||
}
|
||||
|
||||
public read$ = (showId: string): Observable<Show> => this.showDataService.read$(showId);
|
||||
|
||||
public list$(publishedOnly: boolean = false): Observable<Show[]> {
|
||||
|
||||
return this.userService.user$.pipe(
|
||||
switchMap(_ => this.showDataService.list$(), (user: User, shows: Show[]) => ({user, shows})),
|
||||
map(_ => _.shows
|
||||
.filter(_ => !_.archived)
|
||||
.filter(show => show.published || (show.owner === _.user.id && !publishedOnly))
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
public update$ = async (showId: string, data: Partial<Show>): Promise<void> => this.showDataService.update(showId, data);
|
||||
|
||||
public async new$(data: Partial<Show>): Promise<string> {
|
||||
const calculatedData: Partial<Show> = {
|
||||
...data,
|
||||
owner: this.user.id,
|
||||
public: ShowService.SHOW_TYPE_PUBLIC.indexOf(data.showType) !== -1,
|
||||
};
|
||||
return await this.showDataService.add(calculatedData);
|
||||
|
||||
@@ -8,6 +8,8 @@ export interface Show {
|
||||
owner: string;
|
||||
public: boolean;
|
||||
reported: boolean;
|
||||
published: boolean;
|
||||
archived: boolean;
|
||||
|
||||
presentationSongId: string;
|
||||
presentationSection: number;
|
||||
|
||||
Reference in New Issue
Block a user