feat: Phase 6+9 real-time уведомления, CSS Modules, UI-правки

This commit is contained in:
Suslov-MD
2026-08-16 15:28:21 +00:00
parent 476250d5e3
commit 65c44f570c
31 changed files with 1506 additions and 605 deletions
+72
View File
@@ -0,0 +1,72 @@
import { Schema, model, type HydratedDocument, type Types } from 'mongoose';
/** Тип уведомления о действиях с новостью. */
export type NotificationType = 'news.created' | 'news.updated' | 'news.deleted' | 'news.scheduled' | 'news.published';
export interface INotification {
/** Получатель уведомления. */
user: Types.ObjectId;
/** Кто совершил действие (может совпадать с user). */
actor: Types.ObjectId | null;
/** Тип события. */
type: NotificationType;
/** Ссылка на новость (если применимо). */
news: Types.ObjectId | null;
/** Заголовок уведомления. */
title: string;
/** Тело сообщения. */
message: string;
/** Прочитано ли. */
isRead: boolean;
createdAt: Date;
}
export type NotificationDocument = HydratedDocument<INotification>;
const notificationSchema = new Schema<INotification>(
{
user: {
type: Schema.Types.ObjectId,
ref: 'User',
required: [true, 'Получатель уведомления обязателен'],
},
actor: {
type: Schema.Types.ObjectId,
ref: 'User',
default: null,
},
type: {
type: String,
enum: ['news.created', 'news.updated', 'news.deleted', 'news.scheduled', 'news.published'],
required: [true, 'Тип уведомления обязателен'],
},
news: {
type: Schema.Types.ObjectId,
ref: 'News',
default: null,
},
title: {
type: String,
required: [true, 'Заголовок уведомления обязателен'],
trim: true,
},
message: {
type: String,
default: '',
},
isRead: {
type: Boolean,
default: false,
},
},
{
timestamps: { createdAt: true, updatedAt: false },
},
);
// Индекс для быстрого поиска непрочитанных
notificationSchema.index({ user: 1, isRead: 1, createdAt: -1 });
const Notification = model<INotification>('Notification', notificationSchema);
export default Notification;