-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathsubscription.js
55 lines (49 loc) · 1.11 KB
/
subscription.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
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
const uuidv4 = require('uuid/v4');
var winston = require('../config/winston');
var SubscriptionSchema = new Schema({
event: {
type: String,
required: true,
index: true
},
target: {
type: String,
required: true,
index: true
},
secret: {
type: String,
required: true,
default: uuidv4(),
select: false
},
id_project: {
type: String,
required: true,
index: true
},
global: {
type: Boolean,
default: false,
select: false,
index: true
},
createdBy: {
type: String,
required: true
}
},{
timestamps: true
}
);
// Subscription.find({event:event, $or:[{id_project: id_project}, {global: true}]})
SubscriptionSchema.index({ event: 1, id_project: 1, global: 1 });
SubscriptionSchema.index({ id_project: 1, event: 1, target: 1 }, { unique: true });
var subscription = mongoose.model('subscription', SubscriptionSchema);
if (process.env.MONGOOSE_SYNCINDEX) {
subscription.syncIndexes();
winston.verbose("subscription syncIndexes")
}
module.exports = subscription;