UNPKG

webhandle-calendar

Version:

Calendar tools for node webhandle

108 lines (89 loc) 2.42 kB
const Dreck = require('dreck') let wh = global.webhandle const moment = require('moment') const addCallbackToPromise = require('dreck/add-callback-to-promise') class EventTypesDreck extends Dreck { constructor(options) { super(options) options.timeZone = options.timeZone || '-06:00' this.templatePrefix = 'webhandle-calendar/event-types/' let self = this this.injectors.push((req, focus, next) => { // let day = moment.parseZone(req.body.startDate + 'T' + req.body.startTime + '-06:00') // focus.start = day.toDate() // let end = moment(day) // end.add(req.body.durationHours, 'H') // end.add(req.body.durationMinutes, 'm') // focus.end = end.toDate() // delete focus.startDate // delete focus.startTime // delete focus.durationHours // delete focus.durationMinutes // if(req.body.newpassword) { // wh.services.authService.updatePass(focus, req.body.newpassword) // } // if(req.body.groupNames) { // focus.groups = req.body.groupNames.split(',').map(entry => entry.trim()).filter(entry => !!entry) // } // else { // focus.groups = [] // } next() } ) } // synchronousPostProcessor(obj) { // try { // if(obj.start) { // let m = moment(obj.start) // // obj.startDate = m.format('YYYY-MM-DD') // // obj.startTime = m.format('HH:mm') // obj.startDate = obj.start // obj.startTime = obj.start // let diff = moment(obj.end).diff(obj.start) // obj.durationHours = parseInt(diff / (1000 * 60 * 60)) // obj.durationMinutes = parseInt(diff / (1000 * 60)) - (obj.durationHours * 60) // } // } // catch(e) { // // } // return obj // } createTitle(focus) { return 'Create Event Type' } editTitle(focus) { return 'Edit Event Type' } listTitle(items) { return 'List Event Types' } showTitle(items) { return 'View Event Type' } sort(req, res, focus, callback) { let p = new Promise((resolve, reject) => { if(focus && Array.isArray(focus)) { focus = focus.sort((one, two) => { try { if(!one.name || !two.name) { return 0 } if (one.name < two.name) { return -1 } if (one.name > two.name) { return 1 } } catch(e) {} return 0 }) } resolve(focus) }) return addCallbackToPromise(p, callback) } } module.exports = EventTypesDreck