Last active
May 8, 2017 03:29
-
-
Save IniZio/3cba173e45e6c6490f3be86af83cf0e4 to your computer and use it in GitHub Desktop.
Write array of date objects to skygear
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
const event = Object.assign((this.isExistingEvent ? this.event : new eventRecord()), this.form, { | |
beginTime: str2Date(`${this.begin.date} ${this.begin.time}`), | |
endTime: str2Date(`${this.end.date} ${this.end.time}`), | |
rundown: this.rundown.map(slot => ({ time: str2Date(`${slot.date} ${slot.time}`), action: slot.action })) | |
}) | |
WriteRecords(event) | |
.then(records => { console.log(records) }) | |
.catch(error => this.$eventHub.$emit('open-snackbar', 'Failed writing Event!')) | |
const WriteRecords = records => { | |
return new Promise((resolve, reject) => { | |
skygear.publicDB.save(records).then( | |
(records = {}) => resolve(Array.from(records)), | |
error => { | |
console.error(error) | |
reject(error) | |
}) | |
}) | |
} | |
const str2Date = timeStr => !timeStr.replace(/\s/g, '').length ? new Date() : new Date(timeStr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment