rendr-helpers
Version:
helper functions to support rendr api related developement
60 lines (59 loc) • 2.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNextDate = exports.isStoreClosed = exports.TIMEZONE_MAPPING = exports.DEFAULT_OPENING_HOURS = exports.SERVICE_LIST = void 0;
var SERVICE_LIST = {
fast: 'Rendr Fast',
standard: 'Rendr Standard',
flexible: 'Rendr Flexible',
};
exports.SERVICE_LIST = SERVICE_LIST;
var DEFAULT_OPENING_HOURS = [
{ from: '09:00', to: '17:00', buffer_minutes: '30' },
{ from: '09:00', to: '17:00', buffer_minutes: '30' },
{ from: '09:00', to: '17:00', buffer_minutes: '30' },
{ from: '09:00', to: '17:00', buffer_minutes: '30' },
{ from: '09:00', to: '17:00', buffer_minutes: '30' },
{ from: '09:00', to: '17:00', buffer_minutes: '30' },
{ from: '09:00', to: '17:00', buffer_minutes: '30' },
];
exports.DEFAULT_OPENING_HOURS = DEFAULT_OPENING_HOURS;
var TIMEZONE_MAPPING = {
VIC: 'Australia/Melbourne',
NSW: 'Australia/Sydney',
TAS: 'Australia/Hobart',
QLD: 'Australia/Brisbane',
NT: 'Australia/Darwin',
WA: 'Australia/Perth',
ACT: 'Australia/Canberra',
};
exports.TIMEZONE_MAPPING = TIMEZONE_MAPPING;
var isStoreClosed = function (from, to) {
return from === to;
};
exports.isStoreClosed = isStoreClosed;
var getNextDate = function (storeDate, currentDay, opening_hours, maxProductBuffer, addBuffer) {
var _a;
if (addBuffer === void 0) { addBuffer = false; }
var from, to, buffer_minutes;
for (var i = 0; i < 7; i++) {
currentDay = (currentDay + 1) % 7;
storeDate = storeDate.add(1, 'd');
(_a = opening_hours[currentDay], from = _a.from, to = _a.to, buffer_minutes = _a.buffer_minutes);
if (!isStoreClosed(from, to)) {
break;
}
}
if (!from || !to)
return null;
if (isStoreClosed(from, to))
return null;
var buffer = addBuffer
? Math.max(maxProductBuffer, Number(buffer_minutes))
: 0;
var fromArray = from.split(':');
var fromDate = storeDate
.hour(Number(fromArray[0]))
.minute(Number(fromArray[1]));
return fromDate.add(buffer, 'm');
};
exports.getNextDate = getNextDate;