Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
33 lines (30 sloc) 1.14 KB
var defaultsSource = require('../streams/defaultsSource.es6');
var bookingDurationSource = require('../intents/bookingDurationSource.es6');
var timeChangeSource = require('../streams/timeChangeSource.es6');
var roomBookingSource = require('../intents/roomBookingSource.es6');
var pipesAndFilters = require('../../pipesAndFilters.es6');
const CONSTANTS = require('../../constants.es6');
module.exports = (drivers) =>
pipesAndFilters(drivers).
mergeSources(
defaultsSource,
bookingDurationSource,
timeChangeSource,
roomBookingSource
).
scan((prev, curr) => {
var time = prev['time'];
var bookedRoom = ('bookedRoom' in curr) ? curr['bookedRoom'] : prev['bookedRoom'];
var duration = ('duration' in curr) ? curr['duration'] : prev['duration'];
if (bookedRoom != CONSTANTS.ROOM_NONE && 'timeChange' in curr) time = prev['time'] - curr['timeChange'];
if ('bookedRoom' in curr) time = duration;
if (time <= 0) {
time = duration;
bookedRoom = CONSTANTS.ROOM_NONE;
}
return {
time: time,
bookedRoom: bookedRoom,
duration: duration,
};
});