-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathdepartment.js
96 lines (87 loc) · 1.95 KB
/
department.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
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var routingConstants = require('../models/routingConstants');
var winston = require('../config/winston');
var TagSchema = require("../models/tag");
var DepartmentSchema = new Schema({
id_bot: {
type: String,
},
bot_only: { //deprecated
type: Boolean,
// required: true
},
routing: {
type: String,
default:routingConstants.POOLED,
// required: true
},
name: {
type: String,
required: true,
index:true
},
description: {
type: String,
// index:true
},
id_project: {
type: String,
required: true,
index: true
},
id_group: {
type: String,
},
// used??
online_msg: {
type: String,
},
offline_msg: {
type: String,
},
default: {
type: Boolean,
default:false,
index: true
// required: true
},
tags: [TagSchema],
status: {
type: Number,
default: 1, // 1: enabled; 0 hidden for widget; -1 hidden for the dashboard;
index: true
// required: true
},
createdBy: {
type: String,
required: true
}
},{
timestamps: true,
toJSON: { virtuals: true }
}
);
DepartmentSchema.virtual('bot', {
ref: 'faq_kb', // The model to use
localField: 'id_bot', // Find people where `localField`
foreignField: '_id', // is equal to `foreignField`
justOne: true,
//options: { sort: { name: -1 }, limit: 5 } // Query options, see http://bit.ly/mongoose-query-options
});
DepartmentSchema.virtual('hasBot').get(function () {
// winston.debug("department hasBot virtual called");
if (this.id_bot!=undefined) {
return true;
}else {
return false;
}
});
// query = { default: true, id_project: projectid };
DepartmentSchema.index({ id_project: 1, default: 1 });
var department = mongoose.model('department', DepartmentSchema);
if (process.env.MONGOOSE_SYNCINDEX) {
department.syncIndexes();
winston.verbose("department syncIndexes")
}
module.exports = department;