Skip to content

Instantly share code, notes, and snippets.

@IniZio
Last active May 8, 2017 03:29
Show Gist options
  • Save IniZio/3cba173e45e6c6490f3be86af83cf0e4 to your computer and use it in GitHub Desktop.
Save IniZio/3cba173e45e6c6490f3be86af83cf0e4 to your computer and use it in GitHub Desktop.
Write array of date objects to skygear
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