show component
This commit is contained in:
12
src/app/modules/shows/services/show-data.service.spec.ts
Normal file
12
src/app/modules/shows/services/show-data.service.spec.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
|
||||
import {ShowDataService} from './show-data.service';
|
||||
|
||||
describe('ShowDataService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: ShowDataService = TestBed.get(ShowDataService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
19
src/app/modules/shows/services/show-data.service.ts
Normal file
19
src/app/modules/shows/services/show-data.service.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Observable} from 'rxjs';
|
||||
import {DbService} from '../../../services/db.service';
|
||||
import {Show} from './show';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ShowDataService {
|
||||
private collection = 'shows';
|
||||
|
||||
constructor(private dbService: DbService) {
|
||||
}
|
||||
|
||||
public list$ = (): Observable<Show[]> => this.dbService.col$(this.collection);
|
||||
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
|
||||
}
|
||||
37
src/app/modules/shows/services/show.service.spec.ts
Normal file
37
src/app/modules/shows/services/show.service.spec.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
|
||||
import {ShowService} from './show.service';
|
||||
import {ShowDataService} from './show-data.service';
|
||||
|
||||
describe('ShowService', () => {
|
||||
const mockShowDataService = {add: Promise.resolve(null)};
|
||||
beforeEach(() => TestBed.configureTestingModule({
|
||||
providers: [
|
||||
{provide: ShowDataService, useValue: mockShowDataService}
|
||||
]
|
||||
}));
|
||||
|
||||
ShowService.SHOW_TYPE_PUBLIC.forEach(type => {
|
||||
it('should calc public flag for ' + type, async () => {
|
||||
const service: ShowService = TestBed.get(ShowService);
|
||||
const addSpy = spyOn(TestBed.inject(ShowDataService), 'add').and.returnValue(Promise.resolve('id'));
|
||||
|
||||
const id = await service.new$({showType: type});
|
||||
|
||||
expect(id).toBe('id');
|
||||
expect(addSpy).toHaveBeenCalledWith({showType: type, public: true});
|
||||
});
|
||||
});
|
||||
|
||||
ShowService.SHOW_TYPE_PRIVATE.forEach(type => {
|
||||
it('should calc private flag for ' + type, async () => {
|
||||
const service: ShowService = TestBed.get(ShowService);
|
||||
const addSpy = spyOn(TestBed.inject(ShowDataService), 'add').and.returnValue(Promise.resolve('id'));
|
||||
|
||||
const id = await service.new$({showType: type});
|
||||
|
||||
expect(id).toBe('id');
|
||||
expect(addSpy).toHaveBeenCalledWith({showType: type, public: false});
|
||||
});
|
||||
});
|
||||
});
|
||||
27
src/app/modules/shows/services/show.service.ts
Normal file
27
src/app/modules/shows/services/show.service.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ShowDataService} from './show-data.service';
|
||||
import {Show} from './show';
|
||||
import {Observable} from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
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',];
|
||||
|
||||
constructor(private showDataService: ShowDataService) {
|
||||
}
|
||||
|
||||
public read$ = (showId: string): Observable<Show> => this.showDataService.read$(showId);
|
||||
|
||||
public async new$(data: Partial<Show>): Promise<string> {
|
||||
const calculatedData: Partial<Show> = {
|
||||
...data,
|
||||
public: ShowService.SHOW_TYPE_PUBLIC.indexOf(data.showType) !== -1,
|
||||
};
|
||||
return await this.showDataService.add(calculatedData);
|
||||
}
|
||||
}
|
||||
12
src/app/modules/shows/services/show.ts
Normal file
12
src/app/modules/shows/services/show.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import * as firebase from 'firebase';
|
||||
import Timestamp = firebase.firestore.Timestamp;
|
||||
|
||||
|
||||
export interface Show {
|
||||
id: string;
|
||||
showType: string;
|
||||
date: Timestamp;
|
||||
owner: string;
|
||||
public: boolean;
|
||||
reported: boolean;
|
||||
}
|
||||
Reference in New Issue
Block a user