33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import BaseModel, { getModelForClass } from './BaseModel';
|
|
import { prop, DocumentType } from '@typegoose/typegoose';
|
|
import { WHITE_LIST_TYPE } from '../consts';
|
|
|
|
export default class WhiteList extends BaseModel {
|
|
|
|
@prop({ required: true, enum: WHITE_LIST_TYPE })
|
|
type: WHITE_LIST_TYPE; // 区号
|
|
|
|
@prop({ required: true })
|
|
str: string; // ip或手机号
|
|
|
|
public static async checkIp(ip: string) {
|
|
const rec: WhiteListModelType = await WhiteListModel.findOne({ type: WHITE_LIST_TYPE.IP, str: ip }).lean();
|
|
return rec;
|
|
}
|
|
|
|
public static async checkTel(tel: string) {
|
|
const rec: WhiteListModelType = await WhiteListModel.findOne({ type: WHITE_LIST_TYPE.TEL, str: tel }).lean();
|
|
return rec;
|
|
}
|
|
|
|
public static async test(a: number, b: number, c: string) {
|
|
console.log(a, b, c)
|
|
const rec: WhiteListModelType = await WhiteListModel.findOneAndUpdate({}, { type: [] as any }).lean();
|
|
return rec;
|
|
}
|
|
}
|
|
|
|
export const WhiteListModel = getModelForClass(WhiteList);
|
|
|
|
export interface WhiteListModelType extends Pick<DocumentType<WhiteList>, keyof WhiteList> { }
|
|
export type WhiteListModelTypeParam = Partial<WhiteListModelType>; // 将所有字段变成可选项
|