forked from MyZubster-Ecosystem/myzubster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActivity.js
More file actions
48 lines (45 loc) 路 1.02 KB
/
Copy pathActivity.js
File metadata and controls
48 lines (45 loc) 路 1.02 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
const mongoose = require('mongoose');
const activitySchema = new mongoose.Schema(
{
gardenId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Garden',
index: true,
},
plantType: {
type: String,
trim: true,
default: '',
},
type: {
type: String,
enum: ['plant_added', 'plant_updated', 'harvest', 'comment'],
required: true,
},
actor: {
id: { type: String, trim: true, default: '' },
name: { type: String, trim: true, default: 'Anonimo' },
avatar: { type: String, default: '' },
},
message: {
type: String,
trim: true,
default: '',
},
},
{
versionKey: false,
timestamps: true,
toJSON: {
virtuals: true,
transform: (_doc, ret) => {
ret.id = ret._id.toString();
delete ret._id;
return ret;
},
},
}
);
activitySchema.index({ createdAt: -1 });
activitySchema.index({ gardenId: 1, createdAt: -1 });
module.exports = mongoose.model('Activity', activitySchema);