Service Library - courseScheduling
This document provides a complete reference of the custom code library for the courseScheduling service. It includes all library functions, edge functions with their REST endpoints, templates, and assets.
Library Functions
Library functions are reusable modules available to all business APIs and other custom code within the service via require("lib/<moduleName>").
validateSlotAgainstAvailability.js
module.exports = function validateSlotAgainstAvailability(availabilities, scheduledDate, scheduledTime) {
if (!availabilities || availabilities.length === 0) {
return { valid: false, error: 'No tutor availability found for this course.' };
}
const dateStr = (scheduledDate || '').split('T')[0];
const d = new Date(dateStr + 'T00:00:00Z');
if (isNaN(d.getTime())) return { valid: false, error: 'Invalid scheduled date.' };
const dayNames = ['sunday','monday','tuesday','wednesday','thursday','friday','saturday'];
const slotDay = dayNames[d.getUTCDay()];
const slotHour = parseInt((scheduledTime || '').split(':')[0], 10);
const slotMin = parseInt((scheduledTime || '').split(':')[1], 10) || 0;
const slotMinutes = slotHour * 60 + slotMin;
for (const av of availabilities) {
if (av.dayOfWeek !== slotDay) continue;
if (!av.isRecurring && av.specificDate) {
const avDate = (av.specificDate || '').split('T')[0];
if (avDate !== dateStr) continue;
}
const [sh, sm] = (av.startTime || '').split(':').map(Number);
const [eh, em] = (av.endTime || '').split(':').map(Number);
const startMin = sh * 60 + (sm || 0);
const endMin = eh * 60 + (em || 0);
if (slotMinutes >= startMin && slotMinutes < endMin) {
return { valid: true, error: null };
}
}
return { valid: false, error: 'No matching availability for ' + slotDay + ' at ' + scheduledTime + '.' };
};
This document was generated from the service library configuration and should be kept in sync with design changes.