91 lines
4.1 KiB
TypeScript
91 lines
4.1 KiB
TypeScript
import * as tracer from 'tracer';
|
||
import * as _typegoose_typegoose from '@typegoose/typegoose';
|
||
import { ReturnModelType } from '@typegoose/typegoose';
|
||
import * as _typegoose_typegoose_lib_types from '@typegoose/typegoose/lib/types';
|
||
import { AnyParamConstructor } from '@typegoose/typegoose/lib/types';
|
||
import * as mongoose from 'mongoose';
|
||
import { Connection } from 'mongoose';
|
||
|
||
/**
|
||
* 为model指定数据库连接
|
||
* @param {string} name 数据库连接名字, 在config中必须要有对应的配置, 比如main, 则必须要有 db_main
|
||
* */
|
||
declare function dbconn(name?: string): (target: any) => void;
|
||
|
||
declare class NoJsonClass {
|
||
private noJsonPropSet;
|
||
addKey(className: string, propertyKey: string): void;
|
||
checkExist(className: string, propertyKey: string): boolean;
|
||
}
|
||
/**
|
||
* 在不需要toJson方法输出的字段上加上 @noJson
|
||
* @return {{(target: Function): void, (target: Object, propertyKey: (string | symbol)): void}}
|
||
*/
|
||
declare function noJson(): (target: Object, propertyKey: string) => void;
|
||
declare function checkJson(target: any, propertyKey: string): boolean;
|
||
|
||
declare const logger: tracer.Tracer.Logger<string>;
|
||
|
||
declare abstract class BaseModule {
|
||
static db: Connection;
|
||
updateFromReq(data: any): void;
|
||
/**
|
||
* 插入或更新
|
||
* @param condition
|
||
* @param data
|
||
*/
|
||
static insertOrUpdate<T extends BaseModule>(this: ReturnModelType<AnyParamConstructor<T>>, condition: any, data: any): mongoose.QueryWithHelpers<mongoose.IfAny<T, any, mongoose.Document<unknown, _typegoose_typegoose_lib_types.BeAnObject, T> & Omit<mongoose.Require_id<T>, "typegooseName"> & _typegoose_typegoose_lib_types.IObjectWithTypegooseFunction>, mongoose.IfAny<T, any, mongoose.Document<unknown, _typegoose_typegoose_lib_types.BeAnObject, T> & Omit<mongoose.Require_id<T>, "typegooseName"> & _typegoose_typegoose_lib_types.IObjectWithTypegooseFunction>, _typegoose_typegoose_lib_types.BeAnObject, T, "findOneAndUpdate">;
|
||
/**
|
||
* 虚拟删除
|
||
* @param {string[]} ids
|
||
*/
|
||
static deleteVirtual<T extends BaseModule>(this: ReturnModelType<AnyParamConstructor<T>>, ids: string[]): mongoose.QueryWithHelpers<mongoose.UpdateWriteOpResult, mongoose.IfAny<T, any, mongoose.Document<unknown, _typegoose_typegoose_lib_types.BeAnObject, T> & Omit<mongoose.Require_id<T>, "typegooseName"> & _typegoose_typegoose_lib_types.IObjectWithTypegooseFunction>, _typegoose_typegoose_lib_types.BeAnObject, T, "updateMany">;
|
||
/**
|
||
* 自定义分页查询
|
||
* @param data
|
||
* @param {boolean} json
|
||
*/
|
||
static pageQuery<T extends BaseModule>(this: ReturnModelType<AnyParamConstructor<T>>, data: any, json?: boolean): Promise<{
|
||
records: mongoose.IfAny<T, any, mongoose.Document<unknown, _typegoose_typegoose_lib_types.BeAnObject, T> & Omit<mongoose.Require_id<T>, "typegooseName"> & _typegoose_typegoose_lib_types.IObjectWithTypegooseFunction>[];
|
||
total: number;
|
||
start: any;
|
||
limit: any;
|
||
}>;
|
||
toJson(): any;
|
||
/**
|
||
* 通用的查询条件拼接方法
|
||
* @param {{}} params req.params
|
||
* @param options
|
||
* sort: 排序 比如: {createdAt: 1} 默认是 {_id: 1}
|
||
* opt: 设置一些特殊的过滤条件, 比如{deleted: 0}
|
||
* timeKey: 如果需要查询创建时间, 而且创建时间不为 createdAt, 可以用此字段设置
|
||
* matchKey: 指定关键字查询的匹配字段, 可为string或[string]
|
||
*
|
||
* @return {{opt: any, sort: {_id: number}}}
|
||
*/
|
||
static parseQueryParam(params: {}, options?: any): {
|
||
opt: any;
|
||
sort: {
|
||
_id: number;
|
||
};
|
||
};
|
||
getTimestampOfID(): any;
|
||
}
|
||
|
||
/**
|
||
* 用户操作记录
|
||
*/
|
||
declare class UserLogClass extends BaseModule {
|
||
user: string;
|
||
name: string;
|
||
method: string;
|
||
path: string;
|
||
referer: string;
|
||
user_agent: string;
|
||
ip: string;
|
||
params: any;
|
||
}
|
||
declare const UserLog: _typegoose_typegoose.ReturnModelType<typeof UserLogClass, _typegoose_typegoose_lib_types.BeAnObject>;
|
||
|
||
export { BaseModule, NoJsonClass, UserLog, checkJson, dbconn, logger, noJson };
|