cgserver 12.3.6 → 13.0.1
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.
- package/dist/lib/Framework/Config/_error_.js +33 -24
- package/dist/lib/Framework/Database/Mongo/MongoBaseService.js +143 -119
- package/dist/lib/Framework/Database/Mongo/MongoManager.js +18 -561
- package/dist/lib/Framework/Decorator/JsonAuthorityValidate.js +1 -5
- package/dist/lib/Framework/Logic/Log.js +20 -5
- package/dist/lib/Framework/Server/WebServer/Controller/MongoBaseUserController.js +11 -25
- package/dist/lib/Framework/Server/WebServer/Controller/MysqlBaseUserController.js +0 -26
- package/dist/lib/Framework/Service/MongoAccountService.js +53 -116
- package/dist/lib/Framework/Service/MongoCacheService.js +20 -19
- package/dist/lib/Framework/Service/MongoUserService.js +39 -77
- package/dist/lib/Framework/Service/MysqlUserService.js +3 -12
- package/dist/lib/Framework/Service/ini.js +4 -10
- package/dist/lib/Framework/global.js +0 -2
- package/dist/lib/Framework/index_export_.js +2 -21
- package/dist/types/Framework/Config/_error_.d.ts +28 -92
- package/dist/types/Framework/Database/Mongo/MongoBaseService.d.ts +35 -113
- package/dist/types/Framework/Database/Mongo/MongoManager.d.ts +4 -145
- package/dist/types/Framework/Decorator/JsonAuthorityValidate.d.ts +1 -2
- package/dist/types/Framework/Logic/Log.d.ts +5 -5
- package/dist/types/Framework/Server/WebServer/Controller/MongoBaseUserController.d.ts +4 -8
- package/dist/types/Framework/Server/WebServer/Controller/MysqlBaseUserController.d.ts +0 -4
- package/dist/types/Framework/Service/MongoAccountService.d.ts +15 -17
- package/dist/types/Framework/Service/MongoCacheService.d.ts +5 -4
- package/dist/types/Framework/Service/MongoUserService.d.ts +14 -26
- package/dist/types/Framework/Service/MysqlUserService.d.ts +2 -4
- package/dist/types/Framework/Service/ini.d.ts +3 -8
- package/dist/types/Framework/global.d.ts +0 -1
- package/dist/types/Framework/index_export_.d.ts +5 -12
- package/package.json +2 -1
- package/dist/lib/Framework/Database/Mongo/MongoServiceManager.js +0 -52
- package/dist/lib/Framework/Decorator/AdminValidate.js +0 -18
- package/dist/lib/Framework/Decorator/AuthorityValidate.js +0 -22
- package/dist/lib/Framework/Decorator/CreatorValidate.js +0 -18
- package/dist/lib/Framework/Decorator/JsonCreatorValidate.js +0 -18
- package/dist/types/Framework/Database/Mongo/MongoServiceManager.d.ts +0 -13
- package/dist/types/Framework/Decorator/AdminValidate.d.ts +0 -1
- package/dist/types/Framework/Decorator/AuthorityValidate.d.ts +0 -2
- package/dist/types/Framework/Decorator/CreatorValidate.d.ts +0 -1
- package/dist/types/Framework/Decorator/JsonCreatorValidate.d.ts +0 -1
|
@@ -1,34 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FrameworkErrorCode = exports.EErrorCode = void 0;
|
|
3
|
+
exports.FrameworkErrorCode = exports.Errcode = exports.EErrorCode = void 0;
|
|
4
4
|
exports.EErrorCode = null;
|
|
5
|
+
class Errcode {
|
|
6
|
+
id;
|
|
7
|
+
des;
|
|
8
|
+
constructor(id, des) {
|
|
9
|
+
this.id = id;
|
|
10
|
+
this.des = des;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.Errcode = Errcode;
|
|
5
14
|
/**
|
|
6
15
|
* 1-100
|
|
7
16
|
*/
|
|
8
17
|
class FrameworkErrorCode {
|
|
9
|
-
Wrong_Params =
|
|
10
|
-
Verify_failed =
|
|
11
|
-
Account_Create_Failed =
|
|
12
|
-
User_Create_Failed =
|
|
13
|
-
Server_Error =
|
|
14
|
-
No_Account =
|
|
15
|
-
Mysql_Error =
|
|
16
|
-
No_Mysql =
|
|
17
|
-
No_Mssql =
|
|
18
|
-
No_User =
|
|
19
|
-
Account_Phone_Exist =
|
|
20
|
-
Account_Email_Exist =
|
|
21
|
-
Account_Name_Exist =
|
|
22
|
-
Account_Type_Error =
|
|
23
|
-
Email_Send_Failed =
|
|
24
|
-
Login_Failed =
|
|
25
|
-
Password_Too_Short =
|
|
26
|
-
Wrong_Phone =
|
|
27
|
-
PhoneCode_Too_Quick =
|
|
28
|
-
PhoneCode_GetFailed =
|
|
29
|
-
Wrong_Phone_Code =
|
|
30
|
-
No_Mongo =
|
|
31
|
-
Mongo_Error =
|
|
18
|
+
Wrong_Params = new Errcode(1, "参数错误");
|
|
19
|
+
Verify_failed = new Errcode(2, "验证失败");
|
|
20
|
+
Account_Create_Failed = new Errcode(3, "账号创建失败");
|
|
21
|
+
User_Create_Failed = new Errcode(4, "角色创建失败");
|
|
22
|
+
Server_Error = new Errcode(5, "服务器内部错误");
|
|
23
|
+
No_Account = new Errcode(6, "账户不存在");
|
|
24
|
+
Mysql_Error = new Errcode(7, "数据库异常");
|
|
25
|
+
No_Mysql = new Errcode(8, "未开通Mysql数据库");
|
|
26
|
+
No_Mssql = new Errcode(8, "未开通Mssql数据库");
|
|
27
|
+
No_User = new Errcode(9, "用户不存在");
|
|
28
|
+
Account_Phone_Exist = new Errcode(10, "电话已存在");
|
|
29
|
+
Account_Email_Exist = new Errcode(11, "邮箱已存在");
|
|
30
|
+
Account_Name_Exist = new Errcode(12, "账户名已存在");
|
|
31
|
+
Account_Type_Error = new Errcode(13, "账户类型错误");
|
|
32
|
+
Email_Send_Failed = new Errcode(14, "邮件发送失败");
|
|
33
|
+
Login_Failed = new Errcode(15, "登陆验证失败");
|
|
34
|
+
Password_Too_Short = new Errcode(16, "密码太短");
|
|
35
|
+
Wrong_Phone = new Errcode(17, "电话号码不正确");
|
|
36
|
+
PhoneCode_Too_Quick = new Errcode(18, "验证码获取过快,请稍后再试");
|
|
37
|
+
PhoneCode_GetFailed = new Errcode(19, "验证码获取失败");
|
|
38
|
+
Wrong_Phone_Code = new Errcode(20, "验证码不正确");
|
|
39
|
+
No_Mongo = new Errcode(21, "未开通Mongo数据库");
|
|
40
|
+
Mongo_Error = new Errcode(22, "Mongo数据库异常");
|
|
32
41
|
constructor() { }
|
|
33
42
|
}
|
|
34
43
|
exports.FrameworkErrorCode = FrameworkErrorCode;
|
|
@@ -1,145 +1,169 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.MongoBaseService = void 0;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
const _error_1 = require("../../Config/_error_");
|
|
9
|
+
const Log_1 = require("../../Logic/Log");
|
|
4
10
|
const MongoManager_1 = require("./MongoManager");
|
|
5
|
-
const MongoServiceManager_1 = require("./MongoServiceManager");
|
|
6
11
|
class MongoBaseService {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return this._inited;
|
|
14
|
-
}
|
|
15
|
-
get mongoDb() {
|
|
16
|
-
return MongoManager_1.gMongoMgr.getMongo(this._dbname);
|
|
17
|
-
}
|
|
18
|
-
_dbname = "";
|
|
19
|
-
get dbname() {
|
|
20
|
-
if (!this._dbname) {
|
|
21
|
-
this._dbname = MongoManager_1.gMongoMgr.defdbname;
|
|
12
|
+
_model;
|
|
13
|
+
_schema;
|
|
14
|
+
_collection_name;
|
|
15
|
+
get model() {
|
|
16
|
+
if (this._model) {
|
|
17
|
+
return this._model;
|
|
22
18
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this._dbname = db;
|
|
27
|
-
}
|
|
28
|
-
_t_type = null;
|
|
29
|
-
constructor(table, type, dbname = "") {
|
|
30
|
-
this._t_type = type;
|
|
31
|
-
this._table = table;
|
|
32
|
-
this._dbname = dbname;
|
|
33
|
-
MongoServiceManager_1.gMongoServiceMgr.addService(this);
|
|
34
|
-
}
|
|
35
|
-
async getNextId(key = "") {
|
|
36
|
-
if (!key) {
|
|
37
|
-
key = this._table;
|
|
19
|
+
if (mongoose_1.default.connection.readyState !== 1) {
|
|
20
|
+
Log_1.gLog.error("MongoDB connection is not ready, please check the connection settings. Current state: " + mongoose_1.default.connection.readyState);
|
|
21
|
+
throw new Error("MongoDB connection is not ready");
|
|
38
22
|
}
|
|
39
|
-
let
|
|
40
|
-
|
|
23
|
+
let db = mongoose_1.default.connection.db;
|
|
24
|
+
if (!db || db.databaseName == "test") {
|
|
25
|
+
Log_1.gLog.error("MongoDB connection is not valid, please check the connection settings.");
|
|
26
|
+
throw new Error("MongoDB connection is not valid");
|
|
27
|
+
}
|
|
28
|
+
this._model = mongoose_1.default.model(this._collection_name, this._schema);
|
|
29
|
+
return this._model;
|
|
41
30
|
}
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
constructor(collection_name, schema) {
|
|
32
|
+
this._collection_name = collection_name;
|
|
33
|
+
schema.set('collection', collection_name);
|
|
34
|
+
this._schema = schema;
|
|
44
35
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
let rs = await this.mongoDb.findOne(this._table, { id: id });
|
|
51
|
-
return rs.one;
|
|
36
|
+
async findOne(filter, projection, options) {
|
|
37
|
+
if (!this.model) {
|
|
38
|
+
throw new Error("Model is not defined");
|
|
39
|
+
}
|
|
40
|
+
return await this.model.findOne(filter, projection, options);
|
|
52
41
|
}
|
|
53
|
-
async
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
async find(filter, projection, options) {
|
|
43
|
+
if (!this.model) {
|
|
44
|
+
throw new Error("Model is not defined");
|
|
45
|
+
}
|
|
46
|
+
return await this.model.find(filter, projection, options);
|
|
56
47
|
}
|
|
57
|
-
async
|
|
58
|
-
|
|
59
|
-
|
|
48
|
+
async findMany(filter, projection, options, skip, limit) {
|
|
49
|
+
if (!this.model) {
|
|
50
|
+
throw new Error("Model is not defined");
|
|
51
|
+
}
|
|
52
|
+
let query = this.model.find(filter, projection, options);
|
|
53
|
+
if (skip !== undefined) {
|
|
54
|
+
query = query.skip(skip);
|
|
55
|
+
}
|
|
56
|
+
if (limit !== undefined) {
|
|
57
|
+
query = query.limit(limit);
|
|
58
|
+
}
|
|
59
|
+
return await query.exec();
|
|
60
60
|
}
|
|
61
|
-
async
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
async findById(id, projection, options) {
|
|
62
|
+
if (!this.model) {
|
|
63
|
+
throw new Error("Model is not defined");
|
|
64
|
+
}
|
|
65
|
+
return await this.model.findById(id, projection, options);
|
|
64
66
|
}
|
|
65
|
-
async
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
async create(doc) {
|
|
68
|
+
if (!this.model) {
|
|
69
|
+
throw new Error("Model is not defined");
|
|
70
|
+
}
|
|
71
|
+
const newDoc = new this.model(doc);
|
|
72
|
+
return await newDoc.save();
|
|
73
|
+
}
|
|
74
|
+
async insert(doc) {
|
|
75
|
+
try {
|
|
76
|
+
if (!this.model) {
|
|
77
|
+
throw new Error("Model is not defined");
|
|
78
|
+
}
|
|
79
|
+
const newDoc = await this.model.insertOne(doc);
|
|
80
|
+
return { errcode: null, model: newDoc };
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
Log_1.gLog.error(arguments);
|
|
84
|
+
Log_1.gLog.error("MongoDB insert error:", error.stack);
|
|
85
|
+
return { errcode: _error_1.EErrorCode.Mongo_Error, model: null };
|
|
86
|
+
}
|
|
68
87
|
}
|
|
69
|
-
async
|
|
70
|
-
|
|
71
|
-
|
|
88
|
+
async updateOne(filter, update, options) {
|
|
89
|
+
try {
|
|
90
|
+
if (!this.model) {
|
|
91
|
+
throw new Error("Model is not defined");
|
|
92
|
+
}
|
|
93
|
+
let rs = await this.model.updateOne(filter, update, options);
|
|
94
|
+
return { errcode: null, rs: rs };
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
return { errcode: _error_1.EErrorCode.Mongo_Error, rs: null };
|
|
98
|
+
}
|
|
72
99
|
}
|
|
73
|
-
async
|
|
74
|
-
|
|
75
|
-
|
|
100
|
+
async updateMany(filter, update, options) {
|
|
101
|
+
try {
|
|
102
|
+
if (!this.model) {
|
|
103
|
+
throw new Error("Model is not defined");
|
|
104
|
+
}
|
|
105
|
+
await this.model.updateMany(filter, update, options);
|
|
106
|
+
return { errcode: null };
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
return { errcode: error };
|
|
110
|
+
}
|
|
76
111
|
}
|
|
77
|
-
async
|
|
78
|
-
|
|
79
|
-
|
|
112
|
+
async deleteOne(filter) {
|
|
113
|
+
try {
|
|
114
|
+
if (!this.model) {
|
|
115
|
+
throw new Error("Model is not defined");
|
|
116
|
+
}
|
|
117
|
+
let rs = await this.model.deleteOne(filter);
|
|
118
|
+
return { errcode: null, rs: rs };
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
return { errcode: _error_1.EErrorCode.Mongo_Error, rs: null };
|
|
122
|
+
}
|
|
80
123
|
}
|
|
81
|
-
async
|
|
82
|
-
|
|
83
|
-
|
|
124
|
+
async deleteMany(filter) {
|
|
125
|
+
try {
|
|
126
|
+
if (!this.model) {
|
|
127
|
+
throw new Error("Model is not defined");
|
|
128
|
+
}
|
|
129
|
+
await this.model.deleteMany(filter);
|
|
130
|
+
return { errcode: null };
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
return { errcode: error };
|
|
134
|
+
}
|
|
84
135
|
}
|
|
85
|
-
async
|
|
86
|
-
|
|
87
|
-
|
|
136
|
+
async exists(filter) {
|
|
137
|
+
if (!this.model) {
|
|
138
|
+
throw new Error("Model is not defined");
|
|
139
|
+
}
|
|
140
|
+
const doc = await this.model.findOne(filter, { _id: 1 });
|
|
141
|
+
return !!doc;
|
|
88
142
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
143
|
+
// 用于聚合查询
|
|
144
|
+
aggregate(pipeline) {
|
|
145
|
+
if (!this.model) {
|
|
146
|
+
throw new Error("Model is not defined");
|
|
147
|
+
}
|
|
148
|
+
return this.model.aggregate(pipeline);
|
|
92
149
|
}
|
|
93
|
-
|
|
94
|
-
|
|
150
|
+
// findOneAndUpdate method for MongoDB operations
|
|
151
|
+
async findOneAndUpdate(filter, update, options) {
|
|
152
|
+
if (!this.model) {
|
|
153
|
+
throw new Error("Model is not defined");
|
|
154
|
+
}
|
|
155
|
+
let rs = await this.model.findOneAndUpdate(filter, update, options);
|
|
95
156
|
return rs;
|
|
96
157
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
* 仅仅支持一级
|
|
103
|
-
* @param array 数据名称 比如 items
|
|
104
|
-
* @param where 数组内赛选条件 比如 "items.id":1
|
|
105
|
-
* @param pre_match 数组上一级赛选条件 比如 "user_id":1
|
|
106
|
-
*/
|
|
107
|
-
async getsInArray(array, where, pre_match) {
|
|
108
|
-
let agg = this.aggregate();
|
|
109
|
-
if (pre_match) {
|
|
110
|
-
agg = agg.match(pre_match);
|
|
111
|
-
}
|
|
112
|
-
agg = agg.unwind("$" + array);
|
|
113
|
-
if (where) {
|
|
114
|
-
agg = agg.match(where);
|
|
115
|
-
}
|
|
116
|
-
let all = await agg.toArray();
|
|
117
|
-
let items = [];
|
|
118
|
-
for (let i = 0; i < all.length; ++i) {
|
|
119
|
-
items.push(all[i][array]);
|
|
120
|
-
}
|
|
121
|
-
return items;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* 仅仅支持一级
|
|
125
|
-
* @param array 数据名称 比如 items
|
|
126
|
-
* @param where 数组内赛选条件 比如 "items.id":1
|
|
127
|
-
* @param pre_match 数组上一级赛选条件 比如 "user_id":1
|
|
128
|
-
*/
|
|
129
|
-
async getInArray(array, where, pre_match) {
|
|
130
|
-
let items = await this.getsInArray(array, where, pre_match);
|
|
131
|
-
if (items.length <= 0) {
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
return items[0];
|
|
135
|
-
}
|
|
136
|
-
async distinct(key, where = {}) {
|
|
137
|
-
let rs = await this.mongoDb.distinct(this._table, key, where);
|
|
138
|
-
return rs;
|
|
158
|
+
async countDocuments(filter) {
|
|
159
|
+
if (!this.model) {
|
|
160
|
+
throw new Error("Model is not defined");
|
|
161
|
+
}
|
|
162
|
+
return await this.model.countDocuments(filter);
|
|
139
163
|
}
|
|
140
|
-
async
|
|
141
|
-
let
|
|
142
|
-
return
|
|
164
|
+
async getAutoIds() {
|
|
165
|
+
let id = await MongoManager_1.gMongoMgr.getMongo().getAutoIds(this.model.collection.name);
|
|
166
|
+
return id;
|
|
143
167
|
}
|
|
144
168
|
}
|
|
145
169
|
exports.MongoBaseService = MongoBaseService;
|