-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
54 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,38 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { | ||
getDoc, | ||
orderBy, | ||
DocumentReference, | ||
QueryDocumentSnapshot, | ||
} from '@angular/fire/firestore'; | ||
import { getDoc, orderBy, DocumentReference, QueryDocumentSnapshot } from '@angular/fire/firestore'; | ||
import { FirestoreService, snapshotOptions } from './firestore.service'; | ||
import { Guide } from '../models/guide.model'; | ||
import { Page } from '../models/page.model'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
providedIn: 'root', | ||
}) | ||
export class GuideService extends FirestoreService { | ||
readonly dataPromise = super.getDocuments<Guide>(orderBy('no')); | ||
readonly dataPromise = super.getDocuments<Guide>(orderBy('no')); | ||
|
||
constructor() { | ||
super('guide'); | ||
} | ||
constructor() { | ||
super('guide'); | ||
} | ||
|
||
protected override fromFirestore(snapshot: QueryDocumentSnapshot) { | ||
const toDocument = async (docRef: DocumentReference) => { | ||
const doc = await getDoc(docRef); | ||
return doc.data(snapshotOptions); | ||
}; | ||
protected override fromFirestore(snapshot: QueryDocumentSnapshot) { | ||
const toDocument = async (docRef: DocumentReference) => { | ||
const doc = await getDoc(docRef); | ||
return { | ||
id: doc.id, | ||
...doc.data(snapshotOptions), | ||
}; | ||
}; | ||
|
||
const data = snapshot.data(snapshotOptions); | ||
const pageIds = data['pages'] ?? []; | ||
const pages = Promise.all(pageIds.map(toDocument)); | ||
return { | ||
...data, | ||
pages, | ||
}; | ||
} | ||
const data = snapshot.data(snapshotOptions); | ||
const pageIds = data['pages'] ?? []; | ||
const pages = Promise.all(pageIds.map(toDocument)); | ||
return { | ||
...data, | ||
pages, | ||
}; | ||
} | ||
|
||
async getPages(index: number): Promise<Page[]> { | ||
return this.dataPromise.then(guide => guide[index]?.pages ?? []); | ||
} | ||
async getPages(index: number): Promise<Page[]> { | ||
return this.dataPromise.then((guide) => guide[index]?.pages ?? []); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters