Spaces:
Sleeping
Sleeping
| const mongoose = require('mongoose'); | |
| const notificationSchema = new mongoose.Schema({ | |
| recipient: { | |
| type: mongoose.Schema.Types.ObjectId, | |
| ref: 'User', | |
| required: true | |
| }, | |
| type: { | |
| type: String, | |
| enum: ['booking', 'message', 'review', 'system'], | |
| required: true | |
| }, | |
| content: { | |
| type: String, | |
| required: true | |
| }, | |
| link: { | |
| type: String | |
| }, | |
| isRead: { | |
| type: Boolean, | |
| default: false | |
| } | |
| }, { timestamps: true }); | |
| // Index for fetching unread notifications for a user | |
| notificationSchema.index({ recipient: 1, isRead: 1 }); | |
| const Notification = mongoose.model('Notification', notificationSchema); | |
| module.exports = Notification; | |