-
Notifications
You must be signed in to change notification settings - Fork 0
/
queryMaker.js
117 lines (112 loc) · 2.81 KB
/
queryMaker.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
module.exports = {
reportQuery : function (params) {
if (params.query.usertype === "BIKE_MESSENGER" && params.query.userid && params.query.userid.length === 24) {
var userid = "Assets." + params.query.userid;
var dynObj = {};
dynObj[userid] = { $exists : true};
dynObj["CreateTime"] = {
$gte: new Date(params.query.startdate),
$lt: new Date(params.query.enddate),
};
return dynObj;
} else if (params.query.username) {
return {
$or: [
{
"CreateTime" : {
$gte: new Date(params.query.startdate),
$lt: new Date(params.query.enddate),
}
},
{
"CompletionTime": {
$gte: new Date(params.query.startdate),
$lt: new Date(params.query.enddate),
}
},
{
"State" : "IN_PROGRESS"
}
],
"User.UserName" : params.query.username
}
}
else if (params.query.usertype === "BIKE_MESSENGER") {
return {
$or: [
{
"CreateTime" : {
$gte: new Date(params.query.startdate),
$lt: new Date(params.query.enddate),
}
},
{
"CompletionTime": {
$gte: new Date(params.query.startdate),
$lt: new Date(params.query.enddate),
}
},
{
"State" : "IN_PROGRESS"
}
]
}
}
else
return {
$or: [
{
"CreateTime" : {
$gte: new Date(params.query.startdate),
$lt: new Date(params.query.enddate),
}
},
{
"CompletionTime": {
$gte: new Date(params.query.startdate),
$lt: new Date(params.query.enddate),
}
},
{
"State" : "IN_PROGRESS"
}
],
"User.Type" : params.query.usertype || "ENTERPRISE"
}
},
productSearchQuery : function (area, keyword) {
console.log(area + " " + keyword)
return {
$and: [
{
"SupportedAreas": {
$in: [ new RegExp(area, 'i')]
}
},
{
$or: [
{
"ProductCategories": {
$in: [new RegExp(keyword,'i')]
}
},
{
"StoreName" : new RegExp(keyword,'i')
},
{
"Products": {
$elemMatch : {
"Name": new RegExp(keyword,'i')
}
}
}
]
}
]
}
},
userListQuery: function (params) {
console.log(params.query.usertype)
return {"Type" : params.query.usertype}, {"_id": 1, "UserName": 1}
}
}