I am creating a hall booking feature in my app. In this app, I want to save start date and time and end date and time for a hall booking. When a user books a hall for a full day the date color should be changed.
Here I can get the data from the calendar but it is not being inserted in firebase database. The only data being inserted is the UID
and allDay
field. What can I do to fix this?
Here's my code.
addEvent() {
let modal = this.modalCtrl.create('EventModalPage', {
selectedDay: this.selectedDay
});
modal.present();
modal.onDidDismiss(data => {
if (data) {
let eventData = data;
eventData.startTime = new Date(data.startTime);
eventData.endTime = new Date(data.endTime);
let events = [];
events.push(eventData);
// this.eventSource = [];
setTimeout(() => {
this.eventSource = events;
console.log(this.eventSource);
let startTime = this.eventSource['0'].startTime;
let endTime = this.eventSource['0'].endTime;
let allDay = this.eventSource['0'].allDay;
console.log(startTime);
let currentUserUid = this.fire.auth.currentUser.uid;
firebase.database().ref('bookingHall/').push({
uID: currentUserUid,
startTime: startTime,
endTime: endTime,
allDay: allDay,
});
});
}
});
}
The Firebase Realtime Database stores only JSON types. Your
startTime
andendTime
are JavaScriptDate
objects, which are not valid JSON types. To allow storing dates, either store the timestamp (millisecond since the epoch) or a sortable string representation (20181101T034027
) of the value.Also see: