cgserver 13.0.5 → 13.1.0
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 +2 -2
- package/dist/lib/Framework/Server/WebServer/Controller/MongoBaseUserController.js +8 -8
- package/dist/lib/Framework/Service/MongoAccountService.js +7 -7
- package/dist/types/Framework/Database/Mongo/MongoBaseService.d.ts +5 -2
- package/dist/types/Framework/Database/Mongo/MongoManager.d.ts +0 -2
- package/dist/types/Framework/Service/MongoAccountService.d.ts +2 -2
- package/dist/types/Framework/Service/MongoCacheService.d.ts +2 -3
- package/dist/types/Framework/Service/MongoUserService.d.ts +2 -1
- package/dist/types/Framework/index_export_.d.ts +2 -2
- package/package.json +1 -1
|
@@ -68,7 +68,7 @@ class MongoBaseService {
|
|
|
68
68
|
if (!this.model) {
|
|
69
69
|
throw new Error("Model is not defined");
|
|
70
70
|
}
|
|
71
|
-
let one = await this.model.findOne(filter, projection, options);
|
|
71
|
+
let one = await this.model.findOne(filter, projection, options).lean();
|
|
72
72
|
return one;
|
|
73
73
|
}
|
|
74
74
|
async find(filter, projection, options) {
|
|
@@ -83,7 +83,7 @@ class MongoBaseService {
|
|
|
83
83
|
if (!this.model) {
|
|
84
84
|
throw new Error("Model is not defined");
|
|
85
85
|
}
|
|
86
|
-
return await this.model.findById(id, projection, options);
|
|
86
|
+
return await this.model.findById(id, projection, options).lean();
|
|
87
87
|
}
|
|
88
88
|
async create(doc) {
|
|
89
89
|
if (!this.model) {
|
|
@@ -15,7 +15,7 @@ class MongoBaseUserController extends BaseController_1.BaseController {
|
|
|
15
15
|
return this._self_user;
|
|
16
16
|
}
|
|
17
17
|
get isSelf() {
|
|
18
|
-
return this._self_user && (this._self_user.
|
|
18
|
+
return this._self_user && (this._self_user._id == this._user._id);
|
|
19
19
|
}
|
|
20
20
|
get isLogin() {
|
|
21
21
|
return this._self_user && true;
|
|
@@ -27,7 +27,7 @@ class MongoBaseUserController extends BaseController_1.BaseController {
|
|
|
27
27
|
let userSer = this.userService;
|
|
28
28
|
this._engine.cfg.session_type = this._engine.cfg.session_type || FrameworkConfig_1.ESessionType.Cache;
|
|
29
29
|
this._session_id = this._request.getCookie(this._user_session_id) || this._request.params.session_id || this._request.postData.session_id;
|
|
30
|
-
let userId =
|
|
30
|
+
let userId = 0;
|
|
31
31
|
if (this._session_id) {
|
|
32
32
|
let user = await this._getUserBySession(this._session_id);
|
|
33
33
|
if (!user) {
|
|
@@ -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;
|
|
@@ -97,7 +97,7 @@ class MongoBaseUserController extends BaseController_1.BaseController {
|
|
|
97
97
|
return;
|
|
98
98
|
}
|
|
99
99
|
if (!this._session_id) {
|
|
100
|
-
this._session_id = Math.random().toString(36).substring(2) + user.
|
|
100
|
+
this._session_id = Math.random().toString(36).substring(2) + user._id;
|
|
101
101
|
}
|
|
102
102
|
let time = 0;
|
|
103
103
|
if (this._request.postData.remember == "on") {
|
|
@@ -117,12 +117,12 @@ 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
|
}
|
|
124
124
|
else if (this._engine.cfg.session_type == FrameworkConfig_1.ESessionType.Mongo) {
|
|
125
|
-
MongoCacheService_1.gMongoCacheSer.addData(this._session_id, user.
|
|
125
|
+
MongoCacheService_1.gMongoCacheSer.addData(this._session_id, user._id, new Date(Date.now() + time * 1000));
|
|
126
126
|
}
|
|
127
127
|
this._self_user = user;
|
|
128
128
|
}
|
|
@@ -133,10 +133,10 @@ class MongoBaseUserController extends BaseController_1.BaseController {
|
|
|
133
133
|
}
|
|
134
134
|
async update_user(user_id) {
|
|
135
135
|
let user = (await this.userService.findById(user_id));
|
|
136
|
-
if (this._user && this._user.
|
|
136
|
+
if (this._user && this._user._id == user._id) {
|
|
137
137
|
this._user = user;
|
|
138
138
|
}
|
|
139
|
-
if (this._self_user && this._self_user.
|
|
139
|
+
if (this._self_user && this._self_user._id == user._id) {
|
|
140
140
|
this._login(user);
|
|
141
141
|
}
|
|
142
142
|
}
|
|
@@ -149,7 +149,7 @@ class MongoAccountService extends MongoBaseService_1.MongoBaseService {
|
|
|
149
149
|
}
|
|
150
150
|
if (force_user) {
|
|
151
151
|
let userser = this.userService;
|
|
152
|
-
let user = await userser.findOne({ account_id: account.
|
|
152
|
+
let user = await userser.findOne({ account_id: account._id.toString() });
|
|
153
153
|
if (!user) {
|
|
154
154
|
switch (from) {
|
|
155
155
|
case ini_1.EAccountFrom.QQ:
|
|
@@ -193,9 +193,9 @@ class MongoAccountService extends MongoBaseService_1.MongoBaseService {
|
|
|
193
193
|
};
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
let user = await userser.add(account.
|
|
196
|
+
let user = await userser.add(account._id.toString(), extra_info.nickname, extra_info.sex, extra_info.logo);
|
|
197
197
|
if (!user) {
|
|
198
|
-
this.deleteOne({ id: account.
|
|
198
|
+
this.deleteOne({ id: account._id.toString() });
|
|
199
199
|
rs.errcode = _error_1.EErrorCode.User_Create_Failed;
|
|
200
200
|
return rs;
|
|
201
201
|
}
|
|
@@ -206,13 +206,13 @@ class MongoAccountService extends MongoBaseService_1.MongoBaseService {
|
|
|
206
206
|
{
|
|
207
207
|
let user = null;
|
|
208
208
|
if (extra_info) {
|
|
209
|
-
user = await userser.add(account.
|
|
209
|
+
user = await userser.add(account._id.toString(), extra_info.nickname, extra_info.sex, extra_info.logo);
|
|
210
210
|
}
|
|
211
211
|
else {
|
|
212
|
-
user = await userser.add(account.
|
|
212
|
+
user = await userser.add(account._id.toString());
|
|
213
213
|
}
|
|
214
214
|
if (!user) {
|
|
215
|
-
this.deleteOne({
|
|
215
|
+
this.deleteOne({ _id: account._id });
|
|
216
216
|
rs.errcode = _error_1.EErrorCode.User_Create_Failed;
|
|
217
217
|
return rs;
|
|
218
218
|
}
|
|
@@ -229,7 +229,7 @@ class MongoAccountService extends MongoBaseService_1.MongoBaseService {
|
|
|
229
229
|
}
|
|
230
230
|
account.login_time = new Date();
|
|
231
231
|
account.login_ip = ip;
|
|
232
|
-
|
|
232
|
+
this.updateOne({ _id: account._id }, { $set: { login_time: account.login_time, login_ip: account.login_ip } });
|
|
233
233
|
rs.account = account;
|
|
234
234
|
return rs;
|
|
235
235
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import mongoose, {
|
|
1
|
+
import mongoose, { FilterQuery, UpdateQuery, Types, MongooseQueryOptions } from 'mongoose';
|
|
2
2
|
import { Errcode } from '../../Config/_error_';
|
|
3
|
-
export
|
|
3
|
+
export interface IMongoBaseModel {
|
|
4
|
+
_id: Types.ObjectId;
|
|
5
|
+
}
|
|
6
|
+
export declare class MongoBaseService<T> {
|
|
4
7
|
protected _model: mongoose.Model<T>;
|
|
5
8
|
protected _schema: mongoose.Schema<T>;
|
|
6
9
|
protected _collection_name: string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import mongoose from 'mongoose';
|
|
2
2
|
import { Errcode } from '../Config/_error_';
|
|
3
|
-
import { MongoBaseService } from '../Database/Mongo/MongoBaseService';
|
|
3
|
+
import { IMongoBaseModel, MongoBaseService } from '../Database/Mongo/MongoBaseService';
|
|
4
4
|
import { EAccountFrom, EAccountState } from './ini';
|
|
5
5
|
import { IMongoUserModel, MongoUserService } from './MongoUserService';
|
|
6
|
-
export interface IMongoAccountModel extends
|
|
6
|
+
export interface IMongoAccountModel extends IMongoBaseModel {
|
|
7
7
|
phone: string;
|
|
8
8
|
email: string;
|
|
9
9
|
name: string;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export interface IMongoCacheModel extends mongoose.Document {
|
|
1
|
+
import { IMongoBaseModel, MongoBaseService } from "../Database/Mongo/MongoBaseService";
|
|
2
|
+
export interface IMongoCacheModel extends IMongoBaseModel {
|
|
4
3
|
key: string;
|
|
5
4
|
data: any;
|
|
6
5
|
expireAt: Date;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { MongoBaseService } from "../Database/Mongo/MongoBaseService";
|
|
2
2
|
import mongoose from "mongoose";
|
|
3
3
|
import { EUserState } from "./ini";
|
|
4
|
-
export interface IMongoUserModel
|
|
4
|
+
export interface IMongoUserModel {
|
|
5
|
+
_id: number;
|
|
5
6
|
account_id: string;
|
|
6
7
|
state: EUserState;
|
|
7
8
|
is_robot: boolean;
|
|
@@ -21,9 +21,9 @@ export { Property } from './Database/Decorator/Property';
|
|
|
21
21
|
export { Table } from './Database/Decorator/Table';
|
|
22
22
|
export { Type } from './Database/Decorator/Type';
|
|
23
23
|
export { EPropertyType } from './Database/Decorator/Property';
|
|
24
|
-
export { MongoBaseService } from './Database/Mongo/MongoBaseService';
|
|
24
|
+
export { IMongoBaseModel, MongoBaseService } from './Database/Mongo/MongoBaseService';
|
|
25
25
|
export { BaseModel as MysqlBaseModel } from './Database/Mysql/MysqlBaseService';
|
|
26
|
-
export {
|
|
26
|
+
export { MongoManager, MongoExt } from './Database/Mongo/MongoManager';
|
|
27
27
|
export { MysqlBaseService } from './Database/Mysql/MysqlBaseService';
|
|
28
28
|
export { SqlReturn, SqlReturns } from './Database/Mysql/MysqlManager';
|
|
29
29
|
export { EUserState, EAccountFrom } from './Service/ini';
|