-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNotificationTemplate.ts
More file actions
80 lines (76 loc) · 1.82 KB
/
NotificationTemplate.ts
File metadata and controls
80 lines (76 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import mongoose, { Schema, Document } from 'mongoose'
import { Roles, RolesEnum } from '@/types/globals'
export interface INotificationTemplate extends Document {
name: string
title: string
message: string
channels: ('web_push' | 'email' | 'whatsapp' | 'sms')[]
targetRoles: Roles[]
category: 'campaign' | 'system' | 'custom'
createdBy: string // Clerk user ID
isActive: boolean
usageCount: number
createdAt: Date
updatedAt: Date
_id:string
}
const notificationTemplateSchema = new Schema<INotificationTemplate>({
name: {
type: String,
required: true,
trim: true,
maxlength: 100
},
title: {
type: String,
required: true,
trim: true,
maxlength: 200
},
message: {
type: String,
required: true,
trim: true,
maxlength: 1000
},
channels: [{
type: String,
enum: ['web_push', 'email', 'whatsapp', 'sms'],
required: true
}],
targetRoles: [{
type: String,
enum: [...RolesEnum, 'everyone'],
required: true
}],
category: {
type: String,
enum: ['campaign', 'system', 'custom'],
required: true,
default: 'custom'
},
createdBy: {
type: String,
required: true
},
isActive: {
type: Boolean,
default: true
},
usageCount: {
type: Number,
default: 0,
min: 0
}
}, {
timestamps: true,
collection: 'notification_templates'
})
// Indexes for efficient querying
notificationTemplateSchema.index({ createdBy: 1 })
notificationTemplateSchema.index({ category: 1 })
notificationTemplateSchema.index({ isActive: 1 })
notificationTemplateSchema.index({ name: 1, createdBy: 1 }, { unique: true })
notificationTemplateSchema.index({ createdAt: -1 })
export default mongoose.models.NotificationTemplate ||
mongoose.model<INotificationTemplate>('NotificationTemplate', notificationTemplateSchema)