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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user