Files
modstagram-back/models/NotificationModel.js
2026-09-24 21:03:27 +03:30

66 lines
1.8 KiB
JavaScript

const mongoose = require('mongoose')
const timestamp = require('mongoose-timestamp')
const mongoosePaginate = require('mongoose-paginate-v2')
const notificationSchema = new mongoose.Schema({
user_id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User', // مرجع به مدل کاربر
required: true
},
project_post_id: {
type: mongoose.Schema.Types.ObjectId,
required: false
},
type: {
type: String,
required: true
},
title: {
type: String,
required: true
},
description: {
type: String,
required: true
},
read: {
type: Boolean,
default: false // وضعیت خوانده شده یا نشده
},
actor_id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: false
},
// آواتار فرستنده (برای نوتیف‌های مربوط به یه کاربر خاص) یا بنرِ دستیِ ادمین
// (برای admin_broadcast) — هم توی لیستِ داخلِ اپ و هم توی خودِ پوش FCM استفاده می‌شه
image: {
type: String,
required: false,
default: null
},
// فقط برای اعلان‌های همگانی پنل — جدا از read (که یعنی صفحه اعلان‌ها باز شده)،
// seen یعنی پوش واقعاً به دستگاه رسیده و clicked یعنی کاربر روش ضربه زده
broadcast_id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'AdminBroadcast',
required: false,
index: true
},
push_delivered_seen: {
type: Boolean,
default: false
},
push_clicked: {
type: Boolean,
default: false
}
})
notificationSchema.plugin(timestamp)
notificationSchema.plugin(mongoosePaginate)
const NotificationModel = mongoose.model('Notification', notificationSchema)
module.exports = NotificationModel