```
public getDbAllCars() {
const companyCollection = this.afs.collection<Company>(AuthService.COMPANY_COLLECTION_NAME);
return companyCollection.snapshotChanges().pipe(
map(actions => {
return actions.map(a => {
const data = a.payload.doc.data();
const id = a.payload.doc.id;
return { id, ...data };
});
}),
map(companies => {
return companies.map(company => {
console.log(company.id);
return this.getCars(company.id).subscribe();
});
}),
tap(companies => {
console.log(companies);
}),
);
}
下面兩個function 是摳過來的
getCars(companyId: string) {
const carsCollection = this.afs.collection<Car>(`${AuthService.COMPANY_COLLECTION_NAME}/${companyId}/${AuthService.CAR_COLLECTION_NAME}`);
return carsCollection.snapshotChanges().pipe(
map(actions => {
return actions.map(a => {
const data = a.payload.doc.data();
const id = a.payload.doc.id;
return { id, ...data };
});
}),
map(cars => {
return cars.map(car => {
car.pictures = this.getCarPicture(companyId, car.id);
return car;
});
}),
tap(cars => {
console.log('[getCars: Car Service] Cars get');
console.log(cars);
}),
);
}
getCarPicture(companyId: string, carId: string) {
const carPicturesCollection = this.afs.collection<CarPicture>(`${AuthService.COMPANY_COLLECTION_NAME}/${companyId}/${AuthService.CAR_COLLECTION_NAME}/${carId}/${AuthService.CAR_PICTURE_COLLECTION_NAME}`,
ref => ref.where('order', '==', 0));
return carPicturesCollection.snapshotChanges().pipe(
map(actions => {
return actions.map(a => {
const data = a.payload.doc.data();
const id = a.payload.doc.id;
data.image = this.storage.ref(data.image).getDownloadURL();
return { id, ...data };
});
}),
tap(carPictures => {
console.log('[Car Service] Car pictures get');
console.log(carPictures);
}),
);
}
```