feat(classes): store weekdays and meeting times on the class

Keep the class schedule on the class itself so SMS and listings do not have to infer days and hours from sessions.
This commit is contained in:
2026-08-15 23:59:07 +03:30
parent 192c595c68
commit 4d60755a95
5 changed files with 112 additions and 9 deletions
+18
View File
@@ -36,6 +36,24 @@ const classSchema = new mongoose.Schema({
endDate: {
type: Date
},
days: {
type: [{
type: Number,
min: 0,
max: 6
}],
default: []
},
startTime: {
type: String,
trim: true,
default: ''
},
endTime: {
type: String,
trim: true,
default: ''
},
isActive: {
type: Boolean,
default: true
+13 -4
View File
@@ -7,10 +7,17 @@ const Session = require('../sessions/sessionModel');
const AppError = require('../../utils/AppError');
const { calculateMeta, escapeRegex, getSearchTerm } = require('../../utils/pagination');
const { sendClassRegisteredSms } = require('../../utils/senders/smsMessages');
const { buildClassScheduleContext } = require('../../utils/classSchedule');
const { buildClassScheduleContext, normalizeWeekdays, normalizeClockTime } = require('../../utils/classSchedule');
const { pickNotifyFlags } = require('../../utils/notifyFlags');
const logger = require('../../utils/logger');
const applyScheduleFields = (payload, body) => {
if (body.days !== undefined) payload.days = normalizeWeekdays(body.days);
if (body.startTime !== undefined) payload.startTime = normalizeClockTime(body.startTime);
if (body.endTime !== undefined) payload.endTime = normalizeClockTime(body.endTime);
return payload;
};
const getAll = async (query) => {
const page = parseInt(query.page) || 1;
const limit = Math.min(parseInt(query.limit) || 20, 200);
@@ -27,7 +34,7 @@ const getAll = async (query) => {
const [items, total] = await Promise.all([
Class.find(filter)
.select('name course professor students capacity tuitionFee startDate endDate isActive adminNotes createdAt updatedAt')
.select('name course professor students capacity tuitionFee startDate endDate days startTime endTime isActive adminNotes createdAt updatedAt')
.populate({ path: 'course', select: 'title type price' })
.populate({ path: 'professor', select: 'name surname' })
.skip(skip).limit(limit).sort({ createdAt: -1 }).lean(),
@@ -48,12 +55,14 @@ const getOne = async (id) => {
};
const create = async (body) => {
const cls = await Class.create(body);
const payload = applyScheduleFields({ ...body }, body);
const cls = await Class.create(payload);
return getOne(cls._id);
};
const update = async (id, body) => {
const cls = await Class.findByIdAndUpdate(id, body, { new: true, runValidators: true })
const payload = applyScheduleFields({ ...body }, body);
const cls = await Class.findByIdAndUpdate(id, payload, { new: true, runValidators: true })
.populate({ path: 'course', select: 'title' })
.lean();
if (!cls) throw new AppError('CLASS_NOT_FOUND');