forked from MyZubster-Ecosystem/myzubster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReminder.js
More file actions
103 lines (99 loc) 路 2.26 KB
/
Copy pathReminder.js
File metadata and controls
103 lines (99 loc) 路 2.26 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const mongoose = require('mongoose');
const REMINDER_TYPES = ['watering', 'fertilizing', 'harvesting', 'pruning'];
const FREQUENCIES = ['daily', 'every_2_days', 'every_3_days', 'weekly', 'biweekly', 'monthly', 'custom'];
const CHANNELS = ['email', 'push', 'telegram'];
const STATUSES = ['pending', 'sent', 'completed', 'skipped', 'missed'];
const reminderSchema = new mongoose.Schema(
{
plantId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Plant',
default: null,
},
gardenId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Garden',
required: true,
index: true,
},
ownerId: {
type: String,
required: true,
trim: true,
index: true,
},
type: {
type: String,
required: true,
enum: REMINDER_TYPES,
index: true,
},
frequency: {
type: String,
required: true,
enum: FREQUENCIES,
},
customIntervalDays: {
type: Number,
min: 1,
max: 365,
default: null,
},
nextDue: {
type: Date,
required: true,
index: true,
},
lastCompleted: {
type: Date,
default: null,
},
status: {
type: String,
enum: STATUSES,
default: 'pending',
index: true,
},
channel: {
type: String,
enum: CHANNELS,
default: 'push',
},
notes: {
type: String,
trim: true,
default: '',
maxlength: 500,
},
isRecurring: {
type: Boolean,
default: true,
},
history: [
{
action: { type: String, enum: ['completed', 'skipped', 'missed', 'sent'] },
at: { type: Date, default: Date.now },
note: { type: String, default: '' },
},
],
},
{
versionKey: false,
timestamps: true,
toJSON: {
virtuals: true,
transform: (_doc, ret) => {
ret.id = ret._id.toString();
delete ret._id;
return ret;
},
},
}
);
reminderSchema.index({ ownerId: 1, status: 1 });
reminderSchema.index({ gardenId: 1, type: 1 });
reminderSchema.index({ nextDue: 1, status: 1 });
module.exports = mongoose.model('Reminder', reminderSchema);
module.exports.REMINDER_TYPES = REMINDER_TYPES;
module.exports.FREQUENCIES = FREQUENCIES;
module.exports.CHANNELS = CHANNELS;