CoolFace
Apppublic

sanket3280/code-execution

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
Notification.js26 linesDownload Raw Back to models
1const mongoose = require('mongoose');2const Schema = mongoose.Schema;3 4const NotificationSchema = new Schema({5  user: { type: Schema.Types.ObjectId, ref: 'User', required: true },6  type: { 7    type: String, 8    required: true,9    enum: ['challenge_invite', 'challenge_reminder', 'friend_request', 'system_message']10  },11  title: { type: String, required: true },12  message: { type: String, required: true },13  data: { type: Schema.Types.Mixed }, // Additional data like challengeId, fromUserId, etc.14  read: { type: Boolean, default: false },15  createdAt: { type: Date, default: Date.now },16  expiresAt: { type: Date } // Optional expiration date17});18 19// Index for efficient queries20NotificationSchema.index({ user: 1, read: 1, createdAt: -1 });21NotificationSchema.index({ user: 1, type: 1 });22 23// TTL index - automatically delete notifications after 2 days (172800 seconds)24NotificationSchema.index({ createdAt: 1 }, { expireAfterSeconds: 172800 });25 26module.exports = mongoose.model('Notification', NotificationSchema);