Spaces:
Sleeping
Sleeping
| const mongoose = require('mongoose'); | |
| const loyaltyPointsSchema = new mongoose.Schema( | |
| { | |
| userId: { | |
| type: mongoose.Schema.Types.ObjectId, | |
| ref: 'User', | |
| required: true, | |
| unique: true, | |
| }, | |
| totalPoints: { | |
| type: Number, | |
| default: 0, | |
| }, | |
| tier: { | |
| type: String, | |
| enum: ['bronze', 'silver', 'gold', 'platinum'], | |
| default: 'bronze', | |
| }, | |
| pointsHistory: [ | |
| { | |
| action: String, // e.g., "booking_completed", "review_submitted", "referral" | |
| points: Number, | |
| description: String, | |
| bookingId: mongoose.Schema.Types.ObjectId, | |
| timestamp: { | |
| type: Date, | |
| default: Date.now, | |
| }, | |
| }, | |
| ], | |
| redeemedRewards: [ | |
| { | |
| rewardId: String, | |
| pointsUsed: Number, | |
| redeemedAt: { | |
| type: Date, | |
| default: Date.now, | |
| }, | |
| }, | |
| ], | |
| tierBenefits: { | |
| discountPercentage: { | |
| type: Number, | |
| default: 0, | |
| }, | |
| prioritySupport: { | |
| type: Boolean, | |
| default: false, | |
| }, | |
| freeRevisions: { | |
| type: Number, | |
| default: 0, | |
| }, | |
| }, | |
| lastUpdated: { | |
| type: Date, | |
| default: Date.now, | |
| }, | |
| }, | |
| { timestamps: true } | |
| ); | |
| module.exports = mongoose.model('LoyaltyPoints', loyaltyPointsSchema); | |