I think maybe it would be better to use something like map<T,R> then what I'm doing currently. Hopefully, I can receive some suggestions on how to get this working. Currently the result is no events get mapped because I'm mapping incorrectly so the path is wrong.
My main issue is bks.fname is undefined as the path is wrong. The correct path is ["05182020"].Peeter.[-MCcGOMe0FT1IqvlCJkd].fname
But how would I define this in a model?
**Returned Json with each key being dynamic: **
05182020:
Peteer:
-MCcGOMe0FT1IqvlCJkd: //The start of the book model
date: "05/18/2020"
name: "Peteer"
service: "b"
shop: "Howards"
time: "10:00 AM"
The Models:
export interface Books {
date?: string;
fname?: string;
lname?: string
name?: string;
service?: string;
shop?: string
time?: string;
}
export interface IDictionary<T> {
[index:string]: Books;
}
export interface Bookings {
[index:string]: Books;
}
export interface CalendarEvent<MetaType = any> {
id?: string | number;
start: Date;
end?: Date;
title: string;
color?: EventColor;
actions?: EventAction[];
allDay?: boolean;
cssClass?: string;
resizable?: {
beforeStart?: boolean;
afterEnd?: boolean;
};
draggable?: boolean;
meta?: MetaType;
}
TS NOTE: the bks.fname and others are undefined because currently map((results) => is taking in the root object instead of just the Books model.
Calaendar.component.ts
events$: Observable<CalendarEvent<IDictionary<Books>>[]>;
this.events$ = this.fs.getFullList2(this.shopName)
.pipe(
catchError(err => {
console.log(err)
return throwError(err);
}),
first(),
tap(results =>
console.log("bookings:", results[0])
),
map((results) => {
return results.map((bks: Books) => {
return {
title: bks.fname + " " + bks.lname + " ---Time: " + bks.time + " , Service: " + bks.service,
start: new Date(bks.date),
color: colors.red,
allDay: true,
meta: bks,//.time,
};
}
);
}
));
fireserveice.ts
getFullList2(shop: string): Observable<any> {
return this.db.list(shop,ref=>ref.limitToFirst(1)).valueChanges()
}