UNPKG

cloud-ide-model-schema

Version:

Pachage for schema management of Cloud IDEsys LMS

137 lines (136 loc) 3.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CNotification = void 0; var mongoose_1 = require("mongoose"); /* SCHEMA START */ var notification = new mongoose_1.Schema({ not_id_user: { type: mongoose_1.default.Schema.Types.ObjectId, ref: "auth_user_mst", required: true, comment: "Target user for notification" }, not_type: { type: String, enum: ['info', 'success', 'warning', 'error', 'system'], required: true, default: 'info', comment: "Notification type" }, not_category: { type: String, required: true, maxlength: 50, comment: "Notification category" }, not_title: { type: String, required: true, maxlength: 200, comment: "Notification title" }, not_message: { type: String, required: true, maxlength: 1000, comment: "Notification message" }, not_data: { type: mongoose_1.Schema.Types.Mixed, comment: "Additional data in JSON format" }, not_action_url: { type: String, maxlength: 500, comment: "URL to navigate on click" }, not_action_label: { type: String, maxlength: 50, comment: "Action button label" }, not_status: { type: String, enum: ['pending', 'sent', 'delivered', 'read', 'archived'], required: true, default: 'pending', comment: "Notification status" }, not_read_at: { type: Date, comment: "When notification was read" }, not_delivered_at: { type: Date, comment: "When notification was delivered" }, not_archived_at: { type: Date, comment: "When notification was archived" }, not_channels: { in_app: { type: Boolean, default: true, comment: "In-app notification enabled" }, email: { type: Boolean, default: false, comment: "Email notification enabled" }, sms: { type: Boolean, default: false, comment: "SMS notification enabled" } }, not_priority: { type: String, enum: ['low', 'normal', 'high', 'urgent'], required: true, default: 'normal', comment: "Notification priority" }, not_expires_at: { type: Date, comment: "Auto-archive after this date" }, not_id_created_by: { type: mongoose_1.default.Schema.Types.ObjectId, ref: "auth_user_mst", comment: "User/system that created notification" }, not_created_at: { type: Date, default: Date.now, comment: "Creation timestamp" }, not_updated_at: { type: Date, default: Date.now, comment: "Last update timestamp" } }, { timestamps: { createdAt: 'not_created_at', updatedAt: 'not_updated_at' }, collection: 'notifications' }); // Indexes for performance // Single field indexes notification.index({ not_id_user: 1 }); notification.index({ not_type: 1 }); notification.index({ not_category: 1 }); notification.index({ not_priority: 1 }); notification.index({ not_status: 1 }); notification.index({ not_created_at: -1 }); // Descending for recent-first queries // Compound indexes for common query patterns notification.index({ not_id_user: 1, not_status: 1 }); notification.index({ not_id_user: 1, not_created_at: -1 }); notification.index({ not_status: 1, not_created_at: -1 }); notification.index({ not_id_user: 1, not_status: 1, not_created_at: -1 }); var CNotification = mongoose_1.default.model("notification", notification); exports.CNotification = CNotification;