cozy-rsvp/app/models/RSVP.js

47 lines
820 B
JavaScript
Raw Normal View History

2016-11-09 23:12:42 +01:00
import cozySDK from 'cozysdk-client'
import moment from 'moment-timezone'
// Define model fields
const RSVPDefaultFields = {
2016-11-07 23:08:33 +01:00
startTime: null,
endTime: null,
members: [],
eventTypeHash: null,
status: null
}
2016-11-09 23:12:42 +01:00
// Define view
cozySDK.defineView(
'rsvp',
'all',
doc => emit(doc._id, doc),
error => error && console.error(error)
)
cozySDK.defineView(
'rsvp',
'by_day',
(doc) => {
// TODO
const day = 'TODO'
emit(day, doc)
},
error => error && console.error(error)
)
// Constructor
class RSVP {
constructor (fields={}) {
Object.assign(this, RSVPDefaultFields, fields)
this.startTime = moment.unix(this.startTime)
this.endTime = moment.unix(this.endTime)
}
static getFromView(view='all') {
return cozySDK.queryView('rsvp', view, {});
}
}
2016-11-07 23:08:33 +01:00
export default RSVP