-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.js
132 lines (116 loc) · 3.89 KB
/
User.js
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const mongoose = require('mongoose');
// Sub-schemas
const sslCertificateSchema = new mongoose.Schema({
active: { type: Boolean, default: false },
provider: { type: String, default: "Let's Encrypt" },
type: { type: String, enum: ['Standard', 'Wildcard'], default: 'Standard' },
expiryDate: { type: Date },
lastRenewalDate: { type: Date }
});
const dnsRecordSchema = new mongoose.Schema({
type: { type: String, required: true },
value: { type: String, required: true },
lastUpdated: { type: Date, default: Date.now }
});
const domainSchema = new mongoose.Schema({
name: { type: String, required: true },
status: { type: String, enum: ['active', 'pending', 'error'], default: 'pending' },
registrationDate: { type: Date, default: Date.now },
expiryDate: { type: Date, required: true },
autoRenew: { type: Boolean, default: true },
ssl: sslCertificateSchema,
dns: {
records: [dnsRecordSchema]
},
traffic: {
monthly: { type: Number, default: 0 },
bandwidth: { type: String },
uniqueVisitors: { type: Number, default: 0 },
avgDuration: { type: String }
}
});
const websiteSchema = new mongoose.Schema({
domain: { type: String, required: true },
status: { type: String, enum: ['active', 'inactive', 'maintenance'], default: 'active' },
uptime: { type: Number, default: 100 },
lastBackup: { type: Date },
ssl: { type: String, enum: ['Valid', 'Invalid', 'Expired'], default: 'Valid' },
traffic: {
daily: { type: Number, default: 0 },
monthly: { type: Number, default: 0 }
}
});
const activityLogSchema = new mongoose.Schema({
type: {
type: String,
enum: ['backup', 'security', 'traffic', 'update', 'domain'],
required: true
},
title: { type: String, required: true },
description: { type: String },
timestamp: { type: Date, default: Date.now }
});
const subscriptionSchema = new mongoose.Schema({
plan: {
name: { type: String, required: true },
price: { type: Number, required: true },
period: { type: String, enum: ['month', 'year'], required: true },
features: [String]
},
status: { type: String, enum: ['active', 'inactive', 'pending'], default: 'active' },
startDate: { type: Date },
expiryDate: { type: Date },
autoRenew: { type: Boolean, default: true }
});
// Main User Schema
const userSchema = new mongoose.Schema({
// Basic Information
name: { type: String, required: true },
email: { type: String, required: true, unique: true },
password: { type: String, required: true },
createdAt: { type: Date, default: Date.now },
lastLogin: { type: Date },
// Resource Usage
resources: {
hosting: {
totalSpace: { type: Number, required: true }, // in GB
usedSpace: { type: Number, default: 0 },
numberOfFiles: { type: Number, default: 0 },
numberOfDatabases: { type: Number, default: 0 }
},
bandwidth: {
total: { type: Number, required: true }, // in GB
used: { type: Number, default: 0 },
download: { type: Number, default: 0 },
upload: { type: Number, default: 0 }
}
},
// Domains and Websites
domains: [domainSchema],
websites: [websiteSchema],
// Activity Logs
activityLogs: [activityLogSchema],
// Subscription and Billing
subscription: subscriptionSchema,
// Settings and Preferences
settings: {
notifications: {
email: { type: Boolean, default: true },
backup: { type: Boolean, default: true },
security: { type: Boolean, default: true }
},
backupPreferences: {
frequency: { type: String, enum: ['daily', 'weekly', 'monthly'], default: 'daily' },
retention: { type: Number, default: 30 } // days
},
theme: { type: String, default: 'dark' }
}
}, {
timestamps: true
});
// Indexes
userSchema.index({ email: 1 });
userSchema.index({ 'domains.name': 1 });
userSchema.index({ 'activityLogs.timestamp': -1 });
// Export the model
module.exports = mongoose.model('User', userSchema);