feat: add class discounts, frontend visibility, and public listing

Add hasDiscount, freeSpots, and showOnFrontend on classes with a public get-all endpoint and richer notification user populate.
This commit is contained in:
2026-08-16 08:11:42 +03:30
parent 21bff0c4ba
commit f57d8bbdfa
5 changed files with 100 additions and 10 deletions
+28 -1
View File
@@ -30,6 +30,25 @@ const classSchema = new mongoose.Schema({
type: Number,
default: 0
},
hasDiscount: {
type: Boolean,
default: false
},
discount: {
type: Number,
default: 0,
min: 0
},
freeSpots: {
type: Number,
min: 0,
default: null
},
showOnFrontend: {
type: Boolean,
default: true,
index: true
},
startDate: {
type: Date
},
@@ -63,7 +82,15 @@ const classSchema = new mongoose.Schema({
default: []
}
}, {
timestamps: true
timestamps: true,
toJSON: { virtuals: true },
toObject: { virtuals: true }
});
classSchema.virtual('finalTuitionFee').get(function () {
const tuition = this.tuitionFee || 0;
if (!this.hasDiscount) return tuition;
return Math.max(0, tuition - (this.discount || 0));
});
module.exports = mongoose.model('Class', classSchema);