Add class numberOfSessions and fix attendance completion detection.

Sessions with full student attendance are now excluded from the pending list reliably by loading class rosters from the database.
This commit is contained in:
2026-08-16 08:55:03 +03:30
parent cd98adff84
commit 0d57854dc3
3 changed files with 67 additions and 17 deletions
+5
View File
@@ -73,6 +73,11 @@ const classSchema = new mongoose.Schema({
trim: true,
default: ''
},
numberOfSessions: {
type: Number,
min: 1,
default: null
},
isActive: {
type: Boolean,
default: true
+20 -3
View File
@@ -18,7 +18,7 @@ const applyScheduleFields = (payload, body) => {
return payload;
};
const CLASS_LIST_FIELDS = 'name course professor students capacity tuitionFee hasDiscount discount freeSpots showOnFrontend startDate endDate days startTime endTime isActive adminNotes createdAt updatedAt';
const CLASS_LIST_FIELDS = 'name course professor students capacity tuitionFee hasDiscount discount freeSpots showOnFrontend startDate endDate days startTime endTime numberOfSessions isActive adminNotes createdAt updatedAt';
const normalizePricingFields = (body = {}) => {
const tuitionFee = Math.max(0, Number(body.tuitionFee) || 0);
@@ -29,6 +29,13 @@ const normalizePricingFields = (body = {}) => {
return { tuitionFee, hasDiscount, discount };
};
const normalizeNumberOfSessions = (value) => {
if (value === '' || value === null || value === undefined) return null;
const parsed = Number(value);
if (!Number.isFinite(parsed) || parsed < 1) return null;
return Math.floor(parsed);
};
const enrichClassForDisplay = (cls) => {
const tuitionFee = cls.tuitionFee || 0;
const discount = cls.hasDiscount ? (cls.discount || 0) : 0;
@@ -77,7 +84,11 @@ const getOne = async (id) => {
};
const create = async (body) => {
const payload = applyScheduleFields({ ...body, ...normalizePricingFields(body) }, body);
const payload = applyScheduleFields({
...body,
...normalizePricingFields(body),
numberOfSessions: normalizeNumberOfSessions(body.numberOfSessions)
}, body);
if (body.freeSpots === '' || body.freeSpots === null || body.freeSpots === undefined) {
payload.freeSpots = null;
} else {
@@ -88,7 +99,13 @@ const create = async (body) => {
};
const update = async (id, body) => {
const payload = applyScheduleFields({ ...body, ...normalizePricingFields(body) }, body);
const payload = applyScheduleFields({
...body,
...normalizePricingFields(body),
...(body.numberOfSessions !== undefined
? { numberOfSessions: normalizeNumberOfSessions(body.numberOfSessions) }
: {})
}, body);
if (body.freeSpots === '' || body.freeSpots === null) {
payload.freeSpots = null;
} else if (body.freeSpots !== undefined) {