cgserver 13.0.6 → 13.1.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/Database/Mongo/MongoBaseService.js +22 -3
- package/dist/lib/Framework/Server/WebServer/Controller/MongoBaseUserController.js +6 -6
- package/dist/types/Framework/Database/Mongo/MongoBaseService.d.ts +7 -2
- package/dist/types/Framework/Database/Mongo/MongoManager.d.ts +0 -2
- package/dist/types/Framework/Service/MongoAccountService.d.ts +3 -4
- package/dist/types/Framework/Service/MongoCacheService.d.ts +2 -3
- package/dist/types/Framework/Service/MongoUserService.d.ts +2 -2
- package/dist/types/Framework/index_export_.d.ts +2 -2
- package/package.json +1 -1
|
@@ -69,6 +69,7 @@ class MongoBaseService {
|
|
|
69
69
|
throw new Error("Model is not defined");
|
|
70
70
|
}
|
|
71
71
|
let one = await this.model.findOne(filter, projection, options).lean();
|
|
72
|
+
this._convertId(one);
|
|
72
73
|
return one;
|
|
73
74
|
}
|
|
74
75
|
async find(filter, projection, options) {
|
|
@@ -77,13 +78,18 @@ class MongoBaseService {
|
|
|
77
78
|
throw new Error("Model is not defined");
|
|
78
79
|
}
|
|
79
80
|
let list = await this.model.find(filter, projection, options).lean();
|
|
81
|
+
list.forEach(one => {
|
|
82
|
+
this._convertId(one);
|
|
83
|
+
});
|
|
80
84
|
return list;
|
|
81
85
|
}
|
|
82
86
|
async findById(id, projection, options) {
|
|
83
87
|
if (!this.model) {
|
|
84
88
|
throw new Error("Model is not defined");
|
|
85
89
|
}
|
|
86
|
-
|
|
90
|
+
let one = await this.model.findById(id, projection, options).lean();
|
|
91
|
+
this._convertId(one);
|
|
92
|
+
return one;
|
|
87
93
|
}
|
|
88
94
|
async create(doc) {
|
|
89
95
|
if (!this.model) {
|
|
@@ -179,8 +185,9 @@ class MongoBaseService {
|
|
|
179
185
|
if (!this.model) {
|
|
180
186
|
throw new Error("Model is not defined");
|
|
181
187
|
}
|
|
182
|
-
let
|
|
183
|
-
|
|
188
|
+
let one = await this.model.findOneAndUpdate(filter, update, options).lean();
|
|
189
|
+
this._convertId(one);
|
|
190
|
+
return one;
|
|
184
191
|
}
|
|
185
192
|
async countDocuments(filter) {
|
|
186
193
|
filter = this._convertFilter(filter);
|
|
@@ -203,6 +210,18 @@ class MongoBaseService {
|
|
|
203
210
|
}
|
|
204
211
|
return filter;
|
|
205
212
|
}
|
|
213
|
+
_convertId(one) {
|
|
214
|
+
if (!one) {
|
|
215
|
+
return one;
|
|
216
|
+
}
|
|
217
|
+
if (typeof one._id === 'object' && one._id instanceof mongoose_1.Types.ObjectId) {
|
|
218
|
+
one.id = one._id.toString();
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
one.id = one._id;
|
|
222
|
+
}
|
|
223
|
+
return one;
|
|
224
|
+
}
|
|
206
225
|
async getAutoIds() {
|
|
207
226
|
let id = await MongoManager_1.gMongoMgr.getMongo().getAutoIds(this.model.collection.name);
|
|
208
227
|
return id;
|
|
@@ -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) {
|
|
@@ -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") {
|
|
@@ -122,7 +122,7 @@ class MongoBaseUserController extends BaseController_1.BaseController {
|
|
|
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
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import mongoose, { FilterQuery, UpdateQuery, Types, MongooseQueryOptions } from 'mongoose';
|
|
2
2
|
import { Errcode } from '../../Config/_error_';
|
|
3
|
-
export
|
|
3
|
+
export interface IMongoBaseModel {
|
|
4
|
+
_id: any;
|
|
5
|
+
id: any;
|
|
6
|
+
}
|
|
7
|
+
export declare class MongoBaseService<T extends IMongoBaseModel> {
|
|
4
8
|
protected _model: mongoose.Model<T>;
|
|
5
9
|
protected _schema: mongoose.Schema<T>;
|
|
6
10
|
protected _collection_name: string;
|
|
@@ -34,8 +38,9 @@ export declare class MongoBaseService<T> {
|
|
|
34
38
|
}>;
|
|
35
39
|
exists(filter: FilterQuery<T>): Promise<boolean>;
|
|
36
40
|
aggregate(pipeline?: any[]): mongoose.Aggregate<any[]>;
|
|
37
|
-
findOneAndUpdate(filter: FilterQuery<T>, update: UpdateQuery<T>, options?: MongooseQueryOptions): Promise<
|
|
41
|
+
findOneAndUpdate(filter: FilterQuery<T>, update: UpdateQuery<T>, options?: MongooseQueryOptions): Promise<T>;
|
|
38
42
|
countDocuments(filter?: FilterQuery<T>): Promise<number>;
|
|
39
43
|
protected _convertFilter(filter: FilterQuery<T>): FilterQuery<T>;
|
|
44
|
+
protected _convertId(one: T | null): T;
|
|
40
45
|
getAutoIds(): Promise<number>;
|
|
41
46
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import mongoose
|
|
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 {
|
|
7
|
-
_id: Types.ObjectId;
|
|
6
|
+
export interface IMongoAccountModel extends IMongoBaseModel {
|
|
8
7
|
phone: string;
|
|
9
8
|
email: string;
|
|
10
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,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 extends
|
|
4
|
+
export interface IMongoUserModel extends IMongoBaseModel {
|
|
5
5
|
account_id: string;
|
|
6
6
|
state: EUserState;
|
|
7
7
|
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';
|