cozy-rsvp/app/models/RSVP.js

47 lines
820 B
JavaScript

import cozySDK from 'cozysdk-client'
import moment from 'moment-timezone'
// Define model fields
const RSVPDefaultFields = {
startTime: null,
endTime: null,
members: [],
eventTypeHash: null,
status: null
}
// 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, {});
}
}
export default RSVP