cgserver 7.2.686 → 7.2.689
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -75,5 +75,40 @@ class MongoBaseService {
|
|
|
75
75
|
let ret = MongoManager_1.GMongoMgr.aggregate(this._table, pipeline, options);
|
|
76
76
|
return ret;
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* 仅仅支持一级
|
|
80
|
+
* @param array 数据名称 比如 items
|
|
81
|
+
* @param where 数组内赛选条件 比如 "items.id":1
|
|
82
|
+
* @param pre_match 数组上一级赛选条件 比如 "user_id":1
|
|
83
|
+
*/
|
|
84
|
+
async getsInArray(array, where, pre_match) {
|
|
85
|
+
let agg = this.aggregate();
|
|
86
|
+
if (pre_match) {
|
|
87
|
+
agg = agg.match(pre_match);
|
|
88
|
+
}
|
|
89
|
+
agg = agg.unwind("$" + array);
|
|
90
|
+
if (where) {
|
|
91
|
+
agg = agg.match(where);
|
|
92
|
+
}
|
|
93
|
+
let all = await agg.toArray();
|
|
94
|
+
let items = [];
|
|
95
|
+
for (let i = 0; i < all.length; ++i) {
|
|
96
|
+
items.push(all[i][array]);
|
|
97
|
+
}
|
|
98
|
+
return items;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 仅仅支持一级
|
|
102
|
+
* @param array 数据名称 比如 items
|
|
103
|
+
* @param where 数组内赛选条件 比如 "items.id":1
|
|
104
|
+
* @param pre_match 数组上一级赛选条件 比如 "user_id":1
|
|
105
|
+
*/
|
|
106
|
+
async getInArray(array, where, pre_match) {
|
|
107
|
+
let items = await this.getsInArray(array, where, pre_match);
|
|
108
|
+
if (items.length <= 0) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
return items[0];
|
|
112
|
+
}
|
|
78
113
|
}
|
|
79
114
|
exports.MongoBaseService = MongoBaseService;
|
|
@@ -4,12 +4,12 @@ exports.GHttpTool = void 0;
|
|
|
4
4
|
const request = require("request");
|
|
5
5
|
const qs = require("querystring");
|
|
6
6
|
const Log_1 = require("./Log");
|
|
7
|
-
const
|
|
7
|
+
const Core_1 = require("../Core/Core");
|
|
8
8
|
exports.GHttpTool = null;
|
|
9
9
|
class HttpTool {
|
|
10
10
|
get(options_url) {
|
|
11
11
|
let options = null;
|
|
12
|
-
if (
|
|
12
|
+
if (Core_1.core.isString(options_url)) {
|
|
13
13
|
options = { url: options_url };
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
@@ -23,7 +23,7 @@ class HttpTool {
|
|
|
23
23
|
Log_1.GLog.error(error);
|
|
24
24
|
}
|
|
25
25
|
try {
|
|
26
|
-
if (
|
|
26
|
+
if (Core_1.core.isString(body)) {
|
|
27
27
|
body = JSON.parse(body);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -41,7 +41,7 @@ class HttpTool {
|
|
|
41
41
|
}
|
|
42
42
|
post(options_url) {
|
|
43
43
|
let options = null;
|
|
44
|
-
if (
|
|
44
|
+
if (Core_1.core.isString(options_url)) {
|
|
45
45
|
options = { url: options_url };
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
@@ -55,7 +55,7 @@ class HttpTool {
|
|
|
55
55
|
Log_1.GLog.error(error);
|
|
56
56
|
}
|
|
57
57
|
try {
|
|
58
|
-
if (
|
|
58
|
+
if (Core_1.core.isString(body)) {
|
|
59
59
|
body = JSON.parse(body);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -64,4 +64,18 @@ export declare class MongoBaseService<T> {
|
|
|
64
64
|
rs: string;
|
|
65
65
|
}>;
|
|
66
66
|
aggregate(pipeline?: Document[], options?: mongo.AggregateOptions): mongo.AggregationCursor<mongo.Document>;
|
|
67
|
+
/**
|
|
68
|
+
* 仅仅支持一级
|
|
69
|
+
* @param array 数据名称 比如 items
|
|
70
|
+
* @param where 数组内赛选条件 比如 "items.id":1
|
|
71
|
+
* @param pre_match 数组上一级赛选条件 比如 "user_id":1
|
|
72
|
+
*/
|
|
73
|
+
getsInArray<T>(array: string, where?: any, pre_match?: any): Promise<T[]>;
|
|
74
|
+
/**
|
|
75
|
+
* 仅仅支持一级
|
|
76
|
+
* @param array 数据名称 比如 items
|
|
77
|
+
* @param where 数组内赛选条件 比如 "items.id":1
|
|
78
|
+
* @param pre_match 数组上一级赛选条件 比如 "user_id":1
|
|
79
|
+
*/
|
|
80
|
+
getInArray<T>(array: string, where?: any, pre_match?: any): Promise<T>;
|
|
67
81
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cgserver",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.689",
|
|
4
4
|
"author": "trojan",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"description": "free for all.Websocket or Http",
|
|
@@ -48,7 +48,6 @@
|
|
|
48
48
|
"@types/websocket": "^1.0.4",
|
|
49
49
|
"alipay_sdk2": "^1.1.6",
|
|
50
50
|
"alipay-sdk": "^3.1.7",
|
|
51
|
-
"cgserver": "^6.9.468",
|
|
52
51
|
"colors": "^1.4.0",
|
|
53
52
|
"cookie-parser": "^1.4.5",
|
|
54
53
|
"cors": "^2.8.5",
|