activated typescript strict mode
This commit is contained in:
@@ -37,7 +37,9 @@ export class DocxService {
|
||||
) {}
|
||||
|
||||
public async create(showId: string, options: DownloadOptions = {}): Promise<void> {
|
||||
const {show, songs, user, config} = await this.prepareData(showId);
|
||||
const data = await this.prepareData(showId);
|
||||
if (!data) return;
|
||||
const {show, songs, user, config} = data;
|
||||
const type = new ShowTypePipe().transform(show.showType);
|
||||
const title = `${type} ${show.date.toDate().toLocaleDateString()}`;
|
||||
|
||||
@@ -61,7 +63,12 @@ export class DocxService {
|
||||
this.saveAs(blob, `${title}.docx`);
|
||||
}
|
||||
|
||||
private prepareNewDocument(type: string, name: string, options: DownloadOptions, sections: ISectionOptions[]): Document {
|
||||
private prepareNewDocument(
|
||||
type: string,
|
||||
name: string,
|
||||
options: DownloadOptions,
|
||||
sections: ISectionOptions[]
|
||||
): Document {
|
||||
return new Document({
|
||||
creator: name,
|
||||
title: type,
|
||||
@@ -92,16 +99,29 @@ export class DocxService {
|
||||
});
|
||||
}
|
||||
|
||||
private renderSongs(songs: {showSong: ShowSong; song: Song; sections: Section[]}[], options: DownloadOptions, config: Config): Paragraph[] {
|
||||
return songs.reduce((p: Paragraph[], song) => [...p, ...this.renderSong(song.showSong, song.song, song.sections, options, config)], []);
|
||||
private renderSongs(
|
||||
songs: {showSong: ShowSong; song: Song; sections: Section[]}[],
|
||||
options: DownloadOptions,
|
||||
config: Config
|
||||
): Paragraph[] {
|
||||
return songs.reduce(
|
||||
(p: Paragraph[], song) => [...p, ...this.renderSong(song.showSong, song.song, song.sections, options, config)],
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
private renderSong(showSong: ShowSong, song: Song, sections: Section[], options: DownloadOptions, config: Config): Paragraph[] {
|
||||
private renderSong(
|
||||
showSong: ShowSong,
|
||||
song: Song,
|
||||
sections: Section[],
|
||||
options: DownloadOptions,
|
||||
config: Config
|
||||
): Paragraph[] {
|
||||
const songTitle = this.renderSongTitle(song);
|
||||
const copyright = this.renderCopyright(song, options, config);
|
||||
const songText = this.renderSongText(sections, options?.chordMode ?? showSong.chordMode);
|
||||
|
||||
return [songTitle, copyright, ...songText].filter(_ => _);
|
||||
return copyright ? [songTitle, copyright, ...songText] : [songTitle, ...songText];
|
||||
}
|
||||
|
||||
private renderSongText(sections: Section[], chordMode: ChordMode): Paragraph[] {
|
||||
@@ -119,7 +139,7 @@ export class DocxService {
|
||||
});
|
||||
}
|
||||
|
||||
private renderCopyright(song: Song, options: DownloadOptions, config: Config): Paragraph {
|
||||
private renderCopyright(song: Song, options: DownloadOptions, config: Config): Paragraph | null {
|
||||
if (!options?.copyright) {
|
||||
return null;
|
||||
}
|
||||
@@ -128,7 +148,10 @@ export class DocxService {
|
||||
const artist = song.artist ? song.artist + ', ' : '';
|
||||
const termsOfUse = song.termsOfUse ? song.termsOfUse + ', ' : '';
|
||||
const origin = song.origin ? song.origin + ', ' : '';
|
||||
const licence = song.legalOwner === 'CCLI' ? 'CCLI-Liednummer: ' + song.legalOwnerId + ', CCLI-Lizenz: ' + config.ccliLicenseId : 'CCLI-Liednummer: ' + song.legalOwnerId;
|
||||
const licence =
|
||||
song.legalOwner === 'CCLI'
|
||||
? 'CCLI-Liednummer: ' + song.legalOwnerId + ', CCLI-Lizenz: ' + config.ccliLicenseId
|
||||
: 'CCLI-Liednummer: ' + song.legalOwnerId;
|
||||
|
||||
return new Paragraph({
|
||||
text: artist + label + termsOfUse + origin + licence,
|
||||
@@ -178,14 +201,18 @@ export class DocxService {
|
||||
show: Show;
|
||||
user: User;
|
||||
config: Config;
|
||||
}> {
|
||||
} | null> {
|
||||
const show = await this.showService.read$(showId).pipe(first()).toPromise();
|
||||
if (!show) return null;
|
||||
const user = await this.userService.getUserbyId(show.owner);
|
||||
if (!user) return null;
|
||||
const config = await this.configService.get();
|
||||
if (!config) return null;
|
||||
|
||||
const showSongs = await this.showSongService.list(showId);
|
||||
const songsAsync = showSongs.map(async showSong => {
|
||||
const song = await this.songService.read(showSong.songId);
|
||||
if (!song) return null;
|
||||
const sections = this.textRenderingService.parse(song.text, {
|
||||
baseKey: showSong.keyOriginal,
|
||||
targetKey: showSong.key,
|
||||
@@ -196,7 +223,9 @@ export class DocxService {
|
||||
sections,
|
||||
};
|
||||
});
|
||||
const songs = await Promise.all(songsAsync);
|
||||
const songs = (await Promise.all(songsAsync))
|
||||
.filter(_ => !!_)
|
||||
.map(_ => _ as {showSong: ShowSong; song: Song; sections: Section[]});
|
||||
return {songs, show, user, config};
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@ export class ShowDataService {
|
||||
public constructor(private dbService: DbService) {}
|
||||
|
||||
public list$ = (queryFn?: 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 read$ = (showId: string): Observable<Show | null> => 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;
|
||||
}
|
||||
|
||||
@@ -13,10 +13,14 @@ export class ShowSongDataService {
|
||||
|
||||
public constructor(private dbService: DbService) {}
|
||||
|
||||
public list$ = (showId: string, queryFn?: QueryFn): Observable<ShowSong[]> => this.dbService.col$(`${this.collection}/${showId}/${this.subCollection}`, queryFn);
|
||||
public read$ = (showId: string, songId: string): Observable<ShowSong | undefined> => this.dbService.doc$(`${this.collection}/${showId}/${this.subCollection}/${songId}`);
|
||||
public list$ = (showId: string, queryFn?: QueryFn): Observable<ShowSong[]> =>
|
||||
this.dbService.col$(`${this.collection}/${showId}/${this.subCollection}`, queryFn);
|
||||
public read$ = (showId: string, songId: string): Observable<ShowSong | null> =>
|
||||
this.dbService.doc$(`${this.collection}/${showId}/${this.subCollection}/${songId}`);
|
||||
public update$ = async (showId: string, songId: string, data: Partial<ShowSong>): Promise<void> =>
|
||||
await this.dbService.doc(`${this.collection}/${showId}/${this.subCollection}/${songId}`).update(data);
|
||||
public delete = async (showId: string, songId: string): Promise<void> => await this.dbService.doc(`${this.collection}/${showId}/${this.subCollection}/${songId}`).delete();
|
||||
public add = async (showId: string, data: Partial<ShowSong>): Promise<string> => (await this.dbService.col(`${this.collection}/${showId}/${this.subCollection}`).add(data)).id;
|
||||
public delete = async (showId: string, songId: string): Promise<void> =>
|
||||
await this.dbService.doc(`${this.collection}/${showId}/${this.subCollection}/${songId}`).delete();
|
||||
public add = async (showId: string, data: Partial<ShowSong>): Promise<string> =>
|
||||
(await this.dbService.col(`${this.collection}/${showId}/${this.subCollection}`).add(data)).id;
|
||||
}
|
||||
|
||||
@@ -10,11 +10,16 @@ import {UserService} from '../../../services/user/user.service';
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ShowSongService {
|
||||
public constructor(private showSongDataService: ShowSongDataService, private songDataService: SongDataService, private userService: UserService) {}
|
||||
public constructor(
|
||||
private showSongDataService: ShowSongDataService,
|
||||
private songDataService: SongDataService,
|
||||
private userService: UserService
|
||||
) {}
|
||||
|
||||
public async new$(showId: string, songId: string, order: number, addedLive = false): Promise<string> {
|
||||
public async new$(showId: string, songId: string, order: number, addedLive = false): Promise<string | null> {
|
||||
const song = await this.songDataService.read$(songId).pipe(take(1)).toPromise();
|
||||
const user = await this.userService.user$.pipe(take(1)).toPromise();
|
||||
if (!song || !user) return null;
|
||||
const data: Partial<ShowSong> = {
|
||||
songId,
|
||||
order,
|
||||
@@ -26,8 +31,10 @@ export class ShowSongService {
|
||||
return await this.showSongDataService.add(showId, data);
|
||||
}
|
||||
|
||||
public list$ = (showId: string): Observable<ShowSong[]> => this.showSongDataService.list$(showId, _ => _.orderBy('order'));
|
||||
public list$ = (showId: string): Observable<ShowSong[]> =>
|
||||
this.showSongDataService.list$(showId, _ => _.orderBy('order'));
|
||||
public list = (showId: string): Promise<ShowSong[]> => this.list$(showId).pipe(first()).toPromise();
|
||||
public delete$ = (showId: string, songId: string): Promise<void> => this.showSongDataService.delete(showId, songId);
|
||||
public update$ = async (showId: string, songId: string, data: Partial<ShowSong>): Promise<void> => await this.showSongDataService.update$(showId, songId, data);
|
||||
public update$ = async (showId: string, songId: string, data: Partial<ShowSong>): Promise<void> =>
|
||||
await this.showSongDataService.update$(showId, songId, data);
|
||||
}
|
||||
|
||||
@@ -10,30 +10,51 @@ import {User} from '../../../services/user/user';
|
||||
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 = [
|
||||
'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;
|
||||
private user: User | null = null;
|
||||
|
||||
public constructor(private showDataService: ShowDataService, private userService: UserService) {
|
||||
userService.user$.subscribe(_ => (this.user = _));
|
||||
}
|
||||
|
||||
public read$ = (showId: string): Observable<Show> => this.showDataService.read$(showId);
|
||||
public read$ = (showId: string): Observable<Show | null> => this.showDataService.read$(showId);
|
||||
|
||||
public list$(publishedOnly = false): Observable<Show[]> {
|
||||
return this.userService.user$.pipe(
|
||||
switchMap(
|
||||
() => this.showDataService.list$(),
|
||||
(user: User, shows: Show[]) => ({user, shows})
|
||||
(user: User | null, shows: Show[]) => ({user, shows})
|
||||
),
|
||||
map(s => s.shows.filter(_ => !_.archived).filter(show => show.published || (show.owner === s.user.id && !publishedOnly)))
|
||||
map(s =>
|
||||
s.shows.filter(_ => !_.archived).filter(show => show.published || (show.owner === s.user?.id && !publishedOnly))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public update$ = async (showId: string, data: Partial<Show>): Promise<void> => this.showDataService.update(showId, data);
|
||||
public update$ = async (showId: string, data: Partial<Show>): Promise<void> =>
|
||||
this.showDataService.update(showId, data);
|
||||
|
||||
public async new$(data: Partial<Show>): Promise<string> {
|
||||
public async new$(data: Partial<Show>): Promise<string | null> {
|
||||
if (!data.showType || !this.user) return null;
|
||||
const calculatedData: Partial<Show> = {
|
||||
...data,
|
||||
owner: this.user.id,
|
||||
|
||||
Reference in New Issue
Block a user