cgserver 13.1.0 → 13.1.2
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/Database/Mongo/MongoBaseService.js +23 -3
- package/dist/lib/Framework/Server/WebServer/Controller/MongoBaseUserController.js +2 -2
- package/dist/types/Framework/Database/Mongo/MongoBaseService.d.ts +5 -3
- package/dist/types/Framework/Service/MongoUserService.d.ts +2 -3
- package/package.json +1 -1
|
@@ -62,6 +62,7 @@ class MongoBaseService {
|
|
|
62
62
|
this._collection_name = collection_name;
|
|
63
63
|
schema.set('collection', collection_name);
|
|
64
64
|
this._schema = schema;
|
|
65
|
+
this._schema.set('minimize', false);
|
|
65
66
|
}
|
|
66
67
|
async findOne(filter, projection, options) {
|
|
67
68
|
filter = this._convertFilter(filter);
|
|
@@ -69,6 +70,7 @@ class MongoBaseService {
|
|
|
69
70
|
throw new Error("Model is not defined");
|
|
70
71
|
}
|
|
71
72
|
let one = await this.model.findOne(filter, projection, options).lean();
|
|
73
|
+
this._convertId(one);
|
|
72
74
|
return one;
|
|
73
75
|
}
|
|
74
76
|
async find(filter, projection, options) {
|
|
@@ -77,13 +79,18 @@ class MongoBaseService {
|
|
|
77
79
|
throw new Error("Model is not defined");
|
|
78
80
|
}
|
|
79
81
|
let list = await this.model.find(filter, projection, options).lean();
|
|
82
|
+
list.forEach(one => {
|
|
83
|
+
this._convertId(one);
|
|
84
|
+
});
|
|
80
85
|
return list;
|
|
81
86
|
}
|
|
82
87
|
async findById(id, projection, options) {
|
|
83
88
|
if (!this.model) {
|
|
84
89
|
throw new Error("Model is not defined");
|
|
85
90
|
}
|
|
86
|
-
|
|
91
|
+
let one = await this.model.findById(id, projection, options).lean();
|
|
92
|
+
this._convertId(one);
|
|
93
|
+
return one;
|
|
87
94
|
}
|
|
88
95
|
async create(doc) {
|
|
89
96
|
if (!this.model) {
|
|
@@ -179,8 +186,9 @@ class MongoBaseService {
|
|
|
179
186
|
if (!this.model) {
|
|
180
187
|
throw new Error("Model is not defined");
|
|
181
188
|
}
|
|
182
|
-
let
|
|
183
|
-
|
|
189
|
+
let one = await this.model.findOneAndUpdate(filter, update, options).lean();
|
|
190
|
+
this._convertId(one);
|
|
191
|
+
return one;
|
|
184
192
|
}
|
|
185
193
|
async countDocuments(filter) {
|
|
186
194
|
filter = this._convertFilter(filter);
|
|
@@ -203,6 +211,18 @@ class MongoBaseService {
|
|
|
203
211
|
}
|
|
204
212
|
return filter;
|
|
205
213
|
}
|
|
214
|
+
_convertId(one) {
|
|
215
|
+
if (!one) {
|
|
216
|
+
return one;
|
|
217
|
+
}
|
|
218
|
+
if (typeof one._id === 'object' && one._id instanceof mongoose_1.Types.ObjectId) {
|
|
219
|
+
one.id = one._id.toString();
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
one.id = one._id;
|
|
223
|
+
}
|
|
224
|
+
return one;
|
|
225
|
+
}
|
|
206
226
|
async getAutoIds() {
|
|
207
227
|
let id = await MongoManager_1.gMongoMgr.getMongo().getAutoIds(this.model.collection.name);
|
|
208
228
|
return id;
|
|
@@ -37,7 +37,7 @@ class MongoBaseUserController extends BaseController_1.BaseController {
|
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
39
|
this._login(user);
|
|
40
|
-
userId = user.
|
|
40
|
+
userId = user.id;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
let params = this._request.params;
|
|
@@ -117,7 +117,7 @@ class MongoBaseUserController extends BaseController_1.BaseController {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Redis) {
|
|
120
|
-
RedisManager_1.gRedisMgr.redis.set(this._session_id, user.
|
|
120
|
+
RedisManager_1.gRedisMgr.redis.set(this._session_id, user.id).then(() => {
|
|
121
121
|
RedisManager_1.gRedisMgr.redis.expire(this._session_id, time);
|
|
122
122
|
});
|
|
123
123
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import mongoose, { FilterQuery, UpdateQuery, Types, MongooseQueryOptions } from 'mongoose';
|
|
2
2
|
import { Errcode } from '../../Config/_error_';
|
|
3
3
|
export interface IMongoBaseModel {
|
|
4
|
-
_id:
|
|
4
|
+
_id: any;
|
|
5
|
+
id: any;
|
|
5
6
|
}
|
|
6
|
-
export declare class MongoBaseService<T> {
|
|
7
|
+
export declare class MongoBaseService<T extends IMongoBaseModel> {
|
|
7
8
|
protected _model: mongoose.Model<T>;
|
|
8
9
|
protected _schema: mongoose.Schema<T>;
|
|
9
10
|
protected _collection_name: string;
|
|
@@ -37,8 +38,9 @@ export declare class MongoBaseService<T> {
|
|
|
37
38
|
}>;
|
|
38
39
|
exists(filter: FilterQuery<T>): Promise<boolean>;
|
|
39
40
|
aggregate(pipeline?: any[]): mongoose.Aggregate<any[]>;
|
|
40
|
-
findOneAndUpdate(filter: FilterQuery<T>, update: UpdateQuery<T>, options?: MongooseQueryOptions): Promise<
|
|
41
|
+
findOneAndUpdate(filter: FilterQuery<T>, update: UpdateQuery<T>, options?: MongooseQueryOptions): Promise<T>;
|
|
41
42
|
countDocuments(filter?: FilterQuery<T>): Promise<number>;
|
|
42
43
|
protected _convertFilter(filter: FilterQuery<T>): FilterQuery<T>;
|
|
44
|
+
protected _convertId(one: T | null): T;
|
|
43
45
|
getAutoIds(): Promise<number>;
|
|
44
46
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { MongoBaseService } from "../Database/Mongo/MongoBaseService";
|
|
1
|
+
import { IMongoBaseModel, MongoBaseService } from "../Database/Mongo/MongoBaseService";
|
|
2
2
|
import mongoose from "mongoose";
|
|
3
3
|
import { EUserState } from "./ini";
|
|
4
|
-
export interface IMongoUserModel {
|
|
5
|
-
_id: number;
|
|
4
|
+
export interface IMongoUserModel extends IMongoBaseModel {
|
|
6
5
|
account_id: string;
|
|
7
6
|
state: EUserState;
|
|
8
7
|
is_robot: boolean;
|